Skip to content

Commit

Permalink
Implement feedback from cppcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
flubshi committed Jun 25, 2024
1 parent 9972538 commit c30820b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Curl
void ResetHeaders();
virtual std::string GetCookie(const std::string& name);
void SetCookie(const std::string& host, const std::string& name, const std::string& value);
std::string GetLocation() { return m_location; }
const std::string& GetLocation() const { return m_location; }
void SetRedirectLimit(int limit) { m_redirectLimit = limit; }

private:
Expand Down
10 changes: 5 additions & 5 deletions src/JWT.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
class JWT
{
public:
JWT(std::string token);
JWT(){};
explicit JWT(std::string token);
explicit JWT(){};

bool isExpired(int offset = 0) const;

std::string getToken() { return strToken; };
int getExp() { return exp; };
bool isInitialized() { return initialized; };
const std::string& getToken() const { return strToken; };
int getExp() const { return exp; };
bool isInitialized() const { return initialized; };
rapidjson::Document parsedToken; // bad, I know..

private:
Expand Down
36 changes: 16 additions & 20 deletions src/WaipuData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,6 @@ bool WaipuData::RefreshDeviceCapabiltiesToken()

kodi::Log(ADDON_LOG_DEBUG, "[X-Device-Token] response: %s", jsonDeviceToken.c_str());

std::string deviceToken;

rapidjson::Document deviceTokenDoc;
deviceTokenDoc.Parse(jsonDeviceToken.c_str());
if (deviceTokenDoc.HasParseError())
Expand Down Expand Up @@ -693,7 +691,7 @@ PVR_ERROR WaipuData::GetBackendVersion(std::string& version)
return PVR_ERROR_NO_ERROR;
}

