blob: 6bf41694756d706a579c3929d3cd0b2b86ee3cc0 [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áte2e15ee2020-02-05 17:38:13 +01004#include <libnetconf2/log.h>
Václav Kubernátc31bd602019-03-07 11:44:48 +01005#include <libnetconf2/messages_client.h>
6#include <memory>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <vector>
11
12struct nc_session;
13
14namespace libyang {
15class Data_Node;
Václav Kubernát1d50a5b2020-02-03 16:44:22 +010016class Context;
Václav Kubernátc31bd602019-03-07 11:44:48 +010017}
18
19namespace libnetconf {
20namespace client {
21
22class ReportedError : public std::runtime_error {
23public:
24 ReportedError(const std::string& what);
25 ~ReportedError() override;
26};
27
Jan Kundráte0154282020-01-22 19:43:30 +010028using KbdInteractiveCb = std::function<std::string(const std::string&, const std::string&, const std::string&, bool)>;
Václav Kubernáte2e15ee2020-02-05 17:38:13 +010029using LogCb = std::function<void(NC_VERB_LEVEL, const char*)>;
30
31void setLogLevel(NC_VERB_LEVEL level);
32void setLogCallback(const LogCb& callback);
Jan Kundráte0154282020-01-22 19:43:30 +010033
Václav Kubernátc31bd602019-03-07 11:44:48 +010034class Session {
35public:
36 Session(struct nc_session* session);
37 ~Session();
Václav Kubernátc31bd602019-03-07 11:44:48 +010038 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 +010039 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 +010040 static std::unique_ptr<Session> connectSocket(const std::string& path);
Václav Kubernát7a9463f2020-10-30 08:57:59 +010041 static std::unique_ptr<Session> connectFd(const int source, const int sink);
Václav Kubernát59e4ee42020-07-08 17:32:45 +020042 [[nodiscard]] std::vector<std::string_view> capabilities() const;
Václav Kubernátc31bd602019-03-07 11:44:48 +010043 std::shared_ptr<libyang::Data_Node> getConfig(const NC_DATASTORE datastore,
44 const std::optional<const std::string> filter = std::nullopt); // TODO: arguments...
Jan Kundrát9138b162020-01-30 09:27:51 +010045 std::shared_ptr<libyang::Data_Node> get(const std::optional<std::string>& filter = std::nullopt);
Václav Kubernátc31bd602019-03-07 11:44:48 +010046 std::string getSchema(const std::string_view identifier, const std::optional<std::string_view> version);
47 void editConfig(const NC_DATASTORE datastore,
48 const NC_RPC_EDIT_DFLTOP defaultOperation,
49 const NC_RPC_EDIT_TESTOPT testOption,
50 const NC_RPC_EDIT_ERROPT errorOption,
51 const std::string& data);
52 void copyConfigFromString(const NC_DATASTORE target, const std::string& data);
Václav Kubernáta8789602020-07-20 15:18:19 +020053 std::shared_ptr<libyang::Data_Node> rpc_or_action(const std::string& xmlData);
Václav Kubernát7160a132020-04-03 02:11:01 +020054 void copyConfig(const NC_DATASTORE source, const NC_DATASTORE destination);
Václav Kubernátc31bd602019-03-07 11:44:48 +010055 void commit();
56 void discard();
Václav Kubernát1d50a5b2020-02-03 16:44:22 +010057
58 std::shared_ptr<libyang::Context> libyangContext();
Václav Kubernátc31bd602019-03-07 11:44:48 +010059 struct nc_session* session_internal(); // FIXME: remove me
60protected:
61 struct nc_session* m_session;
62};
63}
64}