v1.1.4 : Added code quality check & fixed result.json fmt

This commit is contained in:
Brendan LE GLAUNEC
2016-12-13 12:04:32 +01:00
committed by Brendan LE GLAUNEC
parent 1fc21f0906
commit 6e06346685
12 changed files with 21 additions and 210 deletions
+5 -4
View File
@@ -2,10 +2,11 @@
## An RTSP surveillance camera access multitool
[![cameradar License](https://img.shields.io/badge/license-Apache-blue.svg?style=flat-square)](#license)
[![Docker Pulls](https://img.shields.io/docker/pulls/ullaakut/cameradar.svg?style=flat-square)](https://hub.docker.com/r/ullaakut/cameradar/)
[![Build](https://img.shields.io/travis/EtixLabs/cameradar/master.svg?style=flat-square)](https://travis-ci.org/EtixLabs/cameradar)
[![Latest release](https://img.shields.io/github/release/EtixLabs/cameradar.svg?style=flat-square)](https://github.com/EtixLabs/cameradar/releases/latest)
[![cameradar License](https://img.shields.io/badge/license-Apache-blue.svg?style=flat)](#license)
[![Docker Pulls](https://img.shields.io/docker/pulls/ullaakut/cameradar.svg?style=flat)](https://hub.docker.com/r/ullaakut/cameradar/)
[![Build](https://img.shields.io/travis/EtixLabs/cameradar/master.svg?style=flat)](https://travis-ci.org/EtixLabs/cameradar)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4cca0fe9dd6f457fa904bd2731b7bb9a)](https://www.codacy.com/app/brendan-le-glaunec/cameradar?utm_source=github.com&utm_medium=referral&utm_content=EtixLabs/cameradar&utm_campaign=Badge_Grade)
[![Latest release](https://img.shields.io/github/release/EtixLabs/cameradar.svg?style=flat)](https://github.com/EtixLabs/cameradar/releases/latest)
#### Cameradar allows you to:
-1
View File
@@ -27,7 +27,6 @@ namespace tool {
namespace encode {
std::string encode64(const std::string& str_to_encode);
std::string decode64(const std::string& str_to_decode);
std::string base64_encode(unsigned char const*, unsigned int len);
std::string base64_decode(std::string const& s);
+3 -16
View File
@@ -14,14 +14,16 @@
#pragma once
#include "spdlog/spdlog.h"
#include <sstream>
#include <string>
#include "spdlog/spdlog.h"
namespace etix {
namespace tool {
enum class loglevel { DEBUG = 1, INFO = 2, WARN = 4, ERR = 5, CRITICAL = 6 };
inline std::string
format_output(const std::string& from, const std::string& message) {
auto ss = std::stringstream{};
@@ -32,8 +34,6 @@ format_output(const std::string& from, const std::string& message) {
return ss.str();
}
enum class loglevel { DEBUG = 1, INFO = 2, WARN = 4, ERR = 5, CRITICAL = 6 };
class logger {
std::string name;
std::shared_ptr<spdlog::logger> console;
@@ -64,11 +64,6 @@ public:
}
}
std::string
get_name() const {
return this->name;
}
static void
info(const std::string& message) {
etix::tool::logger::get_instance().console->info(message);
@@ -84,11 +79,6 @@ public:
etix::tool::logger::get_instance().console->error(message);
}
static void
crit(const std::string& message) {
etix::tool::logger::get_instance().console->critical(message);
}
static void
debug(const std::string& message) {
etix::tool::logger::get_instance().console->debug(message);
@@ -111,6 +101,3 @@ public:
#define LOG_INFO_(message, from) \
etix::tool::logger::get_instance().info(etix::tool::format_output( \
std::string(from) + "::" + __FUNCTION__ + ":" + std::to_string(__LINE__), message))
#define LOG_CRIT_(message, from) \
etix::tool::logger::get_instance().crit(etix::tool::format_output( \
std::string(from) + "::" + __FUNCTION__ + ":" + std::to_string(__LINE__), message))
+2 -47
View File
@@ -27,11 +27,6 @@ encode64(const std::string& str_to_encode) {
str_to_encode.length());
}
std::string
decode64(const std::string& str_to_decode) {
return base64_decode(str_to_decode);
}
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
@@ -47,7 +42,6 @@ std::string
base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
@@ -64,8 +58,9 @@ base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
}
}
int j = 0;
if (i) {
for (j = i; j < 3; j++) char_array_3[j] = '\0';
for (int j = i; j < 3; j++) char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
@@ -79,46 +74,6 @@ base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
return ret;
}
/* from external source */
std::string
base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
std::string ret;
while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_];
in_++;
if (i == 4) {
for (i = 0; i < 4; i++) char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (i = 0; (i < 3); i++) ret += char_array_3[i];
i = 0;
}
}
if (i) {
for (j = i; j < 4; j++) char_array_4[j] = 0;
for (j = 0; j < 4; j++) char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
}
return ret;
}
}
}
}
-124
View File
@@ -1,124 +0,0 @@
// Copyright 2016 Etix Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fs.h"
#include <vector> // for std::vector
#include <sstream> // for std::stringstream
#include <pwd.h> // for getpwuid, passwd
#include <stddef.h> // for size_t
#include <sys/stat.h> // for stat, mkdir, S_ISDIR
#include <unistd.h> // for getuid
#include <fstream> // for std::ifstream
namespace etix {
namespace tool {
std::vector<std::string>
split(const std::string& s, char delim) {
std::vector<std::string> elems;
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) elems.push_back(item);
return elems;
}
namespace fs {
fs_error
is_folder(const std::string& folder) {
struct stat sb;
if (stat(folder.c_str(), &sb) == 0) {
if (S_ISDIR(sb.st_mode))
return fs_error::is_dir;
else
return fs_error::is_not_dir;
}
return fs_error::dont_exist;
}
bool
get_or_create_folder(const std::string& folder) {
bool status = false;
switch (is_folder(folder)) {
case fs_error::is_dir: status = true; break;
case fs_error::is_not_dir: status = false; break;
case fs_error::dont_exist: status = create_recursive_folder(folder); break;
}
return status;
}
bool
create_folder(const std::string& folder) {
if (mkdir(folder.c_str(), 0755) == 0) { return true; }
return false;
}
bool
create_recursive_folder(const std::string& folder) {
auto path_elems = split(folder, '/');
std::string current_path = folder[0] == '/' ? "/" : "";
for (const auto& elem : path_elems) {
current_path += elem;
if (is_folder(current_path) == fs_error::dont_exist) create_folder(current_path);
current_path += '/';
}
return true;
}
std::string
get_file_folder(std::string full_file_path) {
// remove ending slash
if (full_file_path.back() == '/') full_file_path.pop_back();
size_t last_slash_position = full_file_path.find_last_of('/');
// it there is no slash, there is no folder to return
if (last_slash_position == std::string::npos) return "";
return std::string(full_file_path, 0, last_slash_position);
}
std::string
home(void) {
struct passwd* passwdEnt = getpwuid(getuid());
return { passwdEnt->pw_dir };
}
bool
copy(const std::string& src, const std::string& dst) {
std::ifstream src_stream(src, std::ios::binary);
std::ofstream dst_stream(dst, std::ios::binary);
if (not src_stream.is_open()) return false;
dst_stream << src_stream.rdbuf();
return true;
}
} // fs
} // tool
} // etix
-1
View File
@@ -14,7 +14,6 @@
#include "version.h" // versionning
#include <dispatcher.h> // program loop
#include <fs.h> // fs::home
#include <iostream> // iostream
#include <opt_parse.h> // parsing opt
+1 -4
View File
@@ -70,10 +70,7 @@ brutepath::bruteforce_camera(const stream_model& stream) const {
if (signal_handler::instance().should_stop() != etix::cameradar::stop_priority::running)
break;
if ((*cache)->has_changed(stream)) return true;
if (test_path(stream, route)) {
return true;
break;
}
if (test_path(stream, route)) return true;
}
return false;
}
+3 -3
View File
@@ -35,10 +35,10 @@ print::run() const {
for (const auto& stream : results) {
file << deserialize(stream).toStyledString();
if (first)
first = false;
else
if (first) {
file << ",";
first = false;
}
LOG_INFO_("Generated JSON Result : " + deserialize(stream).toStyledString(), "print");
}
@@ -22,21 +22,19 @@ namespace cameradar {
// In order to check for the stream validity
bool
stream_check::run() const {
GstElement* pipeline;
GstElement* elem;
gst_init(nullptr, nullptr);
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;
pipeline =
GstElement* pipeline =
gst_parse_launch("rtspsrc name=source ! rtph264depay ! h264parse ! fakesink", &error);
std::string location = "rtsp://";
-1
View File
@@ -2,7 +2,6 @@
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
# if command starts with an option, prepend /cameradar/bin/cameradar
+2 -2
View File
@@ -43,7 +43,7 @@ function start {
for (( i=1; i<=$1; i++ )); do
name="$cams_name_pattern$i"
# random conf
conf_idx=$(($RANDOM % ${#ports[@]}))
conf_idx=$((RANDOM % ${#ports[@]}))
# get conf variables
port=${ports[$conf_idx]}
@@ -65,7 +65,7 @@ function start {
function stop {
# if no cameras containers are started just exit
camera_count="`docker ps -a -q --filter="name=$cams_name_pattern" | wc -l`"
camera_count="$(docker ps -a -q --filter="name=$cams_name_pattern" | wc -l)"
if [ "$camera_count" == "0" ]; then
echo "error: no cameras started"; exit 1
fi
+3 -3
View File
@@ -21,11 +21,11 @@ function make_docker_command {
# add mysql libk
cmd="$cmd --link=\"cameradar-database\""
# add cameradar srcs
cmd="$cmd -v \"`pwd`/src:/go/src/cameradartest\""
cmd="$cmd -v \"$(pwd)/src:/go/src/cameradartest\""
# add cmaeradar conf
cmd="$cmd -v \"`pwd`/:/tmp/tests\""
cmd="$cmd -v \"$(pwd)/:/tmp/tests\""
# add container name
cmd="$cmd -v \"`pwd`/:/tmp/shared\""
cmd="$cmd -v \"$(pwd)/:/tmp/shared\""
# add container name
cmd="$cmd cameradartest"
}