2020-05-11 18:21:45 +02:00
|
|
|
use slog::Logger;
|
|
|
|
|
2020-09-07 17:23:42 +02:00
|
|
|
use smol::net::TcpStream;
|
2020-05-11 18:21:45 +02:00
|
|
|
|
|
|
|
use crate::error::Result;
|
2020-09-07 09:45:55 +02:00
|
|
|
use crate::auth;
|
|
|
|
use crate::api;
|
2020-05-11 18:21:45 +02:00
|
|
|
|
2020-10-22 13:00:58 +02:00
|
|
|
pub use crate::schema::connection_capnp;
|
2020-05-10 17:23:43 +02:00
|
|
|
|
2020-10-23 15:29:32 +02:00
|
|
|
use capnp::capability::{Params, Results, Promise, FromServer};
|
2020-05-11 18:21:45 +02:00
|
|
|
|
2020-10-23 15:29:32 +02:00
|
|
|
/// Connection context
|
|
|
|
struct Connection {
|
|
|
|
stream: TcpStream,
|
|
|
|
user: Option<auth::User>,
|
|
|
|
}
|
2020-05-11 18:21:45 +02:00
|
|
|
|
2020-05-14 23:19:26 +02:00
|
|
|
|
2020-10-23 15:29:32 +02:00
|
|
|
use connection_capnp::bootstrap::*;
|
|
|
|
impl connection_capnp::bootstrap::Server for Connection {
|
|
|
|
fn auth(&mut self,
|
|
|
|
_: Params<auth_params::Owned>,
|
|
|
|
mut res: Results<auth_results::Owned>
|
|
|
|
) -> Promise<(), capnp::Error> {
|
|
|
|
// Forbid mutltiple authentication for now
|
|
|
|
// TODO: When should we allow multiple auth and how do me make sure that does not leak
|
|
|
|
// priviledges (e.g. due to previously issues caps)?
|
|
|
|
if self.user.is_none() {
|
|
|
|
res.get().set_auth(capnp_rpc::new_client(auth::Auth::new()))
|
2020-05-11 18:21:45 +02:00
|
|
|
}
|
2020-05-14 23:19:26 +02:00
|
|
|
|
2020-10-23 15:29:32 +02:00
|
|
|
Promise::ok(())
|
2020-05-14 23:19:26 +02:00
|
|
|
}
|
2020-09-07 09:45:55 +02:00
|
|
|
|
2020-10-23 15:29:32 +02:00
|
|
|
fn permissions(&mut self,
|
|
|
|
_: Params<permissions_params::Owned>,
|
|
|
|
mut res: Results<permissions_results::Owned>
|
|
|
|
) -> Promise<(), capnp::Error> {
|
2020-10-23 16:35:10 +02:00
|
|
|
if self.user.is_some() {
|
2020-05-14 23:19:26 +02:00
|
|
|
|
2020-09-07 09:45:55 +02:00
|
|
|
}
|
|
|
|
|
2020-10-23 15:29:32 +02:00
|
|
|
Promise::ok(())
|
2020-09-07 09:45:55 +02:00
|
|
|
}
|
2020-10-23 15:29:32 +02:00
|
|
|
}
|
2020-05-14 23:19:26 +02:00
|
|
|
|
2020-10-23 15:29:32 +02:00
|
|
|
pub async fn handle_connection(log: Logger, mut stream: TcpStream) -> Result<()> {
|
|
|
|
unimplemented!()
|
2020-05-11 18:21:45 +02:00
|
|
|
}
|