mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-03 15:04:13 +00:00
begin new multi-protocol parser implementation for Client
This commit is contained in:
parent
b43f0b68f8
commit
042ace98d3
@ -1,7 +1,9 @@
|
|||||||
|
mod protocol;
|
||||||
mod redirect;
|
mod redirect;
|
||||||
mod status;
|
mod status;
|
||||||
|
|
||||||
// Children dependencies
|
// Children dependencies
|
||||||
|
use protocol::Protocol;
|
||||||
use redirect::Redirect;
|
use redirect::Redirect;
|
||||||
use status::Status;
|
use status::Status;
|
||||||
|
|
||||||
@ -84,5 +86,11 @@ impl Client {
|
|||||||
.replace(Status::failure_redirect_limit(redirect::LIMIT, true));
|
.replace(Status::failure_redirect_limit(redirect::LIMIT, true));
|
||||||
// @TODO return;
|
// @TODO return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Route request by protocol
|
||||||
|
match Protocol::from_string(query) {
|
||||||
|
Protocol::Gemini { uri } | Protocol::Titan { uri } => todo!("{uri}"),
|
||||||
|
Protocol::Undefined => todo!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
src/app/browser/window/tab/item/page/client/protocol.rs
Normal file
34
src/app/browser/window/tab/item/page/client/protocol.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
mod mode;
|
||||||
|
mod uri;
|
||||||
|
|
||||||
|
use mode::Mode;
|
||||||
|
|
||||||
|
use gtk::glib::{Uri, UriFlags};
|
||||||
|
|
||||||
|
pub enum Protocol {
|
||||||
|
Gemini { /*mode: Mode,*/ uri: Uri },
|
||||||
|
Titan { /*mode: Mode,*/ uri: Uri },
|
||||||
|
Undefined,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Protocol {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
/// Create new `Self` from parsable request string
|
||||||
|
pub fn from_string(request: &str) -> Self {
|
||||||
|
match Mode::from_string(request) {
|
||||||
|
Mode::Default { request } | Mode::Download { request } | Mode::Source { request } => {
|
||||||
|
match Uri::parse(&request, UriFlags::NONE) {
|
||||||
|
Ok(uri) => match uri.scheme().as_str() {
|
||||||
|
"gemini" => Self::Gemini { uri },
|
||||||
|
"titan" => Self::Titan { uri },
|
||||||
|
_ => Self::Undefined,
|
||||||
|
},
|
||||||
|
Err(_) => Self::Gemini {
|
||||||
|
uri: uri::tgls(&request),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
src/app/browser/window/tab/item/page/client/protocol/mode.rs
Normal file
28
src/app/browser/window/tab/item/page/client/protocol/mode.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
pub enum Mode {
|
||||||
|
Default { request: String },
|
||||||
|
Download { request: String },
|
||||||
|
Source { request: String },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Mode {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
/// Parse new `Self` from string
|
||||||
|
pub fn from_string(request: &str) -> Self {
|
||||||
|
if let Some(postfix) = request.strip_prefix("download:") {
|
||||||
|
return Self::Download {
|
||||||
|
request: postfix.to_string(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(postfix) = request.strip_prefix("source:") {
|
||||||
|
return Self::Source {
|
||||||
|
request: postfix.to_string(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::Default {
|
||||||
|
request: request.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
src/app/browser/window/tab/item/page/client/protocol/uri.rs
Normal file
18
src/app/browser/window/tab/item/page/client/protocol/uri.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//! Search providers [Uri](https://docs.gtk.org/glib/struct.Uri.html) asset
|
||||||
|
|
||||||
|
// Global dependencies
|
||||||
|
use gtk::glib::{Uri, UriFlags};
|
||||||
|
|
||||||
|
/// Build TGLS [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||||
|
pub fn tgls(request: &str) -> Uri {
|
||||||
|
Uri::build(
|
||||||
|
UriFlags::NONE,
|
||||||
|
"gemini",
|
||||||
|
None,
|
||||||
|
Some("tlgs.one"),
|
||||||
|
1965,
|
||||||
|
"search",
|
||||||
|
Some(&Uri::escape_string(request, None, false)), // @TODO is `escape_string` really wanted in `build` context?
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user