Added gopher protocol
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
/.idea
|
||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
**/*.swp
|
**/*.swp
|
||||||
83
.idea/workspace.xml
generated
83
.idea/workspace.xml
generated
@@ -1,17 +1,47 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="BranchesTreeState">
|
||||||
|
<expand>
|
||||||
|
<path>
|
||||||
|
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
||||||
|
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
||||||
|
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
||||||
|
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
||||||
|
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
|
||||||
|
</path>
|
||||||
|
</expand>
|
||||||
|
<select />
|
||||||
|
</component>
|
||||||
<component name="CargoProjects">
|
<component name="CargoProjects">
|
||||||
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
|
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="bd356b53-8877-4762-bc50-8d6780ab07cb" name="Default Changelist" comment="">
|
<list default="true" id="bd356b53-8877-4762-bc50-8d6780ab07cb" name="Default Changelist" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/src/configuration.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/configuration.rs" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/gopher.rs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/configuration.rs" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/traits/Document.rs" beforeDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="FileTemplateManagerImpl">
|
||||||
|
<option name="RECENT_TEMPLATES">
|
||||||
|
<list>
|
||||||
|
<option value="Rust File" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
@@ -26,8 +56,10 @@
|
|||||||
<component name="PropertiesComponent">
|
<component name="PropertiesComponent">
|
||||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||||
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
<property name="org.rust.cargo.project.model.PROJECT_DISCOVERY" value="true" />
|
<property name="org.rust.cargo.project.model.PROJECT_DISCOVERY" value="true" />
|
||||||
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
|
<property name="org.rust.hideDetachedFileNotifications/home/jali/Projects/gopherbridge/src/gopherrequest.rs" value="true" />
|
||||||
|
<property name="settings.editor.selected.configurable" value="editing.templates" />
|
||||||
</component>
|
</component>
|
||||||
<component name="RunAnythingCache">
|
<component name="RunAnythingCache">
|
||||||
<option name="myCommands">
|
<option name="myCommands">
|
||||||
@@ -84,7 +116,22 @@
|
|||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="WindowStateProjectService">
|
<component name="WindowStateProjectService">
|
||||||
|
<state x="1759" y="376" width="734" height="634" key="#Inspections" timestamp="1592162631281">
|
||||||
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
|
</state>
|
||||||
|
<state x="1759" y="376" width="734" height="634" key="#Inspections/0.0.3440.1408@0.0.3440.1408" timestamp="1592162631281" />
|
||||||
<state x="1080" y="454" width="1185" height="659" key="#Rust" timestamp="1591078343847">
|
<state x="1080" y="454" width="1185" height="659" key="#Rust" timestamp="1591078343847">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
@@ -97,6 +144,10 @@
|
|||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
<state x="1080" y="454" width="1185" height="593" key="#build/0.0.3440.1408@0.0.3440.1408" timestamp="1591078371778" />
|
<state x="1080" y="454" width="1185" height="593" key="#build/0.0.3440.1408@0.0.3440.1408" timestamp="1591078371778" />
|
||||||
|
<state x="1646" y="829" width="553" height="332" key="#com.intellij.codeInsight.template.impl.EditVariableDialog" timestamp="1592171085624">
|
||||||
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
|
</state>
|
||||||
|
<state x="1646" y="829" width="553" height="332" key="#com.intellij.codeInsight.template.impl.EditVariableDialog/0.0.3440.1408@0.0.3440.1408" timestamp="1592171085624" />
|
||||||
<state x="1134" y="410" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1591481974249">
|
<state x="1134" y="410" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1591481974249">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
@@ -105,30 +156,34 @@
|
|||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
<state x="1520" y="542" width="297" height="479" key="EnvironmentVariablesDialog/0.0.3440.1408@0.0.3440.1408" timestamp="1591078336448" />
|
<state x="1520" y="542" width="297" height="479" key="EnvironmentVariablesDialog/0.0.3440.1408@0.0.3440.1408" timestamp="1591078336448" />
|
||||||
<state x="1517" y="461" width="426" height="481" key="FileChooserDialogImpl" timestamp="1591483226351">
|
<state x="1517" y="461" width="426" height="481" key="FileChooserDialogImpl" timestamp="1592143269262">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
<state x="1517" y="461" width="426" height="481" key="FileChooserDialogImpl/0.0.3440.1408@0.0.3440.1408" timestamp="1591483226351" />
|
<state x="1517" y="461" width="426" height="481" key="FileChooserDialogImpl/0.0.3440.1408@0.0.3440.1408" timestamp="1592143269262" />
|
||||||
<state width="2179" height="287" key="GridCell.Tab.0.bottom" timestamp="1591482320545">
|
<state width="1897" height="253" key="GridCell.Tab.0.bottom" timestamp="1592163709599">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
<state width="2179" height="287" key="GridCell.Tab.0.bottom/0.0.3440.1408@0.0.3440.1408" timestamp="1591482320545" />
|
<state width="1897" height="253" key="GridCell.Tab.0.bottom/0.0.3440.1408@0.0.3440.1408" timestamp="1592163709599" />
|
||||||
<state width="2179" height="287" key="GridCell.Tab.0.center" timestamp="1591482320545">
|
<state width="1897" height="253" key="GridCell.Tab.0.center" timestamp="1592163709599">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
<state width="2179" height="287" key="GridCell.Tab.0.center/0.0.3440.1408@0.0.3440.1408" timestamp="1591482320545" />
|
<state width="1897" height="253" key="GridCell.Tab.0.center/0.0.3440.1408@0.0.3440.1408" timestamp="1592163709599" />
|
||||||
<state width="2179" height="287" key="GridCell.Tab.0.left" timestamp="1591482320545">
|
<state width="1897" height="253" key="GridCell.Tab.0.left" timestamp="1592163709599">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
<state width="2179" height="287" key="GridCell.Tab.0.left/0.0.3440.1408@0.0.3440.1408" timestamp="1591482320545" />
|
<state width="1897" height="253" key="GridCell.Tab.0.left/0.0.3440.1408@0.0.3440.1408" timestamp="1592163709599" />
|
||||||
<state width="2179" height="287" key="GridCell.Tab.0.right" timestamp="1591482320545">
|
<state width="1897" height="253" key="GridCell.Tab.0.right" timestamp="1592163709599">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
<state width="2179" height="287" key="GridCell.Tab.0.right/0.0.3440.1408@0.0.3440.1408" timestamp="1591482320545" />
|
<state width="1897" height="253" key="GridCell.Tab.0.right/0.0.3440.1408@0.0.3440.1408" timestamp="1592163709599" />
|
||||||
<state x="1165" y="387" key="SettingsEditor" timestamp="1591732532558">
|
<state x="1431" y="632" key="SettingsEditor" timestamp="1592171165276">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
<state x="1165" y="387" key="SettingsEditor/0.0.3440.1408@0.0.3440.1408" timestamp="1591732532558" />
|
<state x="1431" y="632" key="SettingsEditor/0.0.3440.1408@0.0.3440.1408" timestamp="1592171165276" />
|
||||||
|
<state width="498" height="445" key="SwitcherDM" timestamp="1592151399794">
|
||||||
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
|
</state>
|
||||||
|
<state width="498" height="445" key="SwitcherDM/0.0.3440.1408@0.0.3440.1408" timestamp="1592151399794" />
|
||||||
<state x="998" y="354" width="1349" height="793" key="new project wizard" timestamp="1591482015251">
|
<state x="998" y="354" width="1349" height="793" key="new project wizard" timestamp="1591482015251">
|
||||||
<screen x="0" y="0" width="3440" height="1408" />
|
<screen x="0" y="0" width="3440" height="1408" />
|
||||||
</state>
|
</state>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//! File: settings.rs
|
//! File: configuration.rs
|
||||||
//! Description: Defines a stuct that holds all of the configuration settings passed to the program
|
//! Description: Defines a stuct that holds all of the configuration settings passed to the program
|
||||||
//! by line.
|
//! by line.
|
||||||
//! Created On: Tue 04 Jun 2019 10:30:46 pm CEST
|
//! Created On: Tue 04 Jun 2019 10:30:46 pm CEST
|
||||||
@@ -12,6 +12,7 @@ use std::str::FromStr;
|
|||||||
* Stores the configuration needed for the server.
|
* Stores the configuration needed for the server.
|
||||||
*/
|
*/
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
pub documentpath: String,
|
||||||
pub foreground: bool,
|
pub foreground: bool,
|
||||||
pub listen: String,
|
pub listen: String,
|
||||||
pub plugins: Vec<String>,
|
pub plugins: Vec<String>,
|
||||||
@@ -29,7 +30,7 @@ impl Settings {
|
|||||||
*
|
*
|
||||||
* A new ```Settings``` object
|
* A new ```Settings``` object
|
||||||
*
|
*
|
||||||
* # Exanples
|
* # Examples
|
||||||
*
|
*
|
||||||
* ```rust
|
* ```rust
|
||||||
* let settings = Settings::create();
|
* let settings = Settings::create();
|
||||||
@@ -39,6 +40,7 @@ impl Settings {
|
|||||||
let matches = Settings::parse_command_line();
|
let matches = Settings::parse_command_line();
|
||||||
|
|
||||||
Settings {
|
Settings {
|
||||||
|
documentpath: matches.value_of("DOCUMENTPATH").unwrap_or("./data").to_owned(),
|
||||||
foreground: matches.is_present("FOREGROUND"),
|
foreground: matches.is_present("FOREGROUND"),
|
||||||
listen: matches.value_of("LISTEN").unwrap_or("127.0.0.1").to_owned(),
|
listen: matches.value_of("LISTEN").unwrap_or("127.0.0.1").to_owned(),
|
||||||
plugins: matches.value_of("PLUGIN").unwrap_or("filesystem").split(",").map(|s| s.to_string()).collect(),
|
plugins: matches.value_of("PLUGIN").unwrap_or("filesystem").split(",").map(|s| s.to_string()).collect(),
|
||||||
@@ -62,6 +64,7 @@ impl Settings {
|
|||||||
(version: "0.1")
|
(version: "0.1")
|
||||||
(author: "jali@orca-central.de")
|
(author: "jali@orca-central.de")
|
||||||
(about: "A simple modular gopher server, that pushes converted web-content to a client")
|
(about: "A simple modular gopher server, that pushes converted web-content to a client")
|
||||||
|
(@arg DOCUMENTPATH: -d --documentpath "Sets the base path to where the gopher documents are a stored.")
|
||||||
(@arg FOREGROUND: -f --foreground "Keeps the service in the foreground")
|
(@arg FOREGROUND: -f --foreground "Keeps the service in the foreground")
|
||||||
(@arg LISTEN: -l --listen +takes_value "Specifies the interface to listn on. Is either a hostname or an address-pattern.")
|
(@arg LISTEN: -l --listen +takes_value "Specifies the interface to listn on. Is either a hostname or an address-pattern.")
|
||||||
(@arg PLUGIN: -u --plugins +takes_value +required "A comma separated list of plugins to load.")
|
(@arg PLUGIN: -u --plugins +takes_value +required "A comma separated list of plugins to load.")
|
||||||
29
src/gopher.rs
Normal file
29
src/gopher.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
//! File: gopher.rs
|
||||||
|
//! Description: Defines a set of functions to wait for selectors in a stream
|
||||||
|
//! and calls a function that returns the request.
|
||||||
|
//! Version: 1.0.20166.1
|
||||||
|
//! Created By: Jali <jali@orca-central.de>
|
||||||
|
|
||||||
|
use tokio::net::TcpStream;
|
||||||
|
use tokio::io;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* # Description
|
||||||
|
*
|
||||||
|
* Reads from the reader until it gets a selector (basically a line of text).
|
||||||
|
* It will then look up the selected resource in the documents, and return the
|
||||||
|
* document.
|
||||||
|
*
|
||||||
|
* # Returns
|
||||||
|
*
|
||||||
|
* The number of bytes transferred in the session.
|
||||||
|
*
|
||||||
|
* # Examples
|
||||||
|
|
||||||
|
* ```rust
|
||||||
|
* let amount = gopher::request(reader, writer);
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
pub fn request(reader: io::ReadHalf<TcpStream>, writer: io::WriteHalf<TcpStream>) -> int32 {
|
||||||
|
|
||||||
|
}
|
||||||
10
src/main.rs
10
src/main.rs
@@ -3,8 +3,11 @@ extern crate clap;
|
|||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
|
|
||||||
mod configuration;
|
mod configuration;
|
||||||
|
mod gopher;
|
||||||
|
|
||||||
use crate::configuration::Settings;
|
use crate::configuration::Settings;
|
||||||
|
use std::fs::create_dir_all;
|
||||||
|
use std::path::Path;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use tokio::io;
|
use tokio::io;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
@@ -20,6 +23,11 @@ fn main() {
|
|||||||
println!("Server listens on {}", settings.listen);
|
println!("Server listens on {}", settings.listen);
|
||||||
println!("Loading plugins {:?}", settings.plugins);
|
println!("Loading plugins {:?}", settings.plugins);
|
||||||
println!("Listening on port {}", settings.port);
|
println!("Listening on port {}", settings.port);
|
||||||
|
println!("Documents directory {}", settings.documentpath);
|
||||||
|
|
||||||
|
if !Path::new(&settings.documentpath).exists() {
|
||||||
|
create_dir_all(&settings.documentpath).expect("Could not create document folder");
|
||||||
|
}
|
||||||
|
|
||||||
let addr: SocketAddr = format!("{}:{}", settings.listen, settings.port)
|
let addr: SocketAddr = format!("{}:{}", settings.listen, settings.port)
|
||||||
.parse()
|
.parse()
|
||||||
@@ -29,7 +37,7 @@ fn main() {
|
|||||||
let server = listener
|
let server = listener
|
||||||
.incoming()
|
.incoming()
|
||||||
.for_each(|socket| {
|
.for_each(|socket| {
|
||||||
let (reader, writer) = socket.split();
|
let (mut reader, mut writer) = socket.split();
|
||||||
let amount = io::copy(reader, writer);
|
let amount = io::copy(reader, writer);
|
||||||
|
|
||||||
let msg = amount.then(|result| {
|
let msg = amount.then(|result| {
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
// File: traits/Document.rs
|
|
||||||
// Description: Defines a trait for a gopher document.
|
|
||||||
// Created On: Tue 08 Oct 2019 09:37:41 pm CEST
|
|
||||||
// Least Modified: Tue 08 Oct 2019 09:37:41 pm CEST
|
|
||||||
// Author: Jali <jali@orca-central.de>
|
|
||||||
|
|
||||||
/// Defines a gopher document.
|
|
||||||
/// A valid document is any document, that can be a selector in gopher.
|
|
||||||
pub trait Document {}
|
|
||||||
Reference in New Issue
Block a user