Joedb 9.1.4
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::Session> session;
17 std::unique_ptr<ssh::Forward_Channel> channel;
18 std::unique_ptr<Server_Connection> connection;
19
20 public:
21 bool has_sharing_option() const final {return true;}
22 int get_min_parameters() const final {return 3;}
23 int get_max_parameters() const final {return 5;}
24 const char *get_name() const final {return "ssh";}
25 const char *get_parameters_description() const final
26 {
27 return "<user> <host> <joedb_port> [<ssh_port> [<ssh_log_level>]]";
28 }
29
30 Connection &build(int argc, char **argv, Buffered_File *file) final
31 {
32 const char * const user = argv[0];
33 const char * const host = argv[1];
34 const uint16_t joedb_port = uint16_t(std::atoi(argv[2]));
35 const unsigned ssh_port = argc > 3 ? std::atoi(argv[3]) : 22;
36 const int ssh_log_level = argc > 4 ? std::atoi(argv[4]) : 0;
37
38 session = std::make_unique<ssh::Session>(user, host, ssh_port, ssh_log_level);
39 channel = std::make_unique<ssh::Forward_Channel>(*session, "localhost", joedb_port);
40
41 if (file)
42 connection = std::make_unique<Server_Connection>(*channel);
43 else
44 connection = std::make_unique<Server_File>(*channel);
45 connection->set_log(&std::cerr);
46
47 return *connection;
48 }
49 };
50}
51
52#endif
Connection & build(int argc, char **argv, Buffered_File *file) final
const char * get_name() const final
const char * get_parameters_description() const final
Definition Blob.h:7