initial commit

This commit is contained in:
yggverse 2024-10-22 20:45:42 +03:00
parent 381a398de1
commit a7083852c3
22 changed files with 446 additions and 15 deletions

View file

@ -0,0 +1,31 @@
pub mod error;
pub use error::Error;
use glib::GString;
/// https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes
pub enum Status {
Input,
SensitiveInput,
Success,
Redirect,
} // @TODO
pub fn from_header(buffer: &[u8] /* @TODO */) -> Result<Status, Error> {
match buffer.get(0..2) {
Some(bytes) => match GString::from_utf8(bytes.to_vec()) {
Ok(string) => from_string(string.as_str()),
Err(_) => Err(Error::Decode),
},
None => Err(Error::Undefined),
}
}
pub fn from_string(code: &str) -> Result<Status, Error> {
match code {
"10" => Ok(Status::Input),
"11" => Ok(Status::SensitiveInput),
"20" => Ok(Status::Success),
_ => Err(Error::Undefined),
}
}