std::string WaipuData::GetLicense()
const std::string& WaipuData::GetLicense()
{
return m_license;
}
Expand Down Expand Up @@ -951,15 +949,16 @@ PVR_ERROR WaipuData::GetChannelStreamProperties(
{
// use hls where possible, fallback to dash
protocol = "dash";
for (const auto& thisChannel : m_channels)

std::vector<WaipuChannel>::iterator thisChannel =
std::find_if(m_channels.begin(), m_channels.end(),
[&](const WaipuChannel& v) { return v.iUniqueId == channel.GetUniqueId(); });

if (thisChannel != m_channels.end())
{
if (thisChannel.iUniqueId == channel.GetUniqueId())
if (m_hls_allowlist.contains(thisChannel->waipuID))
{
if (m_hls_allowlist.contains(thisChannel.waipuID))
{
protocol = "hls";
}
break;
protocol = "hls";
}
}
kodi::Log(ADDON_LOG_DEBUG, "protocol auto select: %s", protocol.c_str());
Expand Down Expand Up @@ -1073,8 +1072,8 @@ PVR_ERROR WaipuData::GetChannelGroupMembers(const kodi::addon::PVRChannelGroup&
{
if (group.GetIsRadio())
{
kodi::Log(ADDON_LOG_ERROR,
"[%s] ERROR: Function was called with a group having 'radio: true'", __FUNCTION__);
kodi::Log(ADDON_LOG_ERROR, "[%s] ERROR: Function was called with a group having 'radio: true'",
__FUNCTION__);
return PVR_ERROR_INVALID_PARAMETERS;
}

Expand Down Expand Up @@ -1295,7 +1294,6 @@ PVR_ERROR WaipuData::GetEPGForChannelNew(int channelUid,
std::transform(channelid.begin(), channelid.end(), channelid.begin(), ::tolower);

kodi::Log(ADDON_LOG_DEBUG, "[epg-new] channel: %s", channelid.c_str());
std::string endTime = Utils::TimeToString(end);

int limit = 32;

Expand Down Expand Up @@ -1520,7 +1518,6 @@ std::string WaipuData::GetEPGTagURL(const kodi::addon::PVREPGTag& tag, const std
// fallback to replay playback
kodi::Log(ADDON_LOG_DEBUG,
"[play epg tag] streamUrlProvider not found -> fallback to replay!");
std::string startTime = std::to_string(tag.GetStartTime());
return GetChannelStreamURL(tag.GetUniqueChannelId(), protocol, startTime);
}

Expand Down Expand Up @@ -1836,7 +1833,7 @@ PVR_ERROR WaipuData::DeleteRecording(const kodi::addon::PVRRecording& recording)
std::string request_data = "{\"ids\":[\"" + recording_id + "\"]}";
kodi::Log(ADDON_LOG_DEBUG, "[delete recording] req: %s;", request_data.c_str());
std::string deleted =
HttpDelete("https://recording.waipu.tv/api/recordings", request_data.c_str(),
HttpDelete("https://recording.waipu.tv/api/recordings", request_data,
{{"Content-Type", "application/vnd.waipu.pvr-recording-ids-v2+json"}});
kodi::Log(ADDON_LOG_DEBUG, "[delete recording] response: %s;", deleted.c_str());
kodi::addon::CInstancePVRClient::TriggerRecordingUpdate();
Expand Down Expand Up @@ -2047,7 +2044,7 @@ PVR_ERROR WaipuData::DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceD
std::string request_data = "{\"ids\":[\"" + std::to_string(timer_id) + "\"]}";
kodi::Log(ADDON_LOG_DEBUG, "[delete single timer] req: %s;", request_data.c_str());
std::string deleted =
HttpDelete("https://recording.waipu.tv/api/recordings", request_data.c_str(),
HttpDelete("https://recording.waipu.tv/api/recordings", request_data,
{{"Content-Type", "application/vnd.waipu.pvr-recording-ids-v2+json"}});
kodi::Log(ADDON_LOG_DEBUG, "[delete single timer] response: %s;", deleted.c_str());
kodi::QueueNotification(QUEUE_INFO, "Recording", "Recording Deleted");
Expand All @@ -2065,7 +2062,7 @@ PVR_ERROR WaipuData::DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceD
kodi::Log(ADDON_LOG_DEBUG, "[delete multi timer] req (group: %i): %s;", groupID,
request_data.c_str());
std::string deleted =
HttpPost("https://recording-scheduler.waipu.tv/api/delete-requests", request_data.c_str(),
HttpPost("https://recording-scheduler.waipu.tv/api/delete-requests", request_data,
{{"Content-Type",
"application/vnd.waipu.recording-scheduler-delete-serial-recordings-v1+json"}});
kodi::Log(ADDON_LOG_DEBUG, "[delete multi timer] response: %s;", deleted.c_str());
Expand Down Expand Up @@ -2162,7 +2159,7 @@ PVR_ERROR WaipuData::GetDriveSpace(uint64_t& total, uint64_t& used)
if (!IsConnected())
return PVR_ERROR_SERVER_ERROR;

total = m_account_hours_recording * 1024 * 1024;
total = m_account_hours_recording * 1024l * 1024l;
used = m_finishedRecordingsSeconds > 0 ? m_finishedRecordingsSeconds * 1024 * 1024 / 3600 : 0;

return PVR_ERROR_NO_ERROR;
Expand Down Expand Up @@ -2224,8 +2221,7 @@ PVR_ERROR WaipuData::SetRecordingLastPlayedPosition(const kodi::addon::PVRRecord
std::string request_data = "{\"position\":" + std::to_string(lastplayedposition) + "}";
std::string response = HttpRequest(
"PUT", "https://stream-position.waipu.tv/api/stream-positions/" + recording.GetRecordingId(),
request_data.c_str(),
{{"Content-Type", "application/vnd.waipu.stream-position-request.v1+json"}});
request_data, {{"Content-Type", "application/vnd.waipu.stream-position-request.v1+json"}});
kodi::Log(ADDON_LOG_DEBUG, "%s - Response: %s", __FUNCTION__, response.c_str());

return PVR_ERROR_NO_ERROR;
Expand Down
6 changes: 3 additions & 3 deletions src/WaipuData.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ATTR_DLL_LOCAL WaipuData : public kodi::addon::CAddonBase,
std::string m_userhandle = "";
std::string m_protocol;
std::string m_device_id;
WAIPU_PROVIDER m_provider;
WAIPU_PROVIDER m_provider = WAIPU_PROVIDER_WAIPU;

std::vector<WaipuChannel> m_channels;
std::vector<WaipuChannelGroup> m_channelGroups;
Expand Down Expand Up @@ -188,15 +188,15 @@ class ATTR_DLL_LOCAL WaipuData : public kodi::addon::CAddonBase,
void ReadSettings();
bool ParseAccessToken();

void AddTimerType(std::vector<kodi::addon::PVRTimerType>& types, int idx, int attributes);
void AddTimerType(std::vector<kodi::addon::PVRTimerType>& types, int id, int attributes);

std::string GetChannelStreamURL(int uniqueId,
const std::string& protocol,
const std::string& startTime);
std::string GetRecordingURL(const kodi::addon::PVRRecording& recording,
const std::string& protocol);
std::string GetEPGTagURL(const kodi::addon::PVREPGTag& tag, const std::string& protocol);
std::string GetLicense();
const std::string& GetLicense();
const std::map<std::string, std::string> GetOAuthDeviceCode(const std::string& tenant);
const std::map<std::string, std::string> CheckOAuthState(const std::string& device_code);
void SetStreamProperties(std::vector<kodi::addon::PVRStreamProperty>& properties,
Expand Down

0 comments on commit c30820b

Please sign in to comment.