summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2025-11-05 09:44:04 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2025-11-05 09:44:04 +0100
commitc1d73cbe17650c834faee5a0098a9499b39a2835 (patch)
treeac9c1180f5f8603dd887b7360597db8c53b6e99e /modules
parent5c1d7018ba867a73c160cc044b939e35a2c07243 (diff)
downloadforstio-forstio-c1d73cbe17650c834faee5a0098a9499b39a2835.tar.gz
Dangling changes from the weekend. Added io/ssh setup
Diffstat (limited to 'modules')
-rw-r--r--modules/io-ssh/.nix/derivation.nix41
-rw-r--r--modules/io-ssh/SConstruct80
-rw-r--r--modules/io-ssh/c++/SConscript38
-rw-r--r--modules/io-ssh/c++/ssh.hpp43
-rw-r--r--modules/io-ssh/examples/SConscript33
5 files changed, 235 insertions, 0 deletions
diff --git a/modules/io-ssh/.nix/derivation.nix b/modules/io-ssh/.nix/derivation.nix
new file mode 100644
index 0000000..6131a98
--- /dev/null
+++ b/modules/io-ssh/.nix/derivation.nix
@@ -0,0 +1,41 @@
+{ lib
+, stdenv
+, scons
+, clang-tools
+, version
+, forstio
+, gnutls
+, build_examples ? "false"
+}:
+
+let
+
+in stdenv.mkDerivation {
+ pname = "forstio-io-tls";
+ inherit version;
+ src = ./..;
+
+ enableParallelBuilding = true;
+
+ nativeBuildInputs = [
+ scons
+ clang-tools
+ ];
+
+ buildInputs = [
+ forstio.core
+ forstio.async
+ forstio.io
+ gnutls
+ ];
+
+ buildPhase = ''
+ scons build_examples=${build_examples}
+ '';
+
+ installPhase = ''
+ scons prefix=$out build_examples=${build_examples} install
+ '';
+
+ outputs = ["out" "dev"];
+}
diff --git a/modules/io-ssh/SConstruct b/modules/io-ssh/SConstruct
new file mode 100644
index 0000000..909eadb
--- /dev/null
+++ b/modules/io-ssh/SConstruct
@@ -0,0 +1,80 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+import os.path
+import glob
+import re
+
+
+if sys.version_info < (3,):
+ def isbasestring(s):
+ return isinstance(s,basestring)
+else:
+ def isbasestring(s):
+ return isinstance(s, (str,bytes))
+
+def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
+
+ if isbasestring(filetype):
+ dir_path = self.Dir('.').abspath
+ filetype = sorted(glob.glob(dir_path+"/"+filetype))
+
+ for path in filetype:
+ target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
+ if shared:
+ target_name+='.os'
+ sources.append( self.SharedObject( target=target_name, source=path ) )
+ else:
+ target_name+='.o'
+ sources.append( self.StaticObject( target=target_name, source=path ) )
+ pass
+
+def isAbsolutePath(key, dirname, env):
+ assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
+
+env_vars = Variables(
+ args=ARGUMENTS
+)
+
+env_vars.Add(
+ BoolVariable('build_examples',
+ help='Build examples',
+ default=False
+ )
+);
+
+env_vars.Add('prefix',
+ help='Installation target location of build results and headers',
+ default='/usr/local/',
+ validator=isAbsolutePath
+);
+
+env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
+ CXX=['c++'],
+ CPPDEFINES=['SAW_UNIX'],
+ CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
+ LIBS=[
+ 'gnutls'
+ ,'forstio-core'
+ ,'forstio-async'
+ ,'forstio-io'
+ ])
+env.__class__.add_source_files = add_kel_source_files
+env.Tool('compilation_db');
+env.cdb = env.CompilationDatabase('compile_commands.json');
+
+env.objects = [];
+env.sources = [];
+env.headers = [];
+env.targets = [];
+
+Export('env')
+SConscript('c++/SConscript')
+SConscript('examples/SConscript')
+
+env.Alias('cdb', env.cdb);
+env.Alias('all', [env.targets]);
+env.Default('all');
+
+env.Alias('install', '$prefix')
diff --git a/modules/io-ssh/c++/SConscript b/modules/io-ssh/c++/SConscript
new file mode 100644
index 0000000..4af4ea3
--- /dev/null
+++ b/modules/io-ssh/c++/SConscript
@@ -0,0 +1,38 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+io_ssh_env = env.Clone();
+
+io_ssh_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+io_ssh_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += io_ssh_env.sources;
+env.headers += io_ssh_env.headers;
+
+## Shared lib
+objects_shared = []
+io_ssh_env.add_source_files(objects_shared, io_ssh_env.sources, shared=True);
+env.library_shared = io_ssh_env.SharedLibrary('#build/forstio-io-ssh', [objects_shared]);
+
+## Static lib
+objects_static = []
+io_ssh_env.add_source_files(objects_static, io_ssh_env.sources, shared=False);
+env.library_static = io_ssh_env.StaticLibrary('#build/forstio-io-ssh', [objects_static]);
+
+# Set Alias
+env.Alias('library_io_ssh', [env.library_shared, env.library_static]);
+
+env.targets += ['library_io_ssh'];
+
+# Install
+env.Install('$prefix/lib/', [env.library_shared, env.library_static]);
+env.Install('$prefix/include/forstio/io/ssh/', [io_ssh_env.headers]);
diff --git a/modules/io-ssh/c++/ssh.hpp b/modules/io-ssh/c++/ssh.hpp
new file mode 100644
index 0000000..93c4ac0
--- /dev/null
+++ b/modules/io-ssh/c++/ssh.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <forstio/io/io.hpp>
+
+namespace saw {
+namespace net {
+struct Ssh {};
+}
+
+template<>
+class network_address<net::Ssh> final {
+private:
+ std::string address_;
+public:
+ network_address(const std::string& address__):
+ address_{address__}
+ {}
+};
+
+template<>
+class network<net::Ssh> final {
+private:
+public:
+ conveyor<own<network_address<net::Ssh>>> resolve_address(const std::string& addr){
+ return make_error<err::not_implemented>("SSH resolve address not implemented");
+ }
+
+ error_or<own<network_address<net::Ssh>>> parse_address(const std::string& addr){
+ return heap<network_address<net::Ssh>>(addr);
+ }
+};
+
+error_or<own<network<net::Ssh>>> setup_ssh_network(){
+ own<network<net::Ssh>> ssh_net;
+ try{
+ ssh_net = heap<network<net::Ssh>>();
+ }catch(const std::exception& e){
+ (void)e;
+ return make_error<err::critical>("Couldn't allocate ssh memory");
+ }
+ return ssh_net;
+}
+}
diff --git a/modules/io-ssh/examples/SConscript b/modules/io-ssh/examples/SConscript
new file mode 100644
index 0000000..3afa8a7
--- /dev/null
+++ b/modules/io-ssh/examples/SConscript
@@ -0,0 +1,33 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+examples_env = env.Clone();
+
+examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += examples_env.sources;
+env.headers += examples_env.headers;
+
+objects_static = []
+#examples_env.tls_client = examples_env.Program('#bin/tls_client_https_keldu_de', ['tls_client.cpp', env.library_static]);
+#examples_env.tls_echo_server = examples_env.Program('#bin/tls_echo_server', ['tls_echo_server.cpp', env.library_static]);
+
+# Set Alias
+env.examples = [
+];
+env.Alias('examples', env.examples);
+
+if env["build_examples"]:
+ env.targets += ['examples'];
+ env.Install('$prefix/bin/', env.examples);
+#endif