mgmt: management tools
refs #2034
Change-Id: I43ff11e0aa7e67f6207e75f139b7417779590efc
diff --git a/src/daemon/db-mgr.cpp b/src/daemon/db-mgr.cpp
index 35af5de..53d3822 100644
--- a/src/daemon/db-mgr.cpp
+++ b/src/daemon/db-mgr.cpp
@@ -174,6 +174,31 @@
return zone.getId() != 0;
}
+std::vector<Zone>
+DbMgr::listZones()
+{
+ sqlite3_stmt* stmt;
+ const char* sql = "SELECT id, name, ttl FROM zones";
+ int rc = sqlite3_prepare_v2(m_conn, sql, -1, &stmt, 0);
+ if (rc != SQLITE_OK) {
+ throw PrepareError(sql);
+ }
+
+ std::vector<Zone> vec;
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ vec.emplace_back();
+ Zone& zone = vec.back();
+ zone.setId(sqlite3_column_int64(stmt, 0));
+ zone.setTtl(time::seconds(sqlite3_column_int(stmt, 2)));
+ zone.setName(Name(Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 1)),
+ sqlite3_column_bytes(stmt, 1))));
+ }
+ sqlite3_finalize(stmt);
+
+ return vec;
+}
+
void
DbMgr::remove(Zone& zone)
{
diff --git a/src/daemon/db-mgr.hpp b/src/daemon/db-mgr.hpp
index ca83691..336b330 100644
--- a/src/daemon/db-mgr.hpp
+++ b/src/daemon/db-mgr.hpp
@@ -113,6 +113,12 @@
find(Zone& zone);
/**
+ * @brief get all zones in the database
+ */
+ std::vector<Zone>
+ listZones();
+
+ /**
* @brief remove the zone
* @pre m_zone.getId() > 0
* @post m_zone.getId() == 0