mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
update all sessions match certificate scope
This commit is contained in:
parent
c12c57cc99
commit
0f8b98c395
1 changed files with 28 additions and 35 deletions
|
|
@ -6,7 +6,7 @@ use gio::{
|
||||||
prelude::{TlsCertificateExt, TlsConnectionExt},
|
prelude::{TlsCertificateExt, TlsConnectionExt},
|
||||||
TlsCertificate,
|
TlsCertificate,
|
||||||
};
|
};
|
||||||
use glib::Uri;
|
use glib::{Uri, UriHideFlags};
|
||||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||||
|
|
||||||
/// Request sessions holder
|
/// Request sessions holder
|
||||||
|
|
@ -28,10 +28,6 @@ impl Session {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, request: &str) -> Option<Rc<Connection>> {
|
|
||||||
self.index.borrow().get(request).cloned()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set(&self, request: String, connection: Rc<Connection>) -> Option<Rc<Connection>> {
|
pub fn set(&self, request: String, connection: Rc<Connection>) -> Option<Rc<Connection>> {
|
||||||
self.index.borrow_mut().insert(request, connection)
|
self.index.borrow_mut().insert(request, connection)
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +37,13 @@ impl Session {
|
||||||
/// * force rehandshake on user certificate was changed in runtime (ignore default session resumption by Glib TLS backend implementation)
|
/// * force rehandshake on user certificate was changed in runtime (ignore default session resumption by Glib TLS backend implementation)
|
||||||
/// * close previous connection match `Uri` if not closed yet
|
/// * close previous connection match `Uri` if not closed yet
|
||||||
pub fn update(&self, uri: &Uri, certificate: Option<&TlsCertificate>) -> Result<(), Error> {
|
pub fn update(&self, uri: &Uri, certificate: Option<&TlsCertificate>) -> Result<(), Error> {
|
||||||
if let Some(connection) = self.get(&uri.to_string()) {
|
// Get available client connections match `uri` scope
|
||||||
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-60
|
||||||
|
for (request, connection) in self.index.borrow().iter() {
|
||||||
|
if request.starts_with(
|
||||||
|
uri.to_string_partial(UriHideFlags::QUERY | UriHideFlags::FRAGMENT)
|
||||||
|
.as_str(),
|
||||||
|
) {
|
||||||
match connection.tls_client_connection {
|
match connection.tls_client_connection {
|
||||||
// User certificate session
|
// User certificate session
|
||||||
Some(ref tls_client_connection) => {
|
Some(ref tls_client_connection) => {
|
||||||
|
|
@ -67,15 +69,6 @@ impl Session {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel previous session operations
|
|
||||||
if let Err(e) = connection.cancel() {
|
|
||||||
return Err(Error::Connection(e));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close previous session connection
|
|
||||||
if let Err(e) = connection.close() {
|
|
||||||
return Err(Error::Connection(e));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue