libsshpp v0.1.7
Modern C++17 wrapper for libssh
Loading...
Searching...
No Matches
server_session.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2#pragma once
3
4#include <sshpp/config.hpp>
5
9#include <sshpp/event.hpp>
10#include <sshpp/export.hpp>
11#include <sshpp/result.hpp>
13
14#include <chrono>
15#include <memory>
16#include <optional>
17#include <string>
18#include <string_view>
19
20namespace sshpp::server {
21
22struct SSHPP_API AuthMethodSet {
23 bool none = false, password = false, public_key = false,
24 host_based = false, interactive = false, gssapi_mic = false;
25 int to_bits() const noexcept;
26};
27
28class Bind;
29class SessionHandler;
30
32class SSHPP_API Session {
33public:
34 Session() = default;
36 Session(Session&&) noexcept;
37 Session& operator=(Session&&) noexcept;
38 Session(const Session&) = delete;
39
40 explicit operator bool() const noexcept { return core_ && core_->valid(); }
41 native_session native_handle() const noexcept { return core_ ? core_->raw() : nullptr; }
42
44 Result<void> try_handle_key_exchange();
45
46 void set_auth_methods(AuthMethodSet);
47 Result<void> try_disconnect(std::string_view reason = {});
48
49 Result<std::string> try_client_banner() const;
50
51 bool authenticated() const noexcept { return authenticated_; }
52 const std::string& user() const noexcept { return user_; }
53
55 Result<std::optional<Message>> try_next_message(std::chrono::milliseconds timeout =
56 std::chrono::milliseconds(-1));
57
58 // ---- callback style (see docs/design/08 §8.6) --------------------------------
62 Result<void> try_set_handler(std::shared_ptr<SessionHandler>);
63 Result<void> try_attach(Event& event);
65 Result<void> try_poll(std::chrono::milliseconds timeout);
66
67private:
68 friend class Bind;
69 friend class Message;
71 explicit Session(detail::SessionCorePtr core) : core_(std::move(core)) {}
72 void notify_disconnect();
73
75 bool authenticated_ = false;
76 std::string user_;
77 bool used_message_style_ = false;
78 std::shared_ptr<detail::HandlerBridge> bridge_;
79 std::unique_ptr<Event> private_event_;
80};
81
82} // namespace sshpp::server
83
84#if SSHPP_HEADER_ONLY
86#endif
Poll-loop integration seam around ssh_event. See docs/design/05 §5.5.
Definition event.hpp:16
Definition result.hpp:16
Definition handler_bridge.ipp:23
The listening server socket. See docs/design/08 §8.3.
Definition bind.hpp:37
Definition message.hpp:33
Definition handlers.hpp:42
One accepted server-side connection. See docs/design/08 §8.4.
Definition server_session.hpp:32
bool authenticated() const noexcept
Definition server_session.hpp:51
native_session native_handle() const noexcept
Definition server_session.hpp:41
Session(Session &&) noexcept
const std::string & user() const noexcept
Definition server_session.hpp:52
std::shared_ptr< SessionCore > SessionCorePtr
Definition session_core.hpp:43
Definition server_bind.ipp:15
::ssh_session_struct * native_session
Definition native_fwd.hpp:25
Definition error.hpp:110
Definition server_session.hpp:22