Commit 94460d0e authored by Adrien Béraud's avatar Adrien Béraud

qa: fix issues found using clang-tidy

Change-Id: I04de6bb39925c48665cf234f3a714167d9f6ef7c
parent 044ac764
......@@ -208,8 +208,8 @@ void addContact(const std::string& accountId, const std::string& uri);
void removeContact(const std::string& accountId, const std::string& uri, const bool& ban);
std::vector<std::map<std::string, std::string>> getContacts(const std::string& accountId);
int exportAccounts(std::vector<std::string> accountIDs, std::string toDir, std::string password);
int importAccounts(std::string archivePath, std::string password);
int exportAccounts(const std::vector<std::string>& accountIDs, const std::string& toDir, const std::string& password);
int importAccounts(const std::string& archivePath, const std::string& password);
void connectivityChanged();
......
......@@ -384,13 +384,13 @@ sendTrustRequest(const std::string& accountId, const std::string& to, const std:
* Import/Export accounts
*/
int
exportAccounts(std::vector<std::string> accountIDs, std::string filepath, std::string password)
exportAccounts(const std::vector<std::string>& accountIDs, const std::string& filepath, const std::string& password)
{
return ring::archiver::exportAccounts(accountIDs, filepath, password);
}
int
importAccounts(std::string archivePath, std::string password)
importAccounts(const std::string& archivePath, const std::string& password)
{
return ring::archiver::importAccounts(archivePath, password);
}
......
......@@ -273,7 +273,7 @@ VideoFrame::setFromMemory(uint8_t* ptr, int format, int width, int height) noexc
void
VideoFrame::setFromMemory(uint8_t* ptr, int format, int width, int height,
std::function<void(uint8_t*)> cb) noexcept
const std::function<void(uint8_t*)>& cb) noexcept
{
setFromMemory(ptr, format, width, height);
if (cb) {
......@@ -283,7 +283,7 @@ VideoFrame::setFromMemory(uint8_t* ptr, int format, int width, int height,
}
void
VideoFrame::setReleaseCb(std::function<void(uint8_t*)> cb) noexcept
VideoFrame::setReleaseCb(const std::function<void(uint8_t*)>& cb) noexcept
{
if (cb) {
releaseBufferCb_ = cb;
......
......@@ -188,8 +188,8 @@ DRING_PUBLIC std::vector<std::map<std::string, std::string>> getContacts(const s
/*
* Import/Export accounts
*/
DRING_PUBLIC int exportAccounts(std::vector<std::string> accountIDs, std::string filepath, std::string password);
DRING_PUBLIC int importAccounts(std::string archivePath, std::string password);
DRING_PUBLIC int exportAccounts(const std::vector<std::string>& accountIDs, const std::string& filepath, const std::string& password);
DRING_PUBLIC int importAccounts(const std::string& archivePath, const std::string& password);
/*
* Network connectivity
......
......@@ -139,8 +139,8 @@ public:
// Set internal pixel buffers on given memory buffer
// This buffer must follow given specifications.
void setFromMemory(uint8_t* data, int format, int width, int height) noexcept;
void setFromMemory(uint8_t* data, int format, int width, int height, std::function<void(uint8_t*)> cb) noexcept;
void setReleaseCb(std::function<void(uint8_t*)> cb) noexcept;
void setFromMemory(uint8_t* data, int format, int width, int height, const std::function<void(uint8_t*)>& cb) noexcept;
void setReleaseCb(const std::function<void(uint8_t*)>& cb) noexcept;
void noise();
......
......@@ -19,17 +19,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __MEDIA_CODEC_H__
#define __MEDIA_CODEC_H__
#pragma once
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "audio/audiobuffer.h" // for AudioFormat
#include <cctype>
#include "ip_utils.h"
#include <cctype>
#include <string>
#include <vector>
#include <map>
......@@ -286,4 +285,3 @@ struct MediaDescription {
};
}//namespace ring
#endif // __MEDIA_CODEC_H__
......@@ -393,7 +393,7 @@ RingAccount::newOutgoingCall(const std::string& toUrl,
}
void
RingAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::string toUri)
RingAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::string& toUri)
{
// TODO: for now, we automatically trust all explicitly called peers
setCertificateStatus(toUri, tls::TrustStore::PermissionStatus::ALLOWED);
......@@ -2368,7 +2368,7 @@ RingAccount::onTrustRequest(const dht::InfoHash& peer_account, const dht::InfoHa
}
void
RingAccount::onPeerMessage(const dht::InfoHash& peer_device, std::function<void(const std::shared_ptr<dht::crypto::Certificate>& crt, const dht::InfoHash& peer_account)> cb)
RingAccount::onPeerMessage(const dht::InfoHash& peer_device, std::function<void(const std::shared_ptr<dht::crypto::Certificate>& crt, const dht::InfoHash& peer_account)>&& cb)
{
// quick check in case we already explicilty banned this device
auto trustStatus = trust_.getCertificateStatus(peer_device.toString());
......@@ -2378,7 +2378,7 @@ RingAccount::onPeerMessage(const dht::InfoHash& peer_device, std::function<void(
}
findCertificate(peer_device,
[this, peer_device, cb](const std::shared_ptr<dht::crypto::Certificate>& cert) {
[this, peer_device, cb=std::move(cb)](const std::shared_ptr<dht::crypto::Certificate>& cert) {
dht::InfoHash peer_account_id;
if (not foundPeerDevice(cert, peer_account_id)) {
RING_WARN("[Account %s] Discarding message from invalid peer certificate %s.", getAccountID().c_str(), peer_device.toString().c_str());
......@@ -3339,9 +3339,8 @@ RingAccount::igdChanged()
void
RingAccount::forEachDevice(const dht::InfoHash& to,
std::function<void(const std::shared_ptr<RingAccount>&,
const dht::InfoHash&)> op,
std::function<void(const std::shared_ptr<RingAccount>&, bool)> end)
std::function<void(const std::shared_ptr<RingAccount>&, const dht::InfoHash&)>&& op,
std::function<void(const std::shared_ptr<RingAccount>&, bool)>&& end)
{
auto shared = std::static_pointer_cast<RingAccount>(shared_from_this());
auto treatedDevices = std::make_shared<std::set<dht::InfoHash>>();
......@@ -3349,13 +3348,13 @@ RingAccount::forEachDevice(const dht::InfoHash& to,
tls::CertificateStore::instance().pinRevocationList(to.toString(), std::move(crl));
return true;
});
dht_.get<DeviceAnnouncement>(to, [shared,to,treatedDevices,op](DeviceAnnouncement&& dev) {
dht_.get<DeviceAnnouncement>(to, [shared,to,treatedDevices,op=std::move(op)](DeviceAnnouncement&& dev) {
if (dev.from != to)
return true;
if (treatedDevices->emplace(dev.dev).second)
op(shared, dev.dev);
return true;
}, [=](bool /*ok*/){
}, [=, end=std::move(end)](bool /*ok*/){
RING_DBG("[Account %s] found %lu devices for %s",
getAccountID().c_str(), treatedDevices->size(), to.to_c_str());
if (end) end(shared, not treatedDevices->empty());
......@@ -3535,7 +3534,7 @@ RingAccount::publicAddresses()
void
RingAccount::requestPeerConnection(const std::string& peer_id, const DRing::DataTransferId& tid,
std::function<void(PeerConnection*)> connect_cb)
const std::function<void(PeerConnection*)>& connect_cb)
{
dhtPeerConnector_->requestConnection(peer_id, tid, connect_cb);
}
......
......@@ -344,7 +344,7 @@ class RingAccount : public SIPAccountBase {
/// /// \param[in] tid linked outgoing data transfer
///
void requestPeerConnection(const std::string& peer, const DRing::DataTransferId& tid,
std::function<void(PeerConnection*)> connect_cb);
const std::function<void(PeerConnection*)>& connect_cb);
///
/// Close a E2E connection between a given peer and a given transfer id.
......@@ -368,10 +368,8 @@ class RingAccount : public SIPAccountBase {
const std::shared_future<tls::DhParams> dhParams() const { return dhParams_; }
void forEachDevice(const dht::InfoHash& to,
std::function<void(const std::shared_ptr<RingAccount>&,
const dht::InfoHash&)> op,
std::function<void(const std::shared_ptr<RingAccount>&,
bool)> end = {});
std::function<void(const std::shared_ptr<RingAccount>&, const dht::InfoHash&)>&& op,
std::function<void(const std::shared_ptr<RingAccount>&, bool)>&& end = {});
/**
* Inform that a potential peer device have been found.
......@@ -450,7 +448,7 @@ class RingAccount : public SIPAccountBase {
const dht::ValueType USER_PROFILE_TYPE = {9, "User profile", std::chrono::hours(24 * 7)};
void startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::string toUri);
void startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::string& toUri);
void onConnectedOutgoingCall(SIPCall& call, const std::string& to_id, IpAddr target);
......@@ -489,7 +487,7 @@ class RingAccount : public SIPAccountBase {
* peer certificate chain (down to the peer device certificate),
* and the peer account id.
*/
void onPeerMessage(const dht::InfoHash& peer_device, std::function<void(const std::shared_ptr<dht::crypto::Certificate>& crt, const dht::InfoHash& account_id)>);
void onPeerMessage(const dht::InfoHash& peer_device, std::function<void(const std::shared_ptr<dht::crypto::Certificate>& crt, const dht::InfoHash& account_id)>&&);
void onTrustRequest(const dht::InfoHash& peer_account, const dht::InfoHash& peer_device, time_t received , bool confirm, std::vector<uint8_t>&& payload);
......
......@@ -252,7 +252,7 @@ Sdp::setMediaDescriptorLines(bool audio, bool holding, sip_utils::KeyExchangePro
if (kx == sip_utils::KeyExchangeProtocol::SDES) {
if (pjmedia_sdp_media_add_attr(med, generateSdesAttribute()) != PJ_SUCCESS)
SdpException("Could not add sdes attribute to media");
throw SdpException("Could not add sdes attribute to media");
}
return med;
......
......@@ -64,7 +64,7 @@ fetchHeaderValue(pjsip_msg *msg, const std::string &field)
std::string value(hdr->hvalue.ptr, hdr->hvalue.slen);
size_t pos = value.find("\n");
size_t pos = value.find('\n');
if (pos != std::string::npos)
return value.substr(0, pos);
......@@ -79,7 +79,7 @@ createRouteSet(const std::string &route, pj_pool_t *hdr_pool)
std::string host;
int port = 0;
size_t found = route.find(":");
size_t found = route.find(':');
if (found != std::string::npos) {
host = route.substr(0, found);
port = atoi(route.substr(found + 1, route.length() - found).c_str());
......@@ -140,16 +140,16 @@ stripSipUriPrefix(std::string& sipUri)
sipUri.erase(found, (sizeof SIP_PREFIX) - 1);
// URI may or may not be between brackets
found = sipUri.find("<");
found = sipUri.find('<');
if (found != std::string::npos)
sipUri.erase(found, 1);
found = sipUri.find("@");
found = sipUri.find('@');
if (found != std::string::npos)
sipUri.erase(found);
found = sipUri.find(">");
found = sipUri.find('>');
if (found != std::string::npos)
sipUri.erase(found, 1);
}
......@@ -158,11 +158,11 @@ std::string
getHostFromUri(const std::string& sipUri)
{
std::string hostname(sipUri);
size_t found = hostname.find("@");
size_t found = hostname.find('@');
if (found != std::string::npos)
hostname.erase(0, found+1);
found = hostname.find(">");
found = hostname.find('>');
if (found != std::string::npos)
hostname.erase(found, 1);
......
......@@ -1369,7 +1369,7 @@ std::string SIPAccount::getToUri(const std::string& username) const
scheme = "";
// Check if hostname is already specified
if (username.find("@") == std::string::npos)
if (username.find('@') == std::string::npos)
hostname = hostname_;
#if HAVE_IPV6
......
......@@ -393,7 +393,7 @@ protected:
struct UsedPort {
UsedPort() {};
UsedPort(UsedPort&& o) : port_(o.port_) {
UsedPort(UsedPort&& o) noexcept : port_(o.port_) {
o.port_ = 0;
}
UsedPort(in_port_t p) : port_(p) {
......@@ -404,7 +404,7 @@ protected:
if (port_)
releasePort(port_);
};
UsedPort& operator=(UsedPort&& o) {
UsedPort& operator=(UsedPort&& o) noexcept {
if (port_)
releasePort(port_);
port_ = o.port_;
......
......@@ -225,7 +225,7 @@ public: // NOT SIP RELATED (good candidates to be moved elsewhere)
peerRegistredName_ = name;
}
void setPeerUri(const std::string peerUri) { peerUri_ = peerUri; }
void setPeerUri(const std::string& peerUri) { peerUri_ = peerUri; }
bool initIceMediaTransport(bool master, unsigned channel_num=4);
......
......@@ -400,7 +400,7 @@ SIPPresence::send_publish(SIPPresence * pres)
SIPAccount * acc = pres->getAccount();
std::string contactWithAngles = acc->getFromUri();
contactWithAngles.erase(contactWithAngles.find('>'));
int semicolon = contactWithAngles.find_first_of(":");
int semicolon = contactWithAngles.find_first_of(':');
std::string contactWithoutAngles = contactWithAngles.substr(semicolon + 1);
// pj_str_t contact = pj_str(strdup(contactWithoutAngles.c_str()));
// pj_memcpy(&status_data.info[0].contact, &contt, sizeof(pj_str_t));;
......@@ -421,7 +421,7 @@ SIPPresence::send_publish(SIPPresence * pres)
char *epos = pj_strchr(&from, '>');
if (epos - bpos < 2) {
pj_assert(!"Unexpected invalid URI");
RING_ERR("Unexpected invalid URI");
status = PJSIP_EINVALIDURI;
goto on_error;
}
......
......@@ -55,7 +55,7 @@ struct SipTransportDescr
SipTransportDescr() {}
SipTransportDescr(pjsip_transport_type_e t)
: type(t), listenerPort(pjsip_transport_get_default_port_for_type(t)) {}
SipTransportDescr(pjsip_transport_type_e t, pj_uint16_t port, std::string i)
SipTransportDescr(pjsip_transport_type_e t, pj_uint16_t port, const std::string& i)
: type(t), listenerPort(port), interface(i) {}
static inline pjsip_transport_type_e actualType(pjsip_transport_type_e t) {
......
......@@ -487,7 +487,7 @@ SIPVoIPLink::getCachingPool() noexcept
SIPVoIPLink::SIPVoIPLink() : pool_(nullptr, pj_pool_release)
{
#define TRY(ret) do { \
if (ret != PJ_SUCCESS) \
if ((ret) != PJ_SUCCESS) \
throw VoipLinkException(#ret " failed"); \
} while (0)
......@@ -1154,7 +1154,7 @@ resolver_callback(pj_status_t status, void *token, const struct pjsip_server_add
}
void
SIPVoIPLink::resolveSrvName(const std::string &name, pjsip_transport_type_e type, SrvResolveCallback cb)
SIPVoIPLink::resolveSrvName(const std::string &name, pjsip_transport_type_e type, SrvResolveCallback&& cb)
{
// PJSIP limits hostname to be longer than PJ_MAX_HOSTNAME.
// But, resolver prefix the given name by a string like "_sip._udp."
......@@ -1189,11 +1189,11 @@ SIPVoIPLink::resolveSrvName(const std::string &name, pjsip_transport_type_e type
const auto token = std::hash<std::string>()(name + to_string(type));
getResolveCallbackMap().registerCallback(token,
[=](pj_status_t s, const pjsip_server_addresses* r) {
[=,cb=std::move(cb)](pj_status_t s, const pjsip_server_addresses* r) {
try {
if (s != PJ_SUCCESS || !r) {
RING_WARN("Can't resolve \"%s\" using pjsip_endpt_resolve, trying getaddrinfo.", name.c_str());
std::thread([=](){
std::thread([=,cb=std::move(cb)](){
auto ips = ip_utils::getAddrList(name.c_str());
runOnMainThread(std::bind(cb, ips.empty() ? std::vector<IpAddr>{} : std::move(ips)));
}).detach();
......
......@@ -22,8 +22,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef SIPVOIPLINK_H_
#define SIPVOIPLINK_H_
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
......@@ -108,7 +107,7 @@ class SIPVoIPLink {
std::unique_ptr<SipTransportBroker> sipTransportBroker;
typedef std::function<void(std::vector<IpAddr>)> SrvResolveCallback;
void resolveSrvName(const std::string &name, pjsip_transport_type_e type, SrvResolveCallback cb);
void resolveSrvName(const std::string &name, pjsip_transport_type_e type, SrvResolveCallback&& cb);
/**
* Guess the account related to an incoming SIP call.
......@@ -170,5 +169,3 @@ class SIPVoIPLink {
};
} // namespace ring
#endif // SIPVOIPLINK_H_
......@@ -842,7 +842,14 @@ UPnPContext::parseIGD(IXML_Document* doc, const UpnpDiscovery* d_event)
if (not (serviceId.empty() and controlURL.empty() and eventSubURL.empty()) ) {
/* RING_DBG("UPnP: got service info from device:\n\tserviceType: %s\n\tserviceID: %s\n\tcontrolURL: %s\n\teventSubURL: %s",
serviceType.c_str(), serviceId.c_str(), controlURL.c_str(), eventSubURL.c_str()); */
new_igd.reset(new UPnPIGD(UDN, baseURL, friendlyName, serviceType, serviceId, controlURL, eventSubURL));
new_igd.reset(new UPnPIGD(
std::move(UDN),
std::move(baseURL),
std::move(friendlyName),
std::move(serviceType),
std::move(serviceId),
std::move(controlURL),
std::move(eventSubURL)));
if (isIGDConnected(*new_igd)) {
new_igd->publicIp = getExternalIP(*new_igd);
if (new_igd->publicIp) {
......
......@@ -23,7 +23,7 @@
namespace ring { namespace upnp {
/* move constructor and operator */
Mapping::Mapping(Mapping&& other)
Mapping::Mapping(Mapping&& other) noexcept
: port_external_(other.port_external_)
, port_internal_(other.port_internal_)
, type_(other.type_)
......@@ -33,7 +33,7 @@ Mapping::Mapping(Mapping&& other)
other.port_internal_ = 0;
}
Mapping& Mapping::operator=(Mapping&& other)
Mapping& Mapping::operator=(Mapping&& other) noexcept
{
if (this != &other) {
port_external_ = other.port_external_;
......
......@@ -51,7 +51,7 @@ public:
uint16_t port_external = 0,
uint16_t port_internal = 0,
PortType type = PortType::UDP,
std::string description = UPNP_DEFAULT_MAPPING_DESCRIPTION)
const std::string& description = UPNP_DEFAULT_MAPPING_DESCRIPTION)
: port_external_(port_external)
, port_internal_(port_internal)
, type_(type)
......@@ -59,8 +59,8 @@ public:
{};
/* move constructor and operator */
Mapping(Mapping&&);
Mapping& operator=(Mapping&&);
Mapping(Mapping&&) noexcept;
Mapping& operator=(Mapping&&) noexcept;
~Mapping() = default;
......@@ -159,20 +159,20 @@ private:
class UPnPIGD : public IGD {
public:
UPnPIGD(std::string UDN,
std::string baseURL,
std::string friendlyName,
std::string serviceType,
std::string serviceId,
std::string controlURL,
std::string eventSubURL)
: UDN_(UDN)
, baseURL_(baseURL)
, friendlyName_(friendlyName)
, serviceType_(serviceType)
, serviceId_(serviceId)
, controlURL_(controlURL)
, eventSubURL_(eventSubURL)
UPnPIGD(std::string&& UDN,
std::string&& baseURL,
std::string&& friendlyName,
std::string&& serviceType,
std::string&& serviceId,
std::string&& controlURL,
std::string&& eventSubURL)
: UDN_(std::move(UDN))
, baseURL_(std::move(baseURL))
, friendlyName_(std::move(friendlyName))
, serviceType_(std::move(serviceType))
, serviceId_(std::move(serviceId))
, controlURL_(std::move(controlURL))
, eventSubURL_(std::move(eventSubURL))
{}
const std::string& getUDN() const { return UDN_; };
......
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