diff --git a/src/proto/finger_protocol.rs b/src/proto/finger_protocol.rs index 8b13789..cb0b1dc 100644 --- a/src/proto/finger_protocol.rs +++ b/src/proto/finger_protocol.rs @@ -1 +1,55 @@ +use std::path::PathBuf; +use chrono::{DateTime, Utc}; +use nix::libc::uid_t; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct FingerPerson { + /// User id + uid: uid_t, + /// User' home directory + dir: PathBuf, + /// Home phone no. + homephone: String, + /// Login name + name: String, + /// Office name + office: String, + /// Office phone no. + officephone: String, + /// Full name + realname: String, + /// User's shell + shell: String, + /// Last time mail was read + mailread: DateTime, + /// Last time mail was received + mailrecv: DateTime, + /// List of where the user is or has been + where_: Vec, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct FingerWhere { + /// Type/status of request + status: FingerWhereStatus, + /// Tty is writable + writable: bool, + /// Time of (last) login + loginat: DateTime, + /// how long idle (if logged in) + idletime: DateTime, + // TODO: are technically limited by UT_LINESIZE and UT_HOSTSIZE + /// Tty line + tty: String, + /// Remote hostname + host: String, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[repr(C)] +pub enum FingerWhereStatus { + LastLog, + LoggedIn, +} diff --git a/src/server/varlink_api.rs b/src/server/varlink_api.rs index f007536..5e7061e 100644 --- a/src/server/varlink_api.rs +++ b/src/server/varlink_api.rs @@ -3,10 +3,12 @@ use serde::{Deserialize, Serialize}; use zlink::{ReplyError, service::MethodReply}; use crate::{ - proto::{WhodStatusUpdate, WhodUserEntry}, + proto::{WhodStatusUpdate, WhodUserEntry, finger_protocol::FingerPerson}, server::rwhod::RwhodStatusStore, }; +// Types for 'no.ntnu.pvv.roowho2.rwhod' + #[zlink::proxy("no.ntnu.pvv.roowho2.rwhod")] pub trait RwhodClientProxy { async fn rwho( @@ -40,12 +42,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, FingerClientError>>; +} + +#[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(FingerResponse), +} + +pub type FingerResponse = Vec; + +#[derive(Debug, Clone, PartialEq, ReplyError)] +#[zlink(interface = "no.ntnu.pvv.roowho2.finger")] +pub enum FingerClientError { + InvalidRequest, +} + +// -------------------- + +#[derive(Debug, Deserialize)] +#[serde(untagged)] +#[allow(unused)] +enum Method { + Rwhod(RwhodClientRequest), + Finger(FingerClientRequest), +} + +#[derive(Debug, Serialize)] +#[serde(untagged)] +#[allow(unused)] +enum Reply { + Rwhod(RwhodClientResponse), + Finger(FingerClientResponse), +} + +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(untagged)] +#[allow(unused)] +enum ReplyError { + Rwhod(RwhodClientError), + Finger(FingerClientError), +} + #[derive(Debug, Clone)] pub struct Roowhoo2ClientServer { whod_status_store: RwhodStatusStore,