Fix working with libyang parsed info
Before now, yang_schema expected that parsed info was available,
however, in most cases it was not:
For YangAccess, we directly manage the context, so we'll just use the
flag needed.
For NetconfAccess, we need to create our custom context and supply it.
This context is treated by libnetconf2 as shared and it won't try to
free it. We will hold a reference to this context via a new member
variable inside NetconfAccess so that it stays alive for the whole
netconf client session.
sysrepo does not support this flag as of now. Simply patching sysrepo to
always use this flag doesn't work (it gives internal errors), so it
needs an upstream patch.
Change-Id: Ie7e4567a779a09daa7b3a8b3923e73a3dfd6ba1d
diff --git a/src/netconf-client.cpp b/src/netconf-client.cpp
index 0685db6..7171c01 100644
--- a/src/netconf-client.cpp
+++ b/src/netconf-client.cpp
@@ -212,7 +212,7 @@
::nc_session_free(m_session, nullptr);
}
-std::unique_ptr<Session> Session::connectPubkey(const std::string& host, const uint16_t port, const std::string& user, const std::string& pubPath, const std::string& privPath)
+std::unique_ptr<Session> Session::connectPubkey(const std::string& host, const uint16_t port, const std::string& user, const std::string& pubPath, const std::string& privPath, std::optional<libyang::Context> ctx)
{
impl::ClientInit::instance();
@@ -223,14 +223,14 @@
nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, 5);
nc_client_ssh_add_keypair(pubPath.c_str(), privPath.c_str());
}
- auto session = std::make_unique<Session>(nc_connect_ssh(host.c_str(), port, nullptr));
+ auto session = std::make_unique<Session>(nc_connect_ssh(host.c_str(), port, ctx ? libyang::retrieveContext(*ctx) : nullptr));
if (!session->m_session) {
throw std::runtime_error{"nc_connect_ssh failed"};
}
return session;
}
-std::unique_ptr<Session> Session::connectKbdInteractive(const std::string& host, const uint16_t port, const std::string& user, const KbdInteractiveCb& callback)
+std::unique_ptr<Session> Session::connectKbdInteractive(const std::string& host, const uint16_t port, const std::string& user, const KbdInteractiveCb& callback, std::optional<libyang::Context> ctx)
{
impl::ClientInit::instance();
@@ -244,29 +244,29 @@
nc_client_ssh_set_username(nullptr);
});
- auto session = std::make_unique<Session>(nc_connect_ssh(host.c_str(), port, nullptr));
+ auto session = std::make_unique<Session>(nc_connect_ssh(host.c_str(), port, ctx ? libyang::retrieveContext(*ctx) : nullptr));
if (!session->m_session) {
throw std::runtime_error{"nc_connect_ssh failed"};
}
return session;
}
-std::unique_ptr<Session> Session::connectFd(const int source, const int sink)
+std::unique_ptr<Session> Session::connectFd(const int source, const int sink, std::optional<libyang::Context> ctx)
{
impl::ClientInit::instance();
- auto session = std::make_unique<Session>(nc_connect_inout(source, sink, nullptr));
+ auto session = std::make_unique<Session>(nc_connect_inout(source, sink, ctx ? libyang::retrieveContext(*ctx) : nullptr));
if (!session->m_session) {
throw std::runtime_error{"nc_connect_inout failed"};
}
return session;
}
-std::unique_ptr<Session> Session::connectSocket(const std::string& path)
+std::unique_ptr<Session> Session::connectSocket(const std::string& path, std::optional<libyang::Context> ctx)
{
impl::ClientInit::instance();
- auto session = std::make_unique<Session>(nc_connect_unix(path.c_str(), nullptr));
+ auto session = std::make_unique<Session>(nc_connect_unix(path.c_str(), ctx ? libyang::retrieveContext(*ctx) : nullptr));
if (!session->m_session) {
throw std::runtime_error{"nc_connect_unix failed"};
}