Applied copyright headers

This commit is contained in:
2023-05-13 00:42:57 +02:00
parent 23cd7bca8d
commit 1e21a8e226
22 changed files with 1540 additions and 37 deletions

View File

@@ -22,4 +22,5 @@ futures = "0.3.28"
tokio-stream = { version = "0.1.14", features = ["sync"] }
rand = "0.8.5"
base64 = "0.21.0"
lazy_static = "1.4.0"
lazy_static = "1.4.0"
rust-embed = { version = "6.6.1", features = ["interpolate-folder-path"] }

View File

@@ -1,3 +1,21 @@
/*************************************************************************
* D3270 - Detachable 3270 interface *
* Copyright (C) 2023 Daniel Hirsch *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*************************************************************************/
use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::pin::Pin;

View File

@@ -1,3 +1,21 @@
/*************************************************************************
* D3270 - Detachable 3270 interface *
* Copyright (C) 2023 Daniel Hirsch *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*************************************************************************/
use crate::arbiter::{ArbiterHandle, ArbiterHandleRequester};
use d3270_common::b3270::indication::RunResult;
use d3270_common::b3270::operation::Run;

View File

@@ -1,3 +1,21 @@
/*************************************************************************
* D3270 - Detachable 3270 interface *
* Copyright (C) 2023 Daniel Hirsch *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*************************************************************************/
use std::ffi::OsString;
use std::future::Future;
use std::pin::Pin;
@@ -54,7 +72,7 @@ async fn main() -> anyhow::Result<()> {
.with(tracing_subscriber::filter::EnvFilter::from_default_env())
.with(
tracing_subscriber::fmt::layer()
.with_span_events(FmtSpan::ACTIVE)
.with_span_events(FmtSpan::NONE)
).init();
info!("Test");

View File

@@ -1,3 +1,21 @@
/*************************************************************************
* D3270 - Detachable 3270 interface *
* Copyright (C) 2023 Daniel Hirsch *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*************************************************************************/
use std::net::SocketAddr;
use anyhow::bail;
@@ -24,6 +42,7 @@ pub async fn listener_proc(
Ok(listener) => listener
};
let span = info_span!(target: "connection-handling", "tcp_listener", addr=%socket);
info!("TCP listener starting");
Ok(tokio::spawn(
async move {
let error = listener_task(listener, handle_requester).await.unwrap_err();
@@ -61,6 +80,7 @@ async fn handle_tcp_connection(
mut conn: TcpStream,
handle_requester: ArbiterHandleRequester,
) -> anyhow::Result<()> {
info!("Handling TCP connection");
let (stream_rd, mut stream_wr) = conn.split();
let mut stream_rd = BufReader::new(stream_rd).lines();

View File

@@ -1,7 +1,25 @@
/*************************************************************************
* D3270 - Detachable 3270 interface *
* Copyright (C) 2023 Daniel Hirsch *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*************************************************************************/
use std::net::SocketAddr;
use anyhow::anyhow;
use tide::prelude::*;
use tide::Request;
use tide::{Request, Response};
use tide_websockets::{WebSocketConnection, self as ws};
use tokio::select;
use tokio::task::JoinHandle;
@@ -10,15 +28,56 @@ use crate::gen_connection::GenConnection;
use futures::stream::StreamExt;
use tracing::{info, warn};
use d3270_common::b3270::Indication;
use rust_embed::{EmbeddedFile, RustEmbed};
use tide::http::{mime, StatusCode};
#[derive(RustEmbed)]
#[folder = "$CARGO_MANIFEST_DIR/../js3270/dist/"]
struct Asset;
async fn static_file(req: Request<ArbiterHandleRequester>) -> tide::Result {
let mut path = req.param("path").unwrap_or("index.html");
if path == "" {
path = "index.html"
}
let content_type = if let Some((_, ext)) = path.rsplit_once(".") {
match ext {
"svg" => mime::SVG,
"jpg" | "jpeg" => mime::JPEG,
"png" => mime::PNG,
"css" => mime::CSS,
"js" => mime::JAVASCRIPT,
"html" | "htm" => mime::HTML,
_ => mime::BYTE_STREAM,
}
} else {
mime::BYTE_STREAM
};
if let Some(file) = Asset::get(path) as Option<EmbeddedFile> {
Ok(Response::builder(StatusCode::Ok)
.content_type(content_type)
.body(file.data.as_ref())
.build())
} else {
Ok(Response::builder(StatusCode::NotFound)
.content_type(mime::PLAIN)
.body("Dude, where's your file?")
.build())
}
}
pub async fn start_ws_server(socket: SocketAddr, handle_requester: ArbiterHandleRequester, ) -> anyhow::Result<JoinHandle<anyhow::Error>> {
let mut app = tide::Server::with_state(handle_requester);
app.with(tide_tracing::TraceMiddleware::new());
app.at("/api/ws").get(tide_websockets::WebSocket::new(handle_websocket));
app.at("/*path").get(static_file);
app.at("/").get(static_file);
let mut listener = app.bind(socket.clone()).await?;
Ok(tokio::task::spawn(async move {
info!(%socket, "Starting HTTP server");
info!(address=%socket, "Starting HTTP server");
listener.accept().await
.map(|()| anyhow!("HTTP server returned early"))
.unwrap_or_else(Into::into)
@@ -26,6 +85,7 @@ pub async fn start_ws_server(socket: SocketAddr, handle_requester: ArbiterHandle
}
async fn handle_websocket(req: Request<ArbiterHandleRequester>, mut ws: WebSocketConnection) -> tide::Result<()> {
info!("Handling websocket");
let mut arbiter = GenConnection::new(req.state().clone()).await?;
// TODO: do authenticatey things