mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
implement to_network_address method
This commit is contained in:
parent
007921f73f
commit
fecbbff18f
4 changed files with 42 additions and 13 deletions
|
|
@ -65,13 +65,7 @@ impl Client {
|
||||||
// Begin new connection
|
// Begin new connection
|
||||||
// * [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) required for valid
|
// * [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) required for valid
|
||||||
// [SNI](https://geminiprotocol.net/docs/protocol-specification.gmi#server-name-indication)
|
// [SNI](https://geminiprotocol.net/docs/protocol-specification.gmi#server-name-indication)
|
||||||
match crate::gio::network_address::from_uri(
|
match request.to_network_address() {
|
||||||
&match request {
|
|
||||||
Request::Gemini(ref request) => request.uri.clone(),
|
|
||||||
Request::Titan(ref request) => request.uri.clone(),
|
|
||||||
},
|
|
||||||
crate::DEFAULT_PORT,
|
|
||||||
) {
|
|
||||||
Ok(network_address) => {
|
Ok(network_address) => {
|
||||||
self.socket
|
self.socket
|
||||||
.connect_async(&network_address.clone(), Some(&cancellable.clone()), {
|
.connect_async(&network_address.clone(), Some(&cancellable.clone()), {
|
||||||
|
|
@ -112,7 +106,7 @@ impl Client {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(e) => callback(Err(Error::NetworkAddress(e))),
|
Err(e) => callback(Err(Error::Request(e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,33 @@
|
||||||
|
pub mod error;
|
||||||
pub mod gemini;
|
pub mod gemini;
|
||||||
pub mod titan;
|
pub mod titan;
|
||||||
|
|
||||||
|
pub use error::Error;
|
||||||
pub use gemini::Gemini;
|
pub use gemini::Gemini;
|
||||||
pub use titan::Titan;
|
pub use titan::Titan;
|
||||||
|
|
||||||
|
use gio::NetworkAddress;
|
||||||
|
|
||||||
|
/// Single `Request` holder for different protocols
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
Gemini(Gemini),
|
Gemini(Gemini),
|
||||||
Titan(Titan),
|
Titan(Titan),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Request {
|
||||||
|
// Getters
|
||||||
|
|
||||||
|
/// Convert `Self` to [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html)
|
||||||
|
pub fn to_network_address(&self) -> Result<NetworkAddress, Error> {
|
||||||
|
match crate::gio::network_address::from_uri(
|
||||||
|
&match self {
|
||||||
|
Request::Gemini(ref request) => request.uri.clone(),
|
||||||
|
Request::Titan(ref request) => request.uri.clone(),
|
||||||
|
},
|
||||||
|
crate::DEFAULT_PORT,
|
||||||
|
) {
|
||||||
|
Ok(network_address) => Ok(network_address),
|
||||||
|
Err(e) => Err(Error::NetworkAddress(e)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
16
src/client/connection/request/error.rs
Normal file
16
src/client/connection/request/error.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
use std::fmt::{Display, Formatter, Result};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
NetworkAddress(crate::gio::network_address::error::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
|
match self {
|
||||||
|
Self::NetworkAddress(e) => {
|
||||||
|
write!(f, "Network Address error: {e}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,8 +4,7 @@ use std::fmt::{Display, Formatter, Result};
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Connect(glib::Error),
|
Connect(glib::Error),
|
||||||
Connection(crate::client::connection::Error),
|
Connection(crate::client::connection::Error),
|
||||||
NetworkAddress(crate::gio::network_address::Error),
|
Request(crate::client::connection::request::Error),
|
||||||
Request(glib::Error),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
|
|
@ -17,9 +16,6 @@ impl Display for Error {
|
||||||
Self::Connect(e) => {
|
Self::Connect(e) => {
|
||||||
write!(f, "Connect error: {e}")
|
write!(f, "Connect error: {e}")
|
||||||
}
|
}
|
||||||
Self::NetworkAddress(e) => {
|
|
||||||
write!(f, "Network address error: {e}")
|
|
||||||
}
|
|
||||||
Self::Request(e) => {
|
Self::Request(e) => {
|
||||||
write!(f, "Request error: {e}")
|
write!(f, "Request error: {e}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue