diff --git a/src/moonfire-db-test.cc b/src/moonfire-db-test.cc index fe6efa4..ddcaf4c 100644 --- a/src/moonfire-db-test.cc +++ b/src/moonfire-db-test.cc @@ -67,12 +67,20 @@ class MoonfireDbTest : public testing::Test { DatabaseContext ctx(&db_); auto run = ctx.UseOnce( R"( - insert into camera (uuid, short_name, retain_bytes) - values (:uuid, :short_name, :retain_bytes); + insert into camera (uuid, short_name, host, username, password, + main_rtsp_path, sub_rtsp_path, retain_bytes) + values (:uuid, :short_name, :host, :username, :password, + :main_rtsp_path, :sub_rtsp_path, :retain_bytes); )"); run.BindBlob(":uuid", uuid.binary_view()); run.BindText(":short_name", short_name); + run.BindText(":host", "test-camera"); + run.BindText(":username", "foo"); + run.BindText(":password", "bar"); + run.BindText(":main_rtsp_path", "/main"); + run.BindText(":sub_rtsp_path", "/sub"); run.BindInt64(":retain_bytes", 42); + CHECK_EQ(SQLITE_DONE, run.Step()) << run.error_message(); if (run.Step() != SQLITE_DONE) { ADD_FAILURE() << run.error_message(); return -1; @@ -85,6 +93,12 @@ class MoonfireDbTest : public testing::Test { mdb_->ListCameras([&](const ListCamerasRow &row) { ++rows; EXPECT_EQ(camera_uuid, row.uuid); + EXPECT_EQ("test-camera", row.host); + EXPECT_EQ("foo", row.username); + EXPECT_EQ("bar", row.password); + EXPECT_EQ("/main", row.main_rtsp_path); + EXPECT_EQ("/sub", row.sub_rtsp_path); + EXPECT_EQ(42, row.retain_bytes); EXPECT_EQ(-1, row.min_start_time_90k); EXPECT_EQ(-1, row.max_end_time_90k); EXPECT_EQ(0, row.total_duration_90k); diff --git a/src/moonfire-db.cc b/src/moonfire-db.cc index 7cef909..026ce7f 100644 --- a/src/moonfire-db.cc +++ b/src/moonfire-db.cc @@ -59,6 +59,11 @@ bool MoonfireDatabase::Init(Database *db, std::string *error_message) { camera.uuid, camera.short_name, camera.description, + camera.host, + camera.username, + camera.password, + camera.main_rtsp_path, + camera.sub_rtsp_path, camera.retain_bytes, min(recording.start_time_90k), max(recording.start_time_90k + recording.duration_90k), @@ -80,21 +85,26 @@ bool MoonfireDatabase::Init(Database *db, std::string *error_message) { Uuid uuid; if (!uuid.ParseBinary(list_cameras_run.ColumnBlob(1))) { *error_message = - StrCat("bad uuid ", ToHex(list_cameras_run.ColumnBlob(2)), + StrCat("bad uuid ", ToHex(list_cameras_run.ColumnBlob(1)), " for camera id ", data.id); return false; } data.short_name = list_cameras_run.ColumnText(2).as_string(); data.description = list_cameras_run.ColumnText(3).as_string(); - data.retain_bytes = list_cameras_run.ColumnInt64(4); - data.min_start_time_90k = list_cameras_run.ColumnType(5) == SQLITE_NULL + data.host = list_cameras_run.ColumnText(4).as_string(); + data.username = list_cameras_run.ColumnText(5).as_string(); + data.password = list_cameras_run.ColumnText(6).as_string(); + data.main_rtsp_path = list_cameras_run.ColumnText(7).as_string(); + data.sub_rtsp_path = list_cameras_run.ColumnText(8).as_string(); + data.retain_bytes = list_cameras_run.ColumnInt64(9); + data.min_start_time_90k = list_cameras_run.ColumnType(10) == SQLITE_NULL ? -1 - : list_cameras_run.ColumnInt64(5); - data.max_end_time_90k = list_cameras_run.ColumnType(6) == SQLITE_NULL + : list_cameras_run.ColumnInt64(10); + data.max_end_time_90k = list_cameras_run.ColumnType(11) == SQLITE_NULL ? -1 - : list_cameras_run.ColumnInt64(6); - data.total_duration_90k = list_cameras_run.ColumnInt64(7); - data.total_sample_file_bytes = list_cameras_run.ColumnInt64(8); + : list_cameras_run.ColumnInt64(11); + data.total_duration_90k = list_cameras_run.ColumnInt64(12); + data.total_sample_file_bytes = list_cameras_run.ColumnInt64(13); auto ret = cameras_by_uuid_.insert(std::make_pair(uuid, data)); if (!ret.second) { @@ -307,9 +317,15 @@ void MoonfireDatabase::ListCameras( DatabaseContext ctx(db_); ListCamerasRow row; for (const auto &entry : cameras_by_uuid_) { + row.id = entry.second.id; row.uuid = entry.first; row.short_name = entry.second.short_name; row.description = entry.second.description; + row.host = entry.second.host; + row.username = entry.second.username; + row.password = entry.second.password; + row.main_rtsp_path = entry.second.main_rtsp_path; + row.sub_rtsp_path = entry.second.sub_rtsp_path; row.retain_bytes = entry.second.retain_bytes; row.min_start_time_90k = entry.second.min_start_time_90k; row.max_end_time_90k = entry.second.max_end_time_90k; diff --git a/src/moonfire-db.h b/src/moonfire-db.h index 2b5c178..16324ef 100644 --- a/src/moonfire-db.h +++ b/src/moonfire-db.h @@ -75,9 +75,15 @@ namespace moonfire_nvr { // For use with MoonfireDatabase::ListCameras. struct ListCamerasRow { + int64_t id = -1; Uuid uuid; std::string short_name; std::string description; + std::string host; + std::string username; + std::string password; + std::string main_rtsp_path; + std::string sub_rtsp_path; int64_t retain_bytes = -1; // Aggregates summarizing completed recordings. @@ -201,6 +207,11 @@ class MoonfireDatabase { int64_t id = -1; std::string short_name; std::string description; + std::string host; + std::string username; + std::string password; + std::string main_rtsp_path; + std::string sub_rtsp_path; int64_t retain_bytes = -1; // Aggregates of all recordings associated with the camera.