fingers

Finger client library in Rust
Log | Files | Refs | README | LICENSE

commit 415049204a7c3d958b60ed601ad5daaa3fc4566c
parent e0ae73f2d8375347ecb62a5ff138074270741742
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed,  1 Dec 2021 23:18:50 -0800

Cleanup documentation

Diffstat:
MREADME | 8++------
Msrc/lib.rs | 27++++++++++++++++++---------
2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/README b/README @@ -1,12 +1,8 @@ finge.rs ======== -finger client library +A simple, 0-dependency finger client library. Sort of implements https://datatracker.ietf.org/doc/html/rfc1288 -- main difference is ASCII -> UTF8 (which most finger servers I've encountered support) -0 dependencies outside stdlib - -not production ready for your finger-based startup. needs timeouts, etc - -WIP +Comes with a free built-in client in main.rs. JOIN THE FINGER REVIVAL! diff --git a/src/lib.rs b/src/lib.rs @@ -1,9 +1,11 @@ //! A finger client library -//! See https://datatracker.ietf.org/doc/html/rfc1288 +//! +//! See [RFC 1288](https://datatracker.ietf.org/doc/html/rfc1288), which this library loosely +//! implements +//! //! Be mature. //! //! Inspired by Elif Batuman's "The Idiot" -//! https://datatracker.ietf.org/doc/html/draft-ietf-uri-url-finger-02 use std::io::prelude::*; use std::net::{TcpStream, ToSocketAddrs}; @@ -37,6 +39,8 @@ pub struct Request { max_response_len: Option<u64>, } +/// Builds a URL +/// /// From the draft spec: /// https://datatracker.ietf.org/doc/html/draft-ietf-uri-url-finger-02 pub fn from_url(url: &str) -> Result<Request, Error> { @@ -49,9 +53,9 @@ pub fn from_url(url: &str) -> Result<Request, Error> { return Err(Error::InvalidFingerURL); } -// TODO better host resolving -/// rfc1288 2.2 is ignored, queries are UTF-8 strings -/// Uses sensible defaults for timeout and response len +/// Build a finger request +/// +/// rfc1288 2.2 is ignored, queries are UTF-8 strings. /// Host can include port. Defaults to 79 if not included pub fn finger(query: &str, host: &str) -> Request { let mut q = String::new(); @@ -63,20 +67,25 @@ pub fn finger(query: &str, host: &str) -> Request { Request { query: q.to_owned(), host: host.to_owned(), - timeout: Some(10), - max_response_len: Some(1024 * 10), // 10KB + timeout: None, + max_response_len: None, } } + impl Request { pub fn timeout(mut self, timeout: Option<u64>) -> Request { self.timeout = timeout; self } + pub fn max_response_len(mut self, mrl: Option<u64>) -> Request { self.max_response_len = mrl; self } - /// rfc1288 2.2 is ignored, we will allow UTF-8 + + /// Send the finger request + /// + /// rfc1288 2.2 is ignored, we will allow UTF-8. Returns a UTF-8 string pub fn send(self) -> Result<String, Error> { let dest: String; if !self.host.contains(":") { @@ -104,7 +113,7 @@ impl Request { Some(mrl) => stream.take(mrl).read_to_end(&mut line)?, None => stream.read_to_end(&mut line)?, }; - + // Finger responses are small, and always text. Parse as string. return Ok(str::from_utf8(&line)?.to_owned()); } }