From 869f3d5e5fc7ad7ae3dd7789f23a05f8f4f7cf2f Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Thu, 28 Apr 2022 20:33:46 +0200 Subject: [PATCH] Add user search impl --- api/src/schema/general_capnp.rs | 210 +++++++++++ api/src/schema/usersystem_capnp.rs | 560 ++++++++++++++++++++++++++++- bffhd/capnp/machine.rs | 62 ++-- bffhd/capnp/user.rs | 6 +- bffhd/capnp/user_system.rs | 17 +- 5 files changed, 825 insertions(+), 30 deletions(-) diff --git a/api/src/schema/general_capnp.rs b/api/src/schema/general_capnp.rs index 68c0a18..5f91076 100644 --- a/api/src/schema/general_capnp.rs +++ b/api/src/schema/general_capnp.rs @@ -487,3 +487,213 @@ pub mod optional { /* T */ pub type WhichReader<'a,T> = Which<::capnp::Result<>::Reader>>; pub type WhichBuilder<'a,T> = Which<::capnp::Result<>::Builder>>; } + +pub mod fallible { /* T,E */ + pub use self::Which::{Failed,Successful}; + + #[derive(Copy, Clone)] + pub struct Owned { + _phantom: ::core::marker::PhantomData<(T,E)> + } + impl <'a, T,E> ::capnp::traits::Owned<'a> for Owned where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { type Reader = Reader<'a, T,E>; type Builder = Builder<'a, T,E>; } + impl <'a, T,E> ::capnp::traits::OwnedStruct<'a> for Owned where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { type Reader = Reader<'a, T,E>; type Builder = Builder<'a, T,E>; } + impl ::capnp::traits::Pipelined for Owned where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { type Pipeline = Pipeline; } + + #[derive(Clone, Copy)] + pub struct Reader<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + reader: ::capnp::private::layout::StructReader<'a>, + _phantom: ::core::marker::PhantomData<(T,E)> + } + + impl <'a,T,E> ::capnp::traits::HasTypeId for Reader<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,T,E> ::capnp::traits::FromStructReader<'a> for Reader<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,T,E> { + Reader { reader, _phantom: ::core::marker::PhantomData, } + } + } + + impl <'a,T,E> ::capnp::traits::FromPointerReader<'a> for Reader<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?)) + } + } + + impl <'a,T,E> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl <'a,T,E> ::capnp::traits::Imbue<'a> for Reader<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader.imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl <'a,T,E> Reader<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + pub fn reborrow(&self) -> Reader<'_,T,E> { + Reader { .. *self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + pub fn has_failed(&self) -> bool { + if self.reader.get_data_field::(0) != 0 { return false; } + !self.reader.get_pointer_field(0).is_null() + } + pub fn has_successful(&self) -> bool { + if self.reader.get_data_field::(0) != 1 { return false; } + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.reader.get_data_field::(0) { + 0 => { + ::core::result::Result::Ok(Failed( + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(0), ::core::option::Option::None) + )) + } + 1 => { + ::core::result::Result::Ok(Successful( + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(0), ::core::option::Option::None) + )) + } + x => ::core::result::Result::Err(::capnp::NotInSchema(x)) + } + } + } + + pub struct Builder<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + builder: ::capnp::private::layout::StructBuilder<'a>, + _phantom: ::core::marker::PhantomData<(T,E)> + } + impl <'a,T,E> ::capnp::traits::HasStructSize for Builder<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { _private::STRUCT_SIZE } + } + impl <'a,T,E> ::capnp::traits::HasTypeId for Builder<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,T,E> ::capnp::traits::FromStructBuilder<'a> for Builder<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, T,E> { + Builder { builder, _phantom: ::core::marker::PhantomData, } + } + } + + impl <'a,T,E> ::capnp::traits::ImbueMut<'a> for Builder<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder.imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl <'a,T,E> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + fn init_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, _size: u32) -> Builder<'a,T,E> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new(builder.get_struct(_private::STRUCT_SIZE, default)?)) + } + } + + impl <'a,T,E> ::capnp::traits::SetPointerBuilder for Reader<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + fn set_pointer_builder<'b>(pointer: ::capnp::private::layout::PointerBuilder<'b>, value: Reader<'a,T,E>, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } + } + + impl <'a,T,E> Builder<'a,T,E> where T: for<'c> ::capnp::traits::Owned<'c>, E: for<'c> ::capnp::traits::Owned<'c> { + pub fn into_reader(self) -> Reader<'a,T,E> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_,T,E> { + Builder { .. *self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_,T,E> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn initn_failed(self, length: u32) -> >::Builder { + self.builder.set_data_field::(0, 0); + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).initn_as(length) + } + #[inline] + pub fn set_failed(&mut self, value: >::Reader) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 0); + ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(0), value, false) + } + #[inline] + pub fn init_failed(self, ) -> >::Builder { + self.builder.set_data_field::(0, 0); + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).init_as() + } + pub fn has_failed(&self) -> bool { + if self.builder.get_data_field::(0) != 0 { return false; } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn initn_successful(self, length: u32) -> >::Builder { + self.builder.set_data_field::(0, 1); + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).initn_as(length) + } + #[inline] + pub fn set_successful(&mut self, value: >::Reader) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 1); + ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(0), value, false) + } + #[inline] + pub fn init_successful(self, ) -> >::Builder { + self.builder.set_data_field::(0, 1); + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).init_as() + } + pub fn has_successful(&self) -> bool { + if self.builder.get_data_field::(0) != 1 { return false; } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.builder.get_data_field::(0) { + 0 => { + ::core::result::Result::Ok(Failed( + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) + )) + } + 1 => { + ::core::result::Result::Ok(Successful( + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) + )) + } + x => ::core::result::Result::Err(::capnp::NotInSchema(x)) + } + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + _phantom: ::core::marker::PhantomData<(T,E)> + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { _typeless: typeless, _phantom: ::core::marker::PhantomData, } + } + } + impl Pipeline where T: ::capnp::traits::Pipelined, ::Pipeline: ::capnp::capability::FromTypelessPipeline, E: ::capnp::traits::Pipelined, ::Pipeline: ::capnp::capability::FromTypelessPipeline { + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 1, pointers: 1 }; + pub const TYPE_ID: u64 = 0xf477_aafa_9205_11aa; + } + pub enum Which { + Failed(A0), + Successful(A1), + } + pub type WhichReader<'a,T,E> = Which<::capnp::Result<>::Reader>,::capnp::Result<>::Reader>>; + pub type WhichBuilder<'a,T,E> = Which<::capnp::Result<>::Builder>,::capnp::Result<>::Builder>>; +} diff --git a/api/src/schema/usersystem_capnp.rs b/api/src/schema/usersystem_capnp.rs index 4241530..ee40cf4 100644 --- a/api/src/schema/usersystem_capnp.rs +++ b/api/src/schema/usersystem_capnp.rs @@ -57,6 +57,10 @@ pub mod user_system { pub fn get_manage(self) -> ::capnp::Result { match self.reader.get_pointer_field(1).get_capability() { ::core::result::Result::Ok(c) => ::core::result::Result::Ok(::capnp::capability::FromClientHook::new(c)), ::core::result::Result::Err(e) => ::core::result::Result::Err(e)} } + #[inline] + pub fn get_search(self) -> ::capnp::Result { + match self.reader.get_pointer_field(2).get_capability() { ::core::result::Result::Ok(c) => ::core::result::Result::Ok(::capnp::capability::FromClientHook::new(c)), ::core::result::Result::Err(e) => ::core::result::Result::Err(e)} + } } pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } @@ -123,6 +127,14 @@ pub mod user_system { pub fn set_manage(&mut self, value: crate::schema::usersystem_capnp::user_system::manage::Client) { self.builder.get_pointer_field(1).set_capability(value.client.hook); } + #[inline] + pub fn get_search(self) -> ::capnp::Result { + match self.builder.get_pointer_field(2).get_capability() { ::core::result::Result::Ok(c) => ::core::result::Result::Ok(::capnp::capability::FromClientHook::new(c)), ::core::result::Result::Err(e) => ::core::result::Result::Err(e)} + } + #[inline] + pub fn set_search(&mut self, value: crate::schema::usersystem_capnp::user_system::search::Client) { + self.builder.get_pointer_field(2).set_capability(value.client.hook); + } } pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } @@ -138,10 +150,13 @@ pub mod user_system { pub fn get_manage(&self) -> crate::schema::usersystem_capnp::user_system::manage::Client { ::capnp::capability::FromClientHook::new(self._typeless.get_pointer_field(1).as_cap()) } + pub fn get_search(&self) -> crate::schema::usersystem_capnp::user_system::search::Client { + ::capnp::capability::FromClientHook::new(self._typeless.get_pointer_field(2).as_cap()) + } } mod _private { use capnp::private::layout; - pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 0, pointers: 2 }; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 0, pointers: 3 }; pub const TYPE_ID: u64 = 0xdabf_c8b5_9d3c_0019; } @@ -351,6 +366,233 @@ pub mod user_system { } + pub mod search { + #![allow(unused_variables)] + pub type GetUserByNameParams<> = ::capnp::capability::Params; + pub type GetUserByNameResults<> = ::capnp::capability::Results>; + + pub struct Client { + pub client: ::capnp::capability::Client, + } + impl ::capnp::capability::FromClientHook for Client { + fn new(hook: Box) -> Client { + Client { client: ::capnp::capability::Client::new(hook), } + } + } + #[derive(Copy, Clone)] + pub struct Owned(()); + impl <'a> ::capnp::traits::Owned<'a> for Owned { type Reader = Client; type Builder = Client; } + impl ::capnp::traits::Pipelined for Owned { type Pipeline = Client; } + impl <'a,> ::capnp::traits::FromPointerReader<'a> for Client<> { + fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, _default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::capability::FromClientHook::new(reader.get_capability()?)) + } + } + impl <'a,> ::capnp::traits::FromPointerBuilder<'a> for Client<> { + fn init_pointer(_builder: ::capnp::private::layout::PointerBuilder<'a>, _size: u32) -> Client<> { + unimplemented!() + } + fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, _default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::capability::FromClientHook::new(builder.get_capability()?)) + } + } + + impl <> ::capnp::traits::SetPointerBuilder for Client<> { + fn set_pointer_builder(pointer: ::capnp::private::layout::PointerBuilder<'_>, from: Client<>, _canonicalize: bool) -> ::capnp::Result<()> { + pointer.set_capability(from.client.hook); + ::core::result::Result::Ok(()) + } + } + impl ::capnp::traits::HasTypeId for Client { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl Clone for Client { + fn clone(&self) -> Client { + Client { client: ::capnp::capability::Client::new(self.client.hook.add_ref()), } + } + } + impl Client { + pub fn get_user_by_name_request(&self) -> ::capnp::capability::Request> { + self.client.new_call(_private::TYPE_ID, 0, None) + } + } + pub trait Server<> { + fn get_user_by_name(&mut self, _: GetUserByNameParams<>, _: GetUserByNameResults<>) -> ::capnp::capability::Promise<(), ::capnp::Error> { ::capnp::capability::Promise::err(::capnp::Error::unimplemented("method not implemented".to_string())) } + } + pub struct ServerDispatch<_T,> { + pub server: _T, + } + impl <_S: Server + 'static, > ::capnp::capability::FromServer<_S> for Client { + type Dispatch = ServerDispatch<_S, >; + fn from_server(s: _S) -> ServerDispatch<_S, > { + ServerDispatch { server: s, } + } + } + impl <_T: Server> ::core::ops::Deref for ServerDispatch<_T> { + type Target = _T; + fn deref(&self) -> &_T { &self.server} + } + impl <_T: Server> ::core::ops::DerefMut for ServerDispatch<_T> { + fn deref_mut(&mut self) -> &mut _T { &mut self.server} + } + impl <_T: Server> ::capnp::capability::Server for ServerDispatch<_T> { + fn dispatch_call(&mut self, interface_id: u64, method_id: u16, params: ::capnp::capability::Params<::capnp::any_pointer::Owned>, results: ::capnp::capability::Results<::capnp::any_pointer::Owned>) -> ::capnp::capability::Promise<(), ::capnp::Error> { + match interface_id { + _private::TYPE_ID => ServerDispatch::<_T, >::dispatch_call_internal(&mut self.server, method_id, params, results), + _ => { ::capnp::capability::Promise::err(::capnp::Error::unimplemented("Method not implemented.".to_string())) } + } + } + } + impl <_T :Server> ServerDispatch<_T> { + pub fn dispatch_call_internal(server: &mut _T, method_id: u16, params: ::capnp::capability::Params<::capnp::any_pointer::Owned>, results: ::capnp::capability::Results<::capnp::any_pointer::Owned>) -> ::capnp::capability::Promise<(), ::capnp::Error> { + match method_id { + 0 => server.get_user_by_name(::capnp::private::capability::internal_get_typed_params(params), ::capnp::private::capability::internal_get_typed_results(results)), + _ => { ::capnp::capability::Promise::err(::capnp::Error::unimplemented("Method not implemented.".to_string())) } + } + } + } + pub mod _private { + pub const TYPE_ID: u64 = 0x9d17_e40c_2f40_05fd; + } + + pub mod get_user_by_name_params { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl <'a> ::capnp::traits::Owned<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl <'a> ::capnp::traits::OwnedStruct<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl ::capnp::traits::Pipelined for Owned { type Pipeline = Pipeline; } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { reader: ::capnp::private::layout::StructReader<'a> } + + impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> { + Reader { reader, } + } + } + + impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> { + fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?)) + } + } + + impl <'a,> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a,> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl <'a,> ::capnp::traits::Imbue<'a> for Reader<'a,> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader.imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl <'a,> Reader<'a,> { + pub fn reborrow(&self) -> Reader<'_,> { + Reader { .. *self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_username(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(0), ::core::option::Option::None) + } + pub fn has_username(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + } + + pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } + impl <'a,> ::capnp::traits::HasStructSize for Builder<'a,> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { _private::STRUCT_SIZE } + } + impl <'a,> ::capnp::traits::HasTypeId for Builder<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructBuilder<'a> for Builder<'a,> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, > { + Builder { builder, } + } + } + + impl <'a,> ::capnp::traits::ImbueMut<'a> for Builder<'a,> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder.imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl <'a,> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a,> { + fn init_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, _size: u32) -> Builder<'a,> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new(builder.get_struct(_private::STRUCT_SIZE, default)?)) + } + } + + impl <'a,> ::capnp::traits::SetPointerBuilder for Reader<'a,> { + fn set_pointer_builder<'b>(pointer: ::capnp::private::layout::PointerBuilder<'b>, value: Reader<'a,>, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } + } + + impl <'a,> Builder<'a,> { + pub fn into_reader(self) -> Reader<'a,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_,> { + Builder { .. *self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_username(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) + } + #[inline] + pub fn set_username(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_username(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(0).init_text(size) + } + pub fn has_username(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + } + + pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { _typeless: typeless, } + } + } + impl Pipeline { + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 0, pointers: 1 }; + pub const TYPE_ID: u64 = 0xd850_6330_6f45_65ca; + } + } + } + + pub mod manage { #![allow(unused_variables)] pub type GetUserListParams<> = ::capnp::capability::Params; @@ -359,6 +601,8 @@ pub mod user_system { pub type AddUserResults<> = ::capnp::capability::Results; pub type RemoveUserParams<> = ::capnp::capability::Params; pub type RemoveUserResults<> = ::capnp::capability::Results; + pub type AddUserFallibleParams<> = ::capnp::capability::Params; + pub type AddUserFallibleResults<> = ::capnp::capability::Results>; pub struct Client { pub client: ::capnp::capability::Client, @@ -411,11 +655,15 @@ pub mod user_system { pub fn remove_user_request(&self) -> ::capnp::capability::Request { self.client.new_call(_private::TYPE_ID, 2, None) } + pub fn add_user_fallible_request(&self) -> ::capnp::capability::Request> { + self.client.new_call(_private::TYPE_ID, 3, None) + } } pub trait Server<> { fn get_user_list(&mut self, _: GetUserListParams<>, _: GetUserListResults<>) -> ::capnp::capability::Promise<(), ::capnp::Error> { ::capnp::capability::Promise::err(::capnp::Error::unimplemented("method not implemented".to_string())) } fn add_user(&mut self, _: AddUserParams<>, _: AddUserResults<>) -> ::capnp::capability::Promise<(), ::capnp::Error> { ::capnp::capability::Promise::err(::capnp::Error::unimplemented("method not implemented".to_string())) } fn remove_user(&mut self, _: RemoveUserParams<>, _: RemoveUserResults<>) -> ::capnp::capability::Promise<(), ::capnp::Error> { ::capnp::capability::Promise::err(::capnp::Error::unimplemented("method not implemented".to_string())) } + fn add_user_fallible(&mut self, _: AddUserFallibleParams<>, _: AddUserFallibleResults<>) -> ::capnp::capability::Promise<(), ::capnp::Error> { ::capnp::capability::Promise::err(::capnp::Error::unimplemented("method not implemented".to_string())) } } pub struct ServerDispatch<_T,> { pub server: _T, @@ -447,6 +695,7 @@ pub mod user_system { 0 => server.get_user_list(::capnp::private::capability::internal_get_typed_params(params), ::capnp::private::capability::internal_get_typed_results(results)), 1 => server.add_user(::capnp::private::capability::internal_get_typed_params(params), ::capnp::private::capability::internal_get_typed_results(results)), 2 => server.remove_user(::capnp::private::capability::internal_get_typed_params(params), ::capnp::private::capability::internal_get_typed_results(results)), + 3 => server.add_user_fallible(::capnp::private::capability::internal_get_typed_params(params), ::capnp::private::capability::internal_get_typed_results(results)), _ => { ::capnp::capability::Promise::err(::capnp::Error::unimplemented("Method not implemented.".to_string())) } } } @@ -455,6 +704,158 @@ pub mod user_system { pub const TYPE_ID: u64 = 0x9971_b909_6e1d_868c; } + pub mod add_user_error { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl <'a> ::capnp::traits::Owned<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl <'a> ::capnp::traits::OwnedStruct<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl ::capnp::traits::Pipelined for Owned { type Pipeline = Pipeline; } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { reader: ::capnp::private::layout::StructReader<'a> } + + impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> { + Reader { reader, } + } + } + + impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> { + fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?)) + } + } + + impl <'a,> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a,> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl <'a,> ::capnp::traits::Imbue<'a> for Reader<'a,> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader.imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl <'a,> Reader<'a,> { + pub fn reborrow(&self) -> Reader<'_,> { + Reader { .. *self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_error(self) -> ::core::result::Result { + ::capnp::traits::FromU16::from_u16(self.reader.get_data_field::(0)) + } + } + + pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } + impl <'a,> ::capnp::traits::HasStructSize for Builder<'a,> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { _private::STRUCT_SIZE } + } + impl <'a,> ::capnp::traits::HasTypeId for Builder<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructBuilder<'a> for Builder<'a,> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, > { + Builder { builder, } + } + } + + impl <'a,> ::capnp::traits::ImbueMut<'a> for Builder<'a,> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder.imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl <'a,> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a,> { + fn init_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, _size: u32) -> Builder<'a,> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new(builder.get_struct(_private::STRUCT_SIZE, default)?)) + } + } + + impl <'a,> ::capnp::traits::SetPointerBuilder for Reader<'a,> { + fn set_pointer_builder<'b>(pointer: ::capnp::private::layout::PointerBuilder<'b>, value: Reader<'a,>, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } + } + + impl <'a,> Builder<'a,> { + pub fn into_reader(self) -> Reader<'a,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_,> { + Builder { .. *self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_error(self) -> ::core::result::Result { + ::capnp::traits::FromU16::from_u16(self.builder.get_data_field::(0)) + } + #[inline] + pub fn set_error(&mut self, value: crate::schema::usersystem_capnp::user_system::manage::add_user_error::AddUserError) { + self.builder.set_data_field::(0, value as u16) + } + } + + pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { _typeless: typeless, } + } + } + impl Pipeline { + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 1, pointers: 0 }; + pub const TYPE_ID: u64 = 0xf892_55fa_c5eb_df90; + } + + #[repr(u16)] + #[derive(Clone, Copy, Debug, PartialEq)] + pub enum AddUserError { + AlreadyExists = 0, + UsernameInvalid = 1, + PasswordInvalid = 2, + } + impl ::capnp::traits::FromU16 for AddUserError { + #[inline] + fn from_u16(value: u16) -> ::core::result::Result { + match value { + 0 => ::core::result::Result::Ok(AddUserError::AlreadyExists), + 1 => ::core::result::Result::Ok(AddUserError::UsernameInvalid), + 2 => ::core::result::Result::Ok(AddUserError::PasswordInvalid), + n => ::core::result::Result::Err(::capnp::NotInSchema(n)), + } + } + } + impl ::capnp::traits::ToU16 for AddUserError { + #[inline] + fn to_u16(self) -> u16 { self as u16 } + } + impl ::capnp::traits::HasTypeId for AddUserError { + #[inline] + fn type_id() -> u64 { 0x9623_12d4_e9d7_4876u64 } + } + } + pub mod get_user_list_params { #[derive(Copy, Clone)] pub struct Owned(()); @@ -1110,5 +1511,162 @@ pub mod user_system { pub const TYPE_ID: u64 = 0xdfb7_a55c_6d34_06be; } } + + pub mod add_user_fallible_params { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl <'a> ::capnp::traits::Owned<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl <'a> ::capnp::traits::OwnedStruct<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; } + impl ::capnp::traits::Pipelined for Owned { type Pipeline = Pipeline; } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { reader: ::capnp::private::layout::StructReader<'a> } + + impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> { + Reader { reader, } + } + } + + impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> { + fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?)) + } + } + + impl <'a,> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a,> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl <'a,> ::capnp::traits::Imbue<'a> for Reader<'a,> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader.imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl <'a,> Reader<'a,> { + pub fn reborrow(&self) -> Reader<'_,> { + Reader { .. *self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_username(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(0), ::core::option::Option::None) + } + pub fn has_username(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_password(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(1), ::core::option::Option::None) + } + pub fn has_password(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + } + + pub struct Builder<'a> { builder: ::capnp::private::layout::StructBuilder<'a> } + impl <'a,> ::capnp::traits::HasStructSize for Builder<'a,> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { _private::STRUCT_SIZE } + } + impl <'a,> ::capnp::traits::HasTypeId for Builder<'a,> { + #[inline] + fn type_id() -> u64 { _private::TYPE_ID } + } + impl <'a,> ::capnp::traits::FromStructBuilder<'a> for Builder<'a,> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, > { + Builder { builder, } + } + } + + impl <'a,> ::capnp::traits::ImbueMut<'a> for Builder<'a,> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder.imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl <'a,> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a,> { + fn init_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, _size: u32) -> Builder<'a,> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new(builder.get_struct(_private::STRUCT_SIZE, default)?)) + } + } + + impl <'a,> ::capnp::traits::SetPointerBuilder for Reader<'a,> { + fn set_pointer_builder<'b>(pointer: ::capnp::private::layout::PointerBuilder<'b>, value: Reader<'a,>, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } + } + + impl <'a,> Builder<'a,> { + pub fn into_reader(self) -> Reader<'a,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_,> { + Builder { .. *self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_,> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_username(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) + } + #[inline] + pub fn set_username(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_username(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(0).init_text(size) + } + pub fn has_username(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_password(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None) + } + #[inline] + pub fn set_password(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(1).set_text(value); + } + #[inline] + pub fn init_password(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(1).init_text(size) + } + pub fn has_password(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + } + + pub struct Pipeline { _typeless: ::capnp::any_pointer::Pipeline } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { _typeless: typeless, } + } + } + impl Pipeline { + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 0, pointers: 2 }; + pub const TYPE_ID: u64 = 0xf5bf_a6eb_aa16_f44c; + } + } } } diff --git a/bffhd/capnp/machine.rs b/bffhd/capnp/machine.rs index f36386c..d05d4f2 100644 --- a/bffhd/capnp/machine.rs +++ b/bffhd/capnp/machine.rs @@ -1,18 +1,15 @@ +use crate::capnp::user::User; use crate::resources::modules::fabaccess::{ArchivedStatus, Status}; use crate::resources::Resource; use crate::session::SessionHandle; -use api::machine_capnp::machine::{ - self, - admin, admin::Server as AdminServer, check, check::Server as CheckServer, in_use as inuse, - in_use::Server as InUseServer, info, info::Server as InfoServer, manage, - manage::Server as ManageServer, use_, use_::Server as UseServer, - - MachineState, -}; use api::general_capnp::optional; +use api::machine_capnp::machine::{ + self, admin, admin::Server as AdminServer, check, check::Server as CheckServer, + in_use as inuse, in_use::Server as InUseServer, info, info::Server as InfoServer, manage, + manage::Server as ManageServer, use_, use_::Server as UseServer, MachineState, +}; use capnp::capability::Promise; use capnp_rpc::pry; -use crate::capnp::user::User; #[derive(Clone)] pub struct Machine { @@ -37,18 +34,23 @@ impl Machine { if let Some(ref category) = self.resource.get_description().category { builder.set_category(category); } - builder.set_urn(&format!("urn:fabaccess:resource:{}", self.resource.get_id())); + builder.set_urn(&format!( + "urn:fabaccess:resource:{}", + self.resource.get_id() + )); { let user = self.session.get_user_ref(); let state = self.resource.get_state_ref(); let state = state.as_ref(); - if self.session.has_write(&self.resource) && match &state.inner.state { - ArchivedStatus::Free => true, - ArchivedStatus::Reserved(reserver) if reserver == &user => true, - _ => false, - } { + if self.session.has_write(&self.resource) + && match &state.inner.state { + ArchivedStatus::Free => true, + ArchivedStatus::Reserved(reserver) if reserver == &user => true, + _ => false, + } + { builder.set_use(capnp_rpc::new_client(self.clone())); } @@ -67,7 +69,7 @@ impl Machine { builder.set_inuse(capnp_rpc::new_client(self.clone())); } MachineState::InUse - }, + } ArchivedStatus::Reserved(_) => MachineState::Reserved, ArchivedStatus::ToCheck(_) => MachineState::ToCheck, }; @@ -85,7 +87,11 @@ impl Machine { this.build_into(builder) } - pub fn optional_build(session: SessionHandle, resource: Resource, builder: optional::Builder) { + pub fn optional_build( + session: SessionHandle, + resource: Resource, + builder: optional::Builder, + ) { let this = Self::new(session.clone(), resource.clone()); if this.resource.visible(&session) || session.has_read(&resource) { let builder = builder.init_just(); @@ -135,9 +141,7 @@ impl UseServer for Machine { let session = self.session.clone(); Promise::from_future(async move { let user = session.get_user_ref(); - resource - .try_update(session, Status::Reserved(user)) - .await; + resource.try_update(session, Status::Reserved(user)).await; Ok(()) }) } @@ -208,8 +212,16 @@ impl ManageServer for Machine { ) -> Promise<(), ::capnp::Error> { let mut builder = result.get(); let user = User::new_self(self.session.clone()); - user.build_optional(self.resource.get_current_user(), builder.reborrow().init_current_user()); - user.build_optional(self.resource.get_previous_user(), builder.init_last_user()); + User::build_optional( + &self.session, + self.resource.get_current_user(), + builder.reborrow().init_current_user(), + ); + User::build_optional( + &self.session, + self.resource.get_previous_user(), + builder.init_last_user(), + ); Promise::ok(()) } fn set_property( @@ -310,9 +322,11 @@ impl AdminServer for Machine { APIMState::InUse => Status::InUse(user), APIMState::Reserved => Status::Reserved(user), APIMState::ToCheck => Status::ToCheck(user), - APIMState::Totakeover => return Promise::err(::capnp::Error::unimplemented( + APIMState::Totakeover => { + return Promise::err(::capnp::Error::unimplemented( "totakeover not implemented".to_string(), - )), + )) + } }; let resource = self.resource.clone(); Promise::from_future(async move { diff --git a/bffhd/capnp/user.rs b/bffhd/capnp/user.rs index 8442301..d2ae1f5 100644 --- a/bffhd/capnp/user.rs +++ b/bffhd/capnp/user.rs @@ -22,10 +22,10 @@ impl User { Self::new(session, user) } - pub fn build_optional(&self, user: Option, builder: optional::Builder) { - if let Some(user) = user.and_then(|u| self.session.users.get_user(u.get_username())) { + pub fn build_optional(session: &SessionHandle, user: Option, builder: optional::Builder) { + if let Some(user) = user.and_then(|u| session.users.get_user(u.get_username())) { let builder = builder.init_just(); - Self::fill(&self.session, user, builder); + Self::fill(&session, user, builder); } } diff --git a/bffhd/capnp/user_system.rs b/bffhd/capnp/user_system.rs index c0569fe..825165f 100644 --- a/bffhd/capnp/user_system.rs +++ b/bffhd/capnp/user_system.rs @@ -1,13 +1,13 @@ use capnp::capability::Promise; use capnp_rpc::pry; use api::usersystem_capnp::user_system::{ - info, manage, + info, manage, search }; use crate::capnp::user::User; use crate::session::SessionHandle; -use crate::users::db; +use crate::users::{db, UserRef}; #[derive(Clone)] @@ -93,3 +93,16 @@ impl manage::Server for Users { Promise::ok(()) } } + +impl search::Server for Users { + fn get_user_by_name( + &mut self, + params: search::GetUserByNameParams, + mut result: search::GetUserByNameResults, + ) -> Promise<(), ::capnp::Error> { + let username: &str = pry!(pry!(params.get()).get_username()); + let userref = UserRef::new(username.to_string()); + User::build_optional(&self.session, Some(userref), result.get()); + Promise::ok(()) + } +} \ No newline at end of file