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_access.cpp b/src/netconf_access.cpp
index 2b76e50..0c25cc8 100644
--- a/src/netconf_access.cpp
+++ b/src/netconf_access.cpp
@@ -59,15 +59,17 @@
}
NetconfAccess::NetconfAccess(const std::string& hostname, uint16_t port, const std::string& user, const std::string& pubKey, const std::string& privKey)
- : m_session(libnetconf::client::Session::connectPubkey(hostname, port, user, pubKey, privKey))
- , m_schema(std::make_shared<YangSchema>(m_session->libyangContext()))
+ : m_context(nullptr, libyang::ContextOptions::SetPrivParsed)
+ , m_session(libnetconf::client::Session::connectPubkey(hostname, port, user, pubKey, privKey, m_context))
+ , m_schema(std::make_shared<YangSchema>(m_context))
{
checkNMDA();
}
NetconfAccess::NetconfAccess(const int source, const int sink)
- : m_session(libnetconf::client::Session::connectFd(source, sink))
- , m_schema(std::make_shared<YangSchema>(m_session->libyangContext()))
+ : m_context(nullptr, libyang::ContextOptions::SetPrivParsed)
+ , m_session(libnetconf::client::Session::connectFd(source, sink, m_context))
+ , m_schema(std::make_shared<YangSchema>(m_context))
{
checkNMDA();
}
@@ -80,8 +82,9 @@
}
NetconfAccess::NetconfAccess(const std::string& socketPath)
- : m_session(libnetconf::client::Session::connectSocket(socketPath))
- , m_schema(std::make_shared<YangSchema>(m_session->libyangContext()))
+ : m_context(nullptr, libyang::ContextOptions::SetPrivParsed)
+ , m_session(libnetconf::client::Session::connectSocket(socketPath, m_context))
+ , m_schema(std::make_shared<YangSchema>(m_context))
{
checkNMDA();
}