blob: acce38a4a0e0ab8c43edcf0a2d4d9242d14cb71f [file] [log] [blame]
Václav Kubernátc31bd602019-03-07 11:44:48 +01001#pragma once
2
Jan Kundráte0154282020-01-22 19:43:30 +01003#include <functional>
Václav Kubernátc31bd602019-03-07 11:44:48 +01004#include <libnetconf2/messages_client.h>
5#include <memory>
6#include <optional>
7#include <string>
8#include <string_view>
9#include <vector>
10
11struct nc_session;
12
13namespace libyang {
14class Data_Node;
Václav Kubernát1d50a5b2020-02-03 16:44:22 +010015class Context;
Václav Kubernátc31bd602019-03-07 11:44:48 +010016}
17
18namespace libnetconf {
19namespace client {
20
21class ReportedError : public std::runtime_error {
22public:
23 ReportedError(const std::string& what);
24 ~ReportedError() override;
25};
26
Jan Kundráte0154282020-01-22 19:43:30 +010027using KbdInteractiveCb = std::function<std::string(const std::string&, const std::string&, const std::string&, bool)>;
28
Václav Kubernátc31bd602019-03-07 11:44:48 +010029class Session {
30public:
31 Session(struct nc_session* session);
32 ~Session();
Václav Kubernátc31bd602019-03-07 11:44:48 +010033 static std::unique_ptr<Session> connectPubkey(const std::string& host, const uint16_t port, const std::string& user, const std::string& pubPath, const std::string& privPath);
Jan Kundráte0154282020-01-22 19:43:30 +010034 static std::unique_ptr<Session> connectKbdInteractive(const std::string& host, const uint16_t port, const std::string& user, const KbdInteractiveCb& callback);
Václav Kubernátc31bd602019-03-07 11:44:48 +010035 static std::unique_ptr<Session> connectSocket(const std::string& path);
Václav Kubernát7a9463f2020-10-30 08:57:59 +010036 static std::unique_ptr<Session> connectFd(const int source, const int sink);
Václav Kubernát59e4ee42020-07-08 17:32:45 +020037 [[nodiscard]] std::vector<std::string_view> capabilities() const;
Václav Kubernátc31bd602019-03-07 11:44:48 +010038 std::shared_ptr<libyang::Data_Node> getConfig(const NC_DATASTORE datastore,
39 const std::optional<const std::string> filter = std::nullopt); // TODO: arguments...
Jan Kundrát9138b162020-01-30 09:27:51 +010040 std::shared_ptr<libyang::Data_Node> get(const std::optional<std::string>& filter = std::nullopt);
Václav Kubernátc31bd602019-03-07 11:44:48 +010041 std::string getSchema(const std::string_view identifier, const std::optional<std::string_view> version);
42 void editConfig(const NC_DATASTORE datastore,
43 const NC_RPC_EDIT_DFLTOP defaultOperation,
44 const NC_RPC_EDIT_TESTOPT testOption,
45 const NC_RPC_EDIT_ERROPT errorOption,
46 const std::string& data);
47 void copyConfigFromString(const NC_DATASTORE target, const std::string& data);
Václav Kubernáta8789602020-07-20 15:18:19 +020048 std::shared_ptr<libyang::Data_Node> rpc_or_action(const std::string& xmlData);
Václav Kubernát7160a132020-04-03 02:11:01 +020049 void copyConfig(const NC_DATASTORE source, const NC_DATASTORE destination);
Václav Kubernátc31bd602019-03-07 11:44:48 +010050 void commit();
51 void discard();
Václav Kubernát1d50a5b2020-02-03 16:44:22 +010052
53 std::shared_ptr<libyang::Context> libyangContext();
Václav Kubernátc31bd602019-03-07 11:44:48 +010054 struct nc_session* session_internal(); // FIXME: remove me
55protected:
56 struct nc_session* m_session;
57};
58}
59}