This commit is contained in:
badaix 2021-02-10 18:36:40 +01:00
parent 1aa8831416
commit f5d4fcaf43
34 changed files with 274 additions and 273 deletions

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -38,7 +38,7 @@ string hex2str(string input)
using byte = unsigned char;
unsigned long x = strtoul(input.c_str(), nullptr, 16);
byte a[] = {byte(x >> 24), byte(x >> 16), byte(x >> 8), byte(x), 0};
return string((char*)a);
return string(reinterpret_cast<char*>(a));
}
} // namespace
@ -92,7 +92,7 @@ int AirplayStream::parse(string line)
{
enum XML_Status result;
if ((result = XML_Parse(parser_, line.c_str(), line.length(), false)) == XML_STATUS_ERROR)
if ((result = XML_Parse(parser_, line.c_str(), line.length(), 0)) == XML_STATUS_ERROR)
{
XML_ParserFree(parser_);
createParser();
@ -288,10 +288,10 @@ void AirplayStream::initExeAndPath(const string& filename)
throw SnapException("shairport-sync not found");
}
if (exe_.find("/") != string::npos)
if (exe_.find('/') != string::npos)
{
path_ = exe_.substr(0, exe_.find_last_of("/") + 1);
exe_ = exe_.substr(exe_.find_last_of("/") + 1);
path_ = exe_.substr(0, exe_.find_last_of('/') + 1);
exe_ = exe_.substr(exe_.find_last_of('/') + 1);
}
}
@ -317,14 +317,14 @@ void AirplayStream::onStderrMsg(const std::string& line)
#ifdef HAS_EXPAT
void XMLCALL AirplayStream::element_start(void* userdata, const char* element_name, const char** attr)
{
AirplayStream* self = (AirplayStream*)userdata;
auto* self = static_cast<AirplayStream*>(userdata);
string name(element_name);
self->buf_.assign("");
if (name == "item")
self->entry_.reset(new TageEntry);
for (int i = 0; attr[i]; i += 2)
for (int i = 0; attr[i] != nullptr; i += 2)
{
string name(attr[i]);
string value(attr[i + 1]);
@ -335,7 +335,7 @@ void XMLCALL AirplayStream::element_start(void* userdata, const char* element_na
void XMLCALL AirplayStream::element_end(void* userdata, const char* element_name)
{
AirplayStream* self = (AirplayStream*)userdata;
auto* self = static_cast<AirplayStream*>(userdata);
string name(element_name);
if (name == "code")
@ -361,8 +361,8 @@ void XMLCALL AirplayStream::element_end(void* userdata, const char* element_name
void XMLCALL AirplayStream::data(void* userdata, const char* content, int length)
{
AirplayStream* self = (AirplayStream*)userdata;
string value(content, (size_t)length);
auto* self = static_cast<AirplayStream*>(userdata);
string value(content, static_cast<size_t>(length));
self->buf_.append(value);
}

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -162,7 +162,7 @@ void AlsaStream::initAlsa()
void AlsaStream::uninitAlsa()
{
if (handle_)
if (handle_ != nullptr)
{
snd_pcm_close(handle_);
handle_ = nullptr;

View file

@ -33,7 +33,7 @@ static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
static inline bool is_base64(unsigned char c)
{
return (isalnum(c) || (c == '+') || (c == '/'));
return ((isalnum(c) != 0) || (c == '+') || (c == '/'));
}
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len)
@ -44,7 +44,7 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
unsigned char char_array_3[3];
unsigned char char_array_4[4];
while (in_len--)
while ((in_len--) != 0u)
{
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3)
@ -60,7 +60,7 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
}
}
if (i)
if (i != 0)
{
for (j = i; j < 3; j++)
char_array_3[j] = '\0';
@ -88,7 +88,7 @@ std::string base64_decode(std::string const& encoded_string)
unsigned char char_array_4[4], char_array_3[3];
std::string ret;
while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
while (((in_len--) != 0) && (encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
{
char_array_4[i++] = encoded_string[in_];
in_++;
@ -107,7 +107,7 @@ std::string base64_decode(std::string const& encoded_string)
}
}
if (i)
if (i != 0)
{
for (j = i; j < 4; j++)
char_array_4[j] = 0;

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -49,7 +49,7 @@ LibrespotStream::LibrespotStream(PcmListener* pcmListener, boost::asio::io_conte
killall_ = (uri_.getQuery("killall", "false") == "true");
if (username.empty() != password.empty())
throw SnapException("missing parameter \"username\" or \"password\" (must provide both, or neither)");
throw SnapException(R"(missing parameter "username" or "password" (must provide both, or neither))");
if (!params_.empty())
params_ += " ";
@ -90,10 +90,10 @@ void LibrespotStream::initExeAndPath(const std::string& filename)
throw SnapException("librespot not found");
}
if (exe_.find("/") != string::npos)
if (exe_.find('/') != string::npos)
{
path_ = exe_.substr(0, exe_.find_last_of("/") + 1);
exe_ = exe_.substr(exe_.find_last_of("/") + 1);
path_ = exe_.substr(0, exe_.find_last_of('/') + 1);
exe_ = exe_.substr(exe_.find_last_of('/') + 1);
}
if (killall_)
@ -149,7 +149,7 @@ void LibrespotStream::onStderrMsg(const std::string& line)
{
LOG(INFO, LOG_TAG) << "metadata: <" << m[1] << ">\n";
json jtag = {{"TITLE", (string)m[1]}};
json jtag = {{"TITLE", string(m[1])}};
setMeta(jtag);
}
}

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -130,7 +130,7 @@ void PcmStream::setState(ReaderState newState)
state_ = newState;
for (auto* listener : pcmListeners_)
{
if (listener)
if (listener != nullptr)
listener->onStateChanged(this, newState);
}
}
@ -154,7 +154,7 @@ void PcmStream::chunkEncoded(const encoder::Encoder& encoder, std::shared_ptr<ms
tvEncodedChunk_ += std::chrono::nanoseconds(static_cast<std::chrono::nanoseconds::rep>(duration * 1000000));
for (auto* listener : pcmListeners_)
{
if (listener)
if (listener != nullptr)
listener->onChunkEncoded(this, chunk, duration);
}
}
@ -164,7 +164,7 @@ void PcmStream::chunkRead(const msg::PcmChunk& chunk)
{
for (auto* listener : pcmListeners_)
{
if (listener)
if (listener != nullptr)
listener->onChunkRead(this, chunk);
}
encoder_->encode(chunk);
@ -175,7 +175,7 @@ void PcmStream::resync(const std::chrono::nanoseconds& duration)
{
for (auto* listener : pcmListeners_)
{
if (listener)
if (listener != nullptr)
listener->onResync(this, duration.count() / 1000000.);
}
}
@ -225,7 +225,7 @@ void PcmStream::setMeta(const json& jtag)
// Trigger a stream update
for (auto* listener : pcmListeners_)
{
if (listener)
if (listener != nullptr)
listener->onMetaChanged(this);
}
}

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -43,7 +43,7 @@ PipeStream::PipeStream(PcmListener* pcmListener, boost::asio::io_context& ioc, c
LOG(INFO, LOG_TAG) << "PipeStream mode: " << mode << "\n";
if ((mode != "read") && (mode != "create"))
throw SnapException("create mode for fifo must be \"read\" or \"create\"");
throw SnapException(R"(create mode for fifo must be "read" or "create")");
if (mode == "create")
{

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,8 +22,8 @@
#include "common/snap_exception.hpp"
#include "common/utils.hpp"
#include "common/utils/string_utils.hpp"
#include <climits>
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
@ -58,8 +58,8 @@ std::string ProcessStream::findExe(const std::string& filename) const
return filename;
std::string exe = filename;
if (exe.find("/") != string::npos)
exe = exe.substr(exe.find_last_of("/") + 1);
if (exe.find('/') != string::npos)
exe = exe.substr(exe.find_last_of('/') + 1);
/// check with "which"
string which = execGetOutput("which " + exe);
@ -85,10 +85,10 @@ void ProcessStream::initExeAndPath(const std::string& filename)
{
path_ = "";
exe_ = findExe(filename);
if (exe_.find("/") != string::npos)
if (exe_.find('/') != string::npos)
{
path_ = exe_.substr(0, exe_.find_last_of("/") + 1);
exe_ = exe_.substr(exe_.find_last_of("/") + 1);
path_ = exe_.substr(0, exe_.find_last_of('/') + 1);
exe_ = exe_.substr(exe_.find_last_of('/') + 1);
}
if (!fileExists(path_ + exe_))

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -202,7 +202,7 @@ void StreamManager::stop()
json StreamManager::toJson() const
{
json result = json::array();
for (auto stream : streams_)
for (const auto& stream : streams_)
if (stream->getCodec() != "null")
result.push_back(stream->toJson());
return result;