Fix issues with MySQL CM

This commit is contained in:
Brendan LE GLAUNEC
2016-08-24 12:11:54 +02:00
committed by Brendan Le Glaunec
parent 13e1836604
commit bded05688e
7 changed files with 61 additions and 34 deletions
+1 -1
View File
@@ -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}")
+1 -1
View File
@@ -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:
@@ -149,28 +149,33 @@ void
mysql_cache_manager::set_streams(std::vector<etix::cameradar::stream_model> 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);
}
}
+8 -7
View File
@@ -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<etix::cameradar::stream_model> 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) {
+4 -4
View File
@@ -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<stream_model>& 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);
}
@@ -29,6 +29,10 @@ stream_check::run() const {
std::vector<stream_model> 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;
@@ -48,7 +48,12 @@ bool
thumbnail::run() const {
std::vector<stream_model> 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 =