utils: wrap libyang utils in velia::utils

The functions in utils/libyang.cpp were not inside velia::utils
namespace. This was bothering me for some time but I was too lazy.
Now I am going to perform a little refactor to those two functions
so perhaps the time is now.

Change-Id: I077c06b700d0529515595a7b85a87550796d8b54
diff --git a/src/firewall/Firewall.cpp b/src/firewall/Firewall.cpp
index 0a2bedc..1474be4 100644
--- a/src/firewall/Firewall.cpp
+++ b/src/firewall/Firewall.cpp
@@ -68,17 +68,17 @@
         if (nodeSchemaPath == nodepaths::ace_comment) {
             // We will use the ACE name as a comment inside the rule. However, the comment must be at the end, so we
             // save it for later.
-            comment = getValueAsString(node);
+            comment = velia::utils::getValueAsString(node);
         } else if (nodeSchemaPath == nodepaths::ipv4_matches) {
             // Here we save the ip we're matching against.
-            match = " ip saddr "s + getValueAsString(node);
+            match = " ip saddr "s + velia::utils::getValueAsString(node);
         } else if (nodeSchemaPath == nodepaths::ipv6_matches) {
             // Here we save the ip we're matching against.
-            match = " ip6 saddr "s + getValueAsString(node);
+            match = " ip6 saddr "s + velia::utils::getValueAsString(node);
         } else if (nodeSchemaPath == nodepaths::action) {
             // Action is the last statement we get, so this is where we create the actual rule.
             ss << "add rule inet filter acls" << match;
-            auto action = getValueAsString(node);
+            auto action = velia::utils::getValueAsString(node);
             if (action ==  "ietf-access-control-list:accept"sv) {
                 ss << " accept";
             } else if (action ==  "ietf-access-control-list:drop"sv) {
diff --git a/src/system/Authentication.cpp b/src/system/Authentication.cpp
index ae03088..f4d10ed 100644
--- a/src/system/Authentication.cpp
+++ b/src/system/Authentication.cpp
@@ -301,9 +301,9 @@
             auto,
             auto output) {
 
-        auto userNode = getSubtree(input, (authentication_container + "/users" ).c_str());
-        auto name = getValueAsString(getSubtree(userNode, "name"));
-        auto password = getValueAsString(getSubtree(userNode, "change-password/password-cleartext"));
+        auto userNode = utils::getSubtree(input, (authentication_container + "/users" ).c_str());
+        auto name = utils::getValueAsString(utils::getSubtree(userNode, "name"));
+        auto password = utils::getValueAsString(utils::getSubtree(userNode, "change-password/password-cleartext"));
         m_log->debug("Changing password for {}", name);
         try {
             changePassword(name, password, m_etc_shadow);
@@ -326,9 +326,9 @@
             auto,
             auto output) {
 
-        auto userNode = getSubtree(input, (authentication_container + "/users").c_str());
-        auto name = getValueAsString(getSubtree(userNode, "name"));
-        auto key = getValueAsString(getSubtree(userNode, "add-authorized-key/key"));
+        auto userNode = utils::getSubtree(input, (authentication_container + "/users").c_str());
+        auto name = utils::getValueAsString(utils::getSubtree(userNode, "name"));
+        auto key = utils::getValueAsString(utils::getSubtree(userNode, "add-authorized-key/key"));
         m_log->debug("Adding key for {}", name);
         try {
             addKey(name, key);
@@ -351,9 +351,9 @@
             auto,
             auto output) {
 
-        auto userNode = getSubtree(input, (authentication_container + "/users").c_str());
-        auto name = getValueAsString(getSubtree(userNode, "name"));
-        auto key = std::stol(getValueAsString(getSubtree(userNode, "authorized-keys/index")));
+        auto userNode = utils::getSubtree(input, (authentication_container + "/users").c_str());
+        auto name = utils::getValueAsString(utils::getSubtree(userNode, "name"));
+        auto key = std::stol(utils::getValueAsString(utils::getSubtree(userNode, "authorized-keys/index")));
         m_log->debug("Removing key for {}", name);
         try {
             removeKey(name, key);
diff --git a/src/system/IETFInterfacesConfig.cpp b/src/system/IETFInterfacesConfig.cpp
index 421fd85..f28f124 100644
--- a/src/system/IETFInterfacesConfig.cpp
+++ b/src/system/IETFInterfacesConfig.cpp
@@ -52,7 +52,7 @@
     const auto xpath = "ietf-ip:" + proto + "/enabled";
 
     try {
-        auto enabled = getValueAsString(getSubtree(linkEntry, xpath.c_str()));
+        auto enabled = velia::utils::getValueAsString(velia::utils::getSubtree(linkEntry, xpath.c_str()));
         return enabled == "true"s;
     } catch (const std::runtime_error&) { // leaf and the presence container missing
         return false;
@@ -90,10 +90,10 @@
         for (const auto& linkEntry : linkEntries->data()) {
             std::map<std::string, std::vector<std::string>> configValues;
 
-            auto linkName = getValueAsString(getSubtree(linkEntry, "name"));
+            auto linkName = utils::getValueAsString(utils::getSubtree(linkEntry, "name"));
 
             if (auto set = linkEntry->find_path("description"); set->number() != 0) {
-                configValues["Network"].push_back("Description="s + getValueAsString(set->data().front()));
+                configValues["Network"].push_back("Description="s + utils::getValueAsString(set->data().front()));
             }
 
             // if addresses present, generate them...
@@ -107,8 +107,8 @@
                 const auto addresses = linkEntry->find_path(IPAddressListXPath.c_str());
 
                 for (const auto& ipEntry : addresses->data()) {
-                    auto ipAddress = getValueAsString(getSubtree(ipEntry, "ip"));
-                    auto prefixLen = getValueAsString(getSubtree(ipEntry, "prefix-length"));
+                    auto ipAddress = utils::getValueAsString(utils::getSubtree(ipEntry, "ip"));
+                    auto prefixLen = utils::getValueAsString(utils::getSubtree(ipEntry, "prefix-length"));
 
                     spdlog::get("system")->trace("Link {}: address {}/{} configured", linkName, ipAddress, prefixLen);
                     configValues["Network"].push_back("Address="s + ipAddress + "/" + prefixLen);
@@ -120,7 +120,7 @@
             bool isSlave = false;
 
             if (auto set = linkEntry->find_path("czechlight-network:bridge"); set->number() > 0) {
-                configValues["Network"].push_back("Bridge="s + getValueAsString(set->data().front()));
+                configValues["Network"].push_back("Bridge="s + utils::getValueAsString(set->data().front()));
                 isSlave = true;
             }
 
diff --git a/src/system/LED.cpp b/src/system/LED.cpp
index 85c0e9b..1d0b68a 100644
--- a/src/system/LED.cpp
+++ b/src/system/LED.cpp
@@ -54,7 +54,7 @@
     m_srSubscribe->rpc_subscribe_tree(
         (CZECHLIGHT_SYSTEM_LEDS_MODULE_PREFIX + "uid").c_str(),
         [this, uidMaxBrightness, triggerFile, brightnessFile](auto session, auto, auto input, auto, auto, auto) {
-            std::string val = getValueAsString(getSubtree(input, (CZECHLIGHT_SYSTEM_LEDS_MODULE_PREFIX + "uid/state").c_str()));
+            std::string val = utils::getValueAsString(utils::getSubtree(input, (CZECHLIGHT_SYSTEM_LEDS_MODULE_PREFIX + "uid/state").c_str()));
 
             try {
                 if (val == "on") {
diff --git a/src/utils/libyang.cpp b/src/utils/libyang.cpp
index 3f32575..d018a09 100644
--- a/src/utils/libyang.cpp
+++ b/src/utils/libyang.cpp
@@ -2,6 +2,8 @@
 #include <libyang/Tree_Data.hpp>
 #include "utils/libyang.h"
 
+namespace velia::utils {
+
 const char* getValueAsString(const libyang::S_Data_Node& node)
 {
     if (!node || node->schema()->nodetype() != LYS_LEAF) {
@@ -20,3 +22,4 @@
 
     return set->data().front();
 }
+}
diff --git a/src/utils/libyang.h b/src/utils/libyang.h
index 95260af..4ccc59d 100644
--- a/src/utils/libyang.h
+++ b/src/utils/libyang.h
@@ -12,6 +12,8 @@
     class Data_Node;
 }
 
+namespace velia::utils {
+
 /**
  * @brief Gets a string value from a node.
  *
@@ -25,3 +27,4 @@
  * Throws if there is more than one matching node. Also throws if there aren't any matching nodes.
  */
 std::shared_ptr<libyang::Data_Node> getSubtree(const std::shared_ptr<libyang::Data_Node>& start, const char* path);
+}