Commit 5aa17595 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud

sonarqube: fix some code smells

+ Remove some unused using
+ Remove useless std::move
+ Reduce duplicate code
+ Avoid some copy

Change-Id: I7bdbc14aa1b79ce10d30f2f1ef005dd8839de62a
parent 39635c7e
......@@ -125,11 +125,11 @@ AccountFactory::getAllAccounts() const
for (const auto& itemmap : accountMaps_) {
const auto& map = itemmap.second;
for (const auto item : map)
v.reserve(v.size() + map.size());
for (const auto& item : map)
v.push_back(item.second);
}
v.shrink_to_fit();
return v;
}
......
......@@ -77,7 +77,7 @@ accountToJsonValue(const std::map<std::string, std::string>& details) {
// replace paths by the files content
std::ifstream ifs(i.second);
std::string fileContent((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
root[i.first] = std::move(fileContent);
root[i.first] = fileContent;
} else
root[i.first] = i.second;
}
......
......@@ -135,7 +135,7 @@ registerSignalHandlers(const std::map<std::string,
JAMI_ERR("Signal %s not supported", item.first.c_str());
continue;
}
iter->second = std::move(item.second);
iter->second = item.second;
}
}
......
......@@ -272,7 +272,7 @@ private:
SubOutgoingFileTransfer::SubOutgoingFileTransfer(DRing::DataTransferId tid,
const std::string& peerUri,
std::shared_ptr<OptimisticMetaOutgoingInfo> metaInfo)
: DataTransfer(tid), metaInfo_(metaInfo), peerUri_(peerUri)
: DataTransfer(tid), metaInfo_(std::move(metaInfo)), peerUri_(peerUri)
{
info_ = metaInfo_->info();
......
......@@ -42,7 +42,7 @@ class IceSocket
public:
IceSocket(std::shared_ptr<IceTransport> iceTransport, int compId)
: ice_transport_(iceTransport), compId_(compId) {}
: ice_transport_(std::move(iceTransport)), compId_(compId) {}
void close();
ssize_t recv(unsigned char* buf, size_t len);
......
......@@ -999,7 +999,7 @@ IceTransport::start(const std::vector<uint8_t>& rem_data)
IceCandidate cand;
for (const auto& line : result.get().as<std::vector<std::string>>()) {
if (getCandidateFromSDP(line, cand))
rem_candidates.emplace_back(std::move(cand));
rem_candidates.emplace_back(cand);
}
}
} else {
......
......@@ -239,7 +239,7 @@ public:
JAMI_DBG("[Account:%s] add remote ICE candidate: %s",
account.getAccountID().c_str(),
line.c_str());
res.rem_candidates.emplace_back(std::move(cand));
res.rem_candidates.emplace_back(cand);
}
}
nr++;
......@@ -546,9 +546,9 @@ DhtPeerConnector::Impl::turnConnect()
// If a previous turn server exists, but is not ready, we should try to reconnect
if (turnAuthv4_ && !turnAuthv4_->isReady())
turnAuthv4_.release();
turnAuthv4_.reset();
if (turnAuthv6_ && !turnAuthv6_->isReady())
turnAuthv6_.release();
turnAuthv6_.reset();
if (!turnAuthv4_ || !turnAuthv4_->isReady()) {
turn_param_v4.authorized_family = PJ_AF_INET;
......
......@@ -475,7 +475,7 @@ VideoInput::initAVFoundation(const std::string& display)
bool
VideoInput::initGdiGrab(std::string params)
VideoInput::initGdiGrab(const std::string& params)
{
size_t space = params.find(' ');
clearOptions();
......
......@@ -126,7 +126,7 @@ private:
bool initX11(std::string display);
bool initAVFoundation(const std::string& display);
bool initFile(std::string path);
bool initGdiGrab(std::string params);
bool initGdiGrab(const std::string& params);
// for ThreadLoop
bool setup();
......
......@@ -43,7 +43,6 @@
namespace jami { namespace video {
using std::map;
using std::string;
// how long (in seconds) to wait before rechecking for packet loss
......
......@@ -52,6 +52,38 @@
namespace jami {
int
init_crt(gnutls_session_t session, dht::crypto::Certificate& crt)
{
// Support only x509 format
if (gnutls_certificate_type_get(session) != GNUTLS_CRT_X509) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
// Store verification status
unsigned int status = 0;
auto ret = gnutls_certificate_verify_peers2(session, &status);
if (ret < 0 or (status & GNUTLS_CERT_SIGNATURE_FAILURE) != 0) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
unsigned int cert_list_size = 0;
auto cert_list = gnutls_certificate_get_peers(session, &cert_list_size);
if (cert_list == nullptr) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
// Check if received peer certificate is awaited
std::vector<std::pair<uint8_t *, uint8_t *>> crt_data;
crt_data.reserve(cert_list_size);
for (unsigned i = 0; i < cert_list_size; i++)
crt_data.emplace_back(cert_list[i].data,
cert_list[i].data + cert_list[i].size);
crt = dht::crypto::Certificate{crt_data};
return GNUTLS_E_SUCCESS;
}
using lock = std::lock_guard<std::mutex>;
static constexpr std::size_t IO_BUFFER_SIZE {3000}; ///< Size of char buffer used by IO operations
......@@ -90,30 +122,9 @@ TlsTurnEndpoint::Impl::~Impl()
int
TlsTurnEndpoint::Impl::verifyCertificate(gnutls_session_t session)
{
// Support only x509 format
if (gnutls_certificate_type_get(session) != GNUTLS_CRT_X509) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
// Store verification status
unsigned int status = 0;
auto ret = gnutls_certificate_verify_peers2(session, &status);
if (ret < 0 or (status & GNUTLS_CERT_SIGNATURE_FAILURE) != 0) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
unsigned int cert_list_size = 0;
auto cert_list = gnutls_certificate_get_peers(session, &cert_list_size);
if (cert_list == nullptr) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
// Check if received peer certificate is awaited
std::vector<std::pair<uint8_t*, uint8_t*>> crt_data;
crt_data.reserve(cert_list_size);
for (unsigned i=0; i<cert_list_size; i++)
crt_data.emplace_back(cert_list[i].data, cert_list[i].data + cert_list[i].size);
auto crt = dht::crypto::Certificate {crt_data};
dht::crypto::Certificate crt;
auto verified = init_crt(session, crt);
if (verified != GNUTLS_E_SUCCESS) return verified;
if (!peerCertificateCheckFunc(crt))
return GNUTLS_E_CERTIFICATE_ERROR;
......@@ -398,30 +409,9 @@ constexpr std::chrono::seconds TlsSocketEndpoint::Impl::TLS_TIMEOUT;
int
TlsSocketEndpoint::Impl::verifyCertificate(gnutls_session_t session)
{
// Support only x509 format
if (gnutls_certificate_type_get(session) != GNUTLS_CRT_X509) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
// Store verification status
unsigned int status = 0;
auto ret = gnutls_certificate_verify_peers2(session, &status);
if (ret < 0 or (status & GNUTLS_CERT_SIGNATURE_FAILURE) != 0) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
unsigned int cert_list_size = 0;
auto cert_list = gnutls_certificate_get_peers(session, &cert_list_size);
if (cert_list == nullptr) {
return GNUTLS_E_CERTIFICATE_ERROR;
}
// Check if peer certificate is equal to the expected one
std::vector<std::pair<uint8_t*, uint8_t*>> crt_data;
crt_data.reserve(cert_list_size);
for (unsigned i=0; i<cert_list_size; i++)
crt_data.emplace_back(cert_list[i].data, cert_list[i].data + cert_list[i].size);
auto crt = dht::crypto::Certificate {crt_data};
dht::crypto::Certificate crt;
auto verified = init_crt(session, crt);
if (verified != GNUTLS_E_SUCCESS) return verified;
if (peerCertificateCheckFunc) {
if (!(*peerCertificateCheckFunc)(crt)) {
JAMI_ERR() << "[TLS-SOCKET] Unexpected peer certificate";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment