Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
SSH_Connection_Builder.h
Go to the documentation of this file.
1#ifndef joedb_SSH_Connection_Builder
2#define joedb_SSH_Connection_Builder
3
7
8#include <iostream>
9
10namespace joedb
11{
12 /// @ingroup ui
14 {
15 private:
16 std::unique_ptr<ssh::Connector> connector;
17 std::unique_ptr<Connection> connection;
18
19 public:
20 bool has_sharing_option() const override {return true;}
21 const char *get_name() const override {return "ssh";}
22 const char *get_parameters_description() const override
23 {
24 return "<user> <host> <endpoint_path> [<ssh_port> [<ssh_log_level>]]";
25 }
26
27 Connection *build(Arguments &arguments, Buffered_File *file) override
28 {
29 const std::string_view user = arguments.get_next();
30 const std::string_view host = arguments.get_next();
31 const std::string_view remote_path = arguments.get_next();
32
33 if (arguments.missing())
34 return nullptr;
35
36 const std::string_view port_string = arguments.get_next();
37 const std::string_view log_level_string = arguments.get_next();
38
39 unsigned ssh_port = 22;
40 if (port_string.data())
41 ssh_port = std::atoi(port_string.data());
42
43 int ssh_log_level = 0;
44 if (log_level_string.data())
45 ssh_log_level = std::atoi(log_level_string.data());
46
47 connector = std::make_unique<ssh::Connector>
48 (
49 user.data(),
50 host.data(),
51 ssh_port,
52 ssh_log_level,
53 nullptr,
54 nullptr,
55 remote_path.data()
56 );
57
58 if (file)
59 connection = std::make_unique<Robust_Connection>(*connector, &std::cerr);
60 else
61 connection = std::make_unique<Server_File>(*connector, &std::cerr);
62
63 return connection.get();
64 }
65 };
66}
67
68#endif
Class for conveniently parsing command-line arguments.
Definition Arguments.h:19
bool missing() const
Definition Arguments.h:124
std::string_view get_next()
const char * get_name() const override
const char * get_parameters_description() const override
Connection * build(Arguments &arguments, Buffered_File *file) override
bool has_sharing_option() const override
Definition Blob.h:7