@ -7,6 +7,7 @@ mod gemini;
use gemini ::GeminiResponse ;
use error ::{ TaurusError , TaurusResult } ;
use native_tls ::{ Identity , TlsAcceptor , TlsStream } ;
use std ::fs ::File ;
use std ::io ::{ self , Read } ;
@ -24,7 +25,7 @@ fn main() {
}
}
fn run ( ) -> Result < ( ) , error ::TaurusError > {
fn run ( ) -> Taurus Result< ( ) > {
// CLI
let matches = App ::new ( crate_name ! ( ) )
. version ( crate_version ! ( ) )
@ -43,7 +44,7 @@ fn run() -> Result<(), error::TaurusError> {
let config_path = matches . value_of ( "config" ) . unwrap ( ) ;
let config : config ::Config =
config ::Config ::load ( config_path ) . map_err ( error ::TaurusError ::InvalidConfig ) ? ;
config ::Config ::load ( config_path ) . map_err ( TaurusError ::InvalidConfig ) ? ;
// Defaults for configuration file
let port = config . port . unwrap_or ( 1965 ) ;
@ -55,12 +56,12 @@ fn run() -> Result<(), error::TaurusError> {
. unwrap_or_else ( | | "/var/www/gemini" . to_owned ( ) ) ;
// Read certificate
let identity = read_file ( & cert_file ) . map_err ( error ::TaurusError ::NoIdentity ) ? ;
let identity = read_file ( & cert_file ) . map_err ( TaurusError ::NoIdentity ) ? ;
let identity = Identity ::from_pkcs12 ( & identity , & config . certificate_password ) ? ;
let address = format! ( "0.0.0.0:{}" , port ) ;
let listener = TcpListener ::bind ( address ) . map_err ( error ::TaurusError ::BindFailed ) ? ;
let listener = TcpListener ::bind ( address ) . map_err ( TaurusError ::BindFailed ) ? ;
let acceptor = TlsAcceptor ::new ( identity ) . unwrap ( ) ;
let acceptor = Arc ::new ( acceptor ) ;
@ -101,7 +102,7 @@ fn read_file(file_path: &str) -> Result<Vec<u8>, io::Error> {
}
/// Send file as a response
fn write_file ( path : & str ) -> Result < GeminiResponse , error ::TaurusError > {
fn write_file ( path : & str ) -> Taurus Result< GeminiResponse > {
let extension = path ::Path ::new ( path )
. extension ( )
. unwrap_or_else ( | | std ::ffi ::OsStr ::new ( "" ) ) ;
@ -125,15 +126,12 @@ fn write_file(path: &str) -> Result<GeminiResponse, error::TaurusError> {
}
}
fn handle_client (
mut stream : TlsStream < TcpStream > ,
static_root : & str ,
) -> Result < usize , error ::TaurusError > {
fn handle_client ( mut stream : TlsStream < TcpStream > , static_root : & str ) -> TaurusResult < usize > {
let mut buffer = [ 0 ; 1024 ] ;
stream
. read ( & mut buffer )
. map_err ( error ::TaurusError ::StreamReadFailed ) ? ;
. map_err ( TaurusError ::StreamReadFailed ) ? ;
let mut raw_request = String ::from_utf8_lossy ( & buffer [ .. ] ) . to_mut ( ) . to_owned ( ) ;