GCC Code Coverage Report


Directory: ./
File: playlist/PlaylistEntryURL.cpp
Date: 2026-10-29 08:11:58
Exec Total Coverage
Lines: 43 55 78.2%
Functions: 7 9 77.8%
Branches: 40 92 43.5%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-2022 by the Falcon Player Developers.
4 *
5 * The Falcon Player (FPP) is free software, and is covered under
6 * multiple Open Source licenses. Please see the included 'LICENSES'
7 * file for descriptions of what files are covered by each license.
8 *
9 * This source file is covered under the LGPL v2.1 as described in the
10 * included LICENSE.LGPL file.
11 */
12
13 #include "fpp-pch.h"
14
15 #include "fpp-json.h"
16
17 #include "Warnings.h" // WarningHolder -- needed directly for NOPCH builds
18
19 #include "../CurlManager.h"
20 #include "../log.h"
21
22 #include "PlaylistEntryURL.h"
23
24 /*
25 *
26 */
27 20 PlaylistEntryURL::PlaylistEntryURL(Playlist* playlist, PlaylistEntryBase* parent) :
28 20 PlaylistEntryBase(playlist, parent) {
29
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 LogDebug(VB_PLAYLIST, "PlaylistEntryURL::PlaylistEntryURL()\n");
30
31
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 m_type = "url";
32 20 }
33
34 /*
35 *
36 */
37 76 PlaylistEntryURL::~PlaylistEntryURL() {
38 76 }
39
40 /*
41 *
42 */
43 20 int PlaylistEntryURL::Init(Json::Value& config) {
44 20 LogDebug(VB_PLAYLIST, "PlaylistEntryURL::Init()\n");
45
46
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 m_method = config["method"].asString();
47
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 m_url = config["url"].asString();
48
49
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (config.isMember("data"))
50
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 m_data = config["data"].asString();
51
52 20 return PlaylistEntryBase::Init(config);
53 }
54
55 /*
56 *
57 */
58 16 int PlaylistEntryURL::StartPlaying(void) {
59
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 LogDebug(VB_PLAYLIST, "PlaylistEntryURL::StartPlaying()\n");
60
61
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
16 if (!CanPlay()) {
62 ✗ FinishPlay();
63 ✗ return 0;
64 }
65
66
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 std::string repURL = ReplaceMatches(m_url);
67 16 std::string repData;
68
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 13 times.
16 if (m_data.size())
69
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 repData = ReplaceMatches(m_data);
70
71
3/10
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
16 std::string method = m_method.empty() ? "GET" : m_method;
72
73 // Fire-and-forget: the entry does not use the response and finishes the
74 // moment the request is dispatched, so the request runs asynchronously
75 // through CurlManager (pumped by the main loop) rather than blocking the
76 // show for up to the request timeout on the main thread. The callback
77 // captures only the URL string by value, never `this`, so it is safe even
78 // if this entry has been destroyed by the time the request completes.
79
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 std::string urlForLog = repURL;
80
4/8
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
64 CurlManager::INSTANCE.add(
81 repURL, method, repData, {},
82
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
32 [urlForLog](int rc, const std::string& resp) {
83
2/4
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
15 if (rc < 200 || rc >= 300) {
84 ✗ LogErr(VB_PLAYLIST, "Playlist URL request failed (%s): rc=%d\n", urlForLog.c_str(), rc);
85 ✗ WarningHolder::AddWarningTimeout(60, 32, "Playlist URL request failed (" + urlForLog + ")");
86 } else {
87 15 LogDebug(VB_PLAYLIST, "Playlist URL response (%s): %s\n", urlForLog.c_str(), resp.c_str());
88 }
89 15 },
90 "PlaylistEntryURL");
91
92
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 PlaylistEntryBase::StartPlaying();
93
94
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 FinishPlay();
95
96 16 return 1;
97 16 }
98
99 /*
100 *
101 */
102 ✗ int PlaylistEntryURL::Stop(void) {
103 ✗ LogDebug(VB_PLAYLIST, "PlaylistEntryURL::Stop()\n");
104 ✗ return PlaylistEntryBase::Stop();
105 }
106
107 /*
108 *
109 */
110 19 std::string PlaylistEntryURL::ReplaceMatches(std::string in) {
111
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 std::string out = in;
112
113
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 LogDebug(VB_PLAYLIST, "In: '%s'\n", in.c_str());
114
115
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 LogDebug(VB_PLAYLIST, "Out: '%s'\n", out.c_str());
116
117
2/4
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
57 return PlaylistEntryBase::ReplaceMatches(out);
118 19 }
119
120 /*
121 *
122 */
123 ✗ void PlaylistEntryURL::Dump(void) {
124 ✗ LogDebug(VB_PLAYLIST, "URL : %s\n", m_method.c_str());
125 ✗ LogDebug(VB_PLAYLIST, "Method : %s\n", m_url.c_str());
126 ✗ }
127
128 /*
129 *
130 */
131 32 Json::Value PlaylistEntryURL::GetConfig(void) {
132 32 Json::Value result = PlaylistEntryBase::GetConfig();
133
134
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 result["url"] = m_url;
135
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 result["method"] = m_method;
136
137 32 return result;
138 ✗ }
139