From de296f20d913dc91e46a3dc017092a7c7d2f5506 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 31 Jan 2026 12:57:03 +0900 Subject: [PATCH] server/varlink_api: register finger api --- src/proto/finger_protocol.rs | 7 +-- src/server/varlink_api.rs | 93 +++++++++++++++++++++++++++++------- 2 files changed, 81 insertions(+), 19 deletions(-) diff --git a/src/proto/finger_protocol.rs b/src/proto/finger_protocol.rs index 971149a..ec49513 100644 --- a/src/proto/finger_protocol.rs +++ b/src/proto/finger_protocol.rs @@ -1,5 +1,6 @@ -#[derive(Debug, Clone, PartialEq, Eq)] -#[repr(C)] +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct FingerRequest { long: bool, name: String, @@ -38,7 +39,7 @@ impl FingerRequest { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct FingerResponse(String); impl FingerResponse { diff --git a/src/server/varlink_api.rs b/src/server/varlink_api.rs index cd99676..50b4070 100644 --- a/src/server/varlink_api.rs +++ b/src/server/varlink_api.rs @@ -3,18 +3,17 @@ use serde::{Deserialize, Serialize}; use zlink::{ReplyError, service::MethodReply}; use crate::{ - proto::{WhodStatusUpdate, WhodUserEntry}, + proto::{WhodStatusUpdate, WhodUserEntry, finger_protocol::FingerResponse}, server::rwhod::RwhodStatusStore, }; +// Types for 'no.ntnu.pvv.roowho2.rwhod' + #[zlink::proxy("no.ntnu.pvv.roowho2.rwhod")] pub trait RwhodClientProxy { - async fn rwho( - &mut self, - all: bool, - ) -> zlink::Result, RwhodClientError>>; + async fn rwho(&mut self, all: bool) -> zlink::Result>; - async fn ruptime(&mut self) -> zlink::Result, RwhodClientError>>; + async fn ruptime(&mut self) -> zlink::Result>; } #[derive(Debug, Deserialize)] @@ -30,7 +29,7 @@ pub enum RwhodClientRequest { Ruptime, } -#[derive(Debug, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize)] #[serde(untagged)] pub enum RwhodClientResponse { Rwho(RwhoResponse), @@ -40,12 +39,69 @@ pub enum RwhodClientResponse { pub type RwhoResponse = Vec<(String, WhodUserEntry)>; pub type RuptimeResponse = Vec; -#[derive(Debug, ReplyError)] +#[derive(Debug, Clone, PartialEq, ReplyError)] #[zlink(interface = "no.ntnu.pvv.roowho2.rwhod")] pub enum RwhodClientError { InvalidRequest, } +// Types for 'no.ntnu.pvv.roowho2.finger' + +#[zlink::proxy("no.ntnu.pvv.roowho2.finger")] +pub trait FingerClientProxy { + async fn finger( + &mut self, + user_queries: Vec, + ) -> zlink::Result>; +} + +#[derive(Debug, Deserialize)] +#[serde(tag = "method", content = "parameters")] +pub enum FingerClientRequest { + #[serde(rename = "no.ntnu.pvv.roowho2.finger.Finger")] + Finger { user_queries: Vec }, +} + +#[derive(Debug, Serialize)] +#[serde(untagged)] +pub enum FingerClientResponse { + Finger(ZlinkFingerResponse), +} + +pub type ZlinkFingerResponse = FingerResponse; + +#[derive(Debug, Clone, PartialEq, ReplyError)] +#[zlink(interface = "no.ntnu.pvv.roowho2.finger")] +pub enum FingerClientError { + InvalidRequest, +} + +// -------------------- + +#[derive(Debug, Deserialize)] +#[serde(untagged)] +#[allow(unused)] +pub enum Method { + Rwhod(RwhodClientRequest), + Finger(FingerClientRequest), +} + +#[derive(Debug, Serialize)] +#[serde(untagged)] +#[allow(unused)] +pub enum Reply { + Rwhod(RwhodClientResponse), + Finger(FingerClientResponse), +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(untagged)] +#[allow(unused)] +pub enum ReplyError { + Rwhod(RwhodClientError), + Finger(FingerClientError), +} + #[derive(Debug, Clone)] pub struct Roowhoo2ClientServer { whod_status_store: RwhodStatusStore, @@ -83,11 +139,11 @@ impl Roowhoo2ClientServer { } impl zlink::Service for Roowhoo2ClientServer { - type MethodCall<'de> = RwhodClientRequest; - type ReplyParams<'se> = RwhodClientResponse; + type MethodCall<'de> = Method; + type ReplyParams<'se> = Reply; type ReplyStreamParams = (); type ReplyStream = futures_util::stream::Empty>; - type ReplyError<'se> = RwhodClientError; + type ReplyError<'se> = ReplyError; async fn handle<'service, Sock: zlink::connection::Socket>( &'service mut self, @@ -96,12 +152,17 @@ impl zlink::Service for Roowhoo2ClientServer { ) -> MethodReply, Self::ReplyStream, Self::ReplyError<'service>> { match call.method() { - RwhodClientRequest::Rwho { all } => MethodReply::Single(Some( - RwhodClientResponse::Rwho(self.handle_rwho_request(*all).await), - )), - RwhodClientRequest::Ruptime => MethodReply::Single(Some(RwhodClientResponse::Ruptime( - self.handle_ruptime_request().await, + Method::Rwhod(RwhodClientRequest::Rwho { all }) => { + MethodReply::Single(Some(Reply::Rwhod(RwhodClientResponse::Rwho( + self.handle_rwho_request(*all).await, + )))) + } + Method::Rwhod(RwhodClientRequest::Ruptime) => MethodReply::Single(Some(Reply::Rwhod( + RwhodClientResponse::Ruptime(self.handle_ruptime_request().await), ))), + Method::Finger(FingerClientRequest::Finger { user_queries: _ }) => { + unimplemented!() + } } } }