From bded05688eca86c527c0bd7687521519ac12f8d3 Mon Sep 17 00:00:00 2001 From: Brendan LE GLAUNEC Date: Wed, 24 Aug 2016 12:11:54 +0200 Subject: [PATCH] Fix issues with MySQL CM --- CMakeLists.txt | 2 +- README.md | 2 +- .../src/mysql_cache_manager.cpp | 59 ++++++++++++------- cameradar_standalone/src/tasks/brutelogs.cpp | 15 ++--- cameradar_standalone/src/tasks/parsing.cpp | 8 +-- .../src/tasks/stream_check.cpp | 4 ++ cameradar_standalone/src/tasks/thumbnail.cpp | 5 ++ 7 files changed, 61 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efb2033..a2e6dcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ message ("Here") set (${PROJECT_NAME}_VERSION_MAJOR 1) set (${PROJECT_NAME}_VERSION_MINOR 0) -set (${PROJECT_NAME}_VERSION_PATCH 1) +set (${PROJECT_NAME}_VERSION_PATCH 2) set (${PROJECT_NAME}_SUFFIX "-beta") set (${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}${${PROJECT_NAME}_SUFFIX}") diff --git a/README.md b/README.md index 561caa7..9e166b6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## An RTSP surveillance camera access multitool [![cameradar License](https://img.shields.io/badge/license-Apache-blue.svg)](#license) -[![Latest release](https://img.shields.io/badge/release-1.0.1-green.svg)](https://github.com/EtixLabs/cameradar/releases/latest) +[![Latest release](https://img.shields.io/badge/release-1.0.2-green.svg)](https://github.com/EtixLabs/cameradar/releases/latest) #### Cameradar allows you to: diff --git a/cache_managers/mysql_cache_manager/src/mysql_cache_manager.cpp b/cache_managers/mysql_cache_manager/src/mysql_cache_manager.cpp index 53d765f..8708bed 100644 --- a/cache_managers/mysql_cache_manager/src/mysql_cache_manager.cpp +++ b/cache_managers/mysql_cache_manager/src/mysql_cache_manager.cpp @@ -149,28 +149,33 @@ void mysql_cache_manager::set_streams(std::vector models) { LOG_DEBUG_("Beginning stream list DB insertion", "mysql_cache_manager"); for (const auto& model : models) { - auto query = tool::fmt( - this->exist_query, this->connection.get_db_name().c_str(), model.address.c_str()); - auto result = this->connection.query(query); - // If an entry already exists for this address in the database, - // no need to insert it. - if (result.data->next()) return; + if (!model.service_name.compare("rtsp") && !model.state.compare("open")) { + auto query = tool::fmt( + this->exist_query, this->connection.get_db_name().c_str(), model.address.c_str()); + auto result = this->connection.query(query); + // If an entry already exists for this address in the database, + // no need to insert it. - query = tool::fmt(this->insert_with_id_query, - this->connection.get_db_name().c_str(), - model.address.c_str(), - model.password.c_str(), - model.product.c_str(), - model.protocol.c_str(), - model.route.c_str(), - model.service_name.c_str(), - model.state.c_str(), - model.thumbnail_path.c_str(), - model.username.c_str(), - std::to_string(model.port).c_str(), - std::to_string(model.ids_found).c_str(), - std::to_string(model.path_found).c_str()); - execute_query(query); + // TODO : Update an entry if it already exists. + + if (result.data->next()) return; + + query = tool::fmt(this->insert_with_id_query, + this->connection.get_db_name().c_str(), + model.address.c_str(), + model.password.c_str(), + model.product.c_str(), + model.protocol.c_str(), + model.route.c_str(), + model.service_name.c_str(), + model.state.c_str(), + model.thumbnail_path.c_str(), + model.username.c_str(), + std::to_string(model.port).c_str(), + std::to_string(model.ids_found).c_str(), + std::to_string(model.path_found).c_str()); + execute_query(query); + } } } @@ -219,6 +224,18 @@ mysql_cache_manager::get_streams() { result.data->getString("state"), result.data->getBoolean("ids_found"), result.data->getBoolean("path_found"), result.data->getString("thumbnail_path") }; + LOG_DEBUG_("Got a result whose address was " + s.address, "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose port was " + std::to_string(s.port), "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose username was " + s.username, "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose password was " + s.password, "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose route was " + s.route, "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose service name was " + s.service_name, "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose product was " + s.product, "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose protocol was " + s.protocol, "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose state was " + s.state, "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose ids found was " + std::to_string(s.ids_found), "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose path found was " + std::to_string(s.path_found), "mysql_cache_manager"); + LOG_DEBUG_("Got a result whose thumbnail was " + s.thumbnail_path, "mysql_cache_manager"); lst.push_back(s); } } diff --git a/cameradar_standalone/src/tasks/brutelogs.cpp b/cameradar_standalone/src/tasks/brutelogs.cpp index 8ef20a6..e308da3 100644 --- a/cameradar_standalone/src/tasks/brutelogs.cpp +++ b/cameradar_standalone/src/tasks/brutelogs.cpp @@ -42,16 +42,16 @@ brutelogs::test_ids(const etix::cameradar::stream_model& stream, LOG_DEBUG_("[FOUND IDS] : " + path, "brutelogs"); found = true; stream_model newstream{ - stream.address, stream.port, username, password, - stream.route, stream.service_name, stream.product, stream.protocol, - stream.state, stream.path_found, true, stream.thumbnail_path + stream.address, stream.port, username, password, + stream.route, stream.service_name, stream.product, stream.protocol, + stream.state, true, stream.path_found, stream.thumbnail_path }; (*cache)->update_stream(newstream); } else { - stream_model newstream{ stream.address, stream.port, username, - password, stream.route, stream.service_name, - stream.product, stream.protocol, stream.state, - stream.path_found, false, stream.thumbnail_path }; + stream_model newstream{ stream.address, stream.port, username, + password, stream.route, stream.service_name, + stream.product, stream.protocol, stream.state, + false, stream.path_found, stream.thumbnail_path }; (*cache)->update_stream(newstream); } } catch (const std::runtime_error& e) { @@ -77,6 +77,7 @@ brutelogs::run() const { "take a while.", "brutelogs"); std::vector streams = (*cache)->get_streams(); + LOG_DEBUG_("Found " + std::to_string(streams.size()) + " streams in the cache", "brutelogs"); bool doubleskip; size_t found = 0; for (const auto& stream : streams) { diff --git a/cameradar_standalone/src/tasks/parsing.cpp b/cameradar_standalone/src/tasks/parsing.cpp index b377b36..4e56135 100644 --- a/cameradar_standalone/src/tasks/parsing.cpp +++ b/cameradar_standalone/src/tasks/parsing.cpp @@ -27,9 +27,9 @@ static const std::string no_hosts_found_ = //! Avoids segfaults on unknown xml structure std::string xml_safe_get(const TiXmlElement* elem, const std::string& attr) { - if (elem == nullptr) return "Closed"; + if (elem == nullptr) return "closed"; if (elem->Attribute(attr.c_str()) != nullptr) return std::string(elem->Attribute(attr.c_str())); - return "Closed"; + return "closed"; } //! Parse a single host node (generally containing only one camera) @@ -51,8 +51,8 @@ parsing::parse_camera(TiXmlElement* xml_host, std::vector& data) c stream.service_name = xml_safe_get(service, "name"); stream.product = xml_safe_get(service, "product"); } else { - stream.service_name = "Closed"; - stream.product = "Closed"; + stream.service_name = "closed"; + stream.product = "closed"; } data.push_back(stream); } diff --git a/cameradar_standalone/src/tasks/stream_check.cpp b/cameradar_standalone/src/tasks/stream_check.cpp index e9cc28b..770df51 100644 --- a/cameradar_standalone/src/tasks/stream_check.cpp +++ b/cameradar_standalone/src/tasks/stream_check.cpp @@ -29,6 +29,10 @@ stream_check::run() const { std::vector streams = (*cache)->get_valid_streams(); + if (not streams.size()) { + LOG_WARN_("There were no valid streams to check. Cameradar will stop.", "stream_check"); + return false; + } for (const auto& stream : streams) { GError* error = NULL; diff --git a/cameradar_standalone/src/tasks/thumbnail.cpp b/cameradar_standalone/src/tasks/thumbnail.cpp index e33e20a..7bd4cb7 100644 --- a/cameradar_standalone/src/tasks/thumbnail.cpp +++ b/cameradar_standalone/src/tasks/thumbnail.cpp @@ -48,7 +48,12 @@ bool thumbnail::run() const { std::vector streams = (*cache)->get_valid_streams(); LOG_INFO_("Started thumbnail generation, it may take a while", "thumbnail"); + if (not streams.size()) { + LOG_WARN_("There were no valid streams to generate thumbnails from. Cameradar will stop.", "thumbnail_generation"); + return false; + } for (const auto& stream : streams) { + LOG_DEBUG_("Generating thumbnail for " + stream.address, "thumbnail_generation"); if (signal_handler::instance().should_stop() != etix::cameradar::stop_priority::running) break; std::string ffmpeg_cmd =