GCC Code Coverage Report


Directory: ./
File: httpAPI.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 892 989 90.2%
Functions: 79 82 96.3%
Branches: 1491 2993 49.8%

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 drogon framework header before FPP headers to avoid
14 // macro conflicts between trantor's LOG_* macros and FPP's LogLevel enum
15 #include <drogon/HttpAppFramework.h>
16 #include <drogon/version.h>
17 #undef LOG_WARN
18 #undef LOG_INFO
19 #undef LOG_DEBUG
20
21 #include "fpp-pch.h"
22
23 #include "fpp-json.h"
24 #include "fpphttp.h" // drogon/HTTP helpers used here; no longer pulled transitively (see fpphttp_types.h)
25 #include "fpphttp_clientip.h" // getEffectiveClientIP() - FPP-internal, not in the plugin API
26 #include "StatusWebSocket.h"
27 #include <atomic>
28 #include <fcntl.h>
29 #include <signal.h>
30
31 // Defined in fppd.cpp; setting it to 0 breaks the main loop and triggers
32 // FPP's normal shutdown sequence, same as SIGQUIT or a graceful stop.
33 extern std::atomic_int runMainFPPDLoop;
34 extern std::atomic_int fppdStopSignalled;
35
36 #ifdef PLATFORM_OSX
37 #include <sys/sysctl.h>
38 #else
39 #include <sys/ioctl.h>
40 #include <sys/sysinfo.h>
41 #endif
42
43 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <arpa/inet.h>
46
47 #include <cstdlib>
48 #include <ctime>
49 #include <cxxabi.h>
50 #include <iomanip>
51 #include <iostream>
52 #include <list>
53 #include <stdint.h>
54 #include <string>
55 #include <unistd.h>
56 #include <vector>
57
58 #include "MultiSync.h"
59 #include "OutputMonitor.h"
60 #include "mediaoutput/VideoInputManager.h"
61 #include "RecurringTasks.h"
62 #include "Player.h"
63 #include "Plugins.h"
64 #include "Timers.h"
65
66 #include <chrono>
67 #include <condition_variable>
68 #include <future>
69 #include <memory>
70 #include <mutex>
71 #include <trantor/net/EventLoop.h>
72 #include "Scheduler.h"
73 #include "Sequence.h"
74 #include "Variables.h"
75 #include "Warnings.h"
76 #include "common.h"
77 #include "e131bridge.h"
78 #include "effects.h"
79 #include "fppversion.h"
80 #include "gpio.h"
81 #include "log.h"
82 #include "mqtt.h"
83 #include "settings.h"
84 #include "channeloutput/ChannelOutputSetup.h"
85 #include "channeloutput/channeloutputthread.h"
86 #include "channeltester/ChannelTester.h"
87 #include "commands/Commands.h"
88 #include "commands/Condition.h"
89 #include "mediaoutput/AES67Manager.h"
90 #include "mediaoutput/AudioSourceRegistry.h"
91 #include "mediaoutput/AudioLevelMonitor.h"
92 #include "mediaoutput/MediaOutputBase.h"
93 #include "mediaoutput/MediaOutputStatus.h"
94 #include "mediaoutput/OpusRTPManager.h"
95 #include "mediaoutput/RTSPOutputManager.h"
96 #include "mediaoutput/StreamSlotManager.h"
97 #include "mediaoutput/mediaoutput.h"
98 #include "overlays/PixelOverlay.h"
99 #include "playlist/Playlist.h"
100 #include "sensors/Sensors.h"
101
102 #include "httpAPI.h"
103
104 // Monotonic, so the reported uptime survives a wall-clock step (NTP, an RTC
105 // that boots in the past) instead of going negative or jumping by hours.
106 static long long startupTimeMS = GetMonotonicTimeMS();
107
108 // Trantor aborts fppd if a listener can't be bound, so only ask drogon to
109 // listen on [::1] when that address is actually bindable. A kernel built
110 // without IPv6 fails socket() with EAFNOSUPPORT; one with IPv6 disabled
111 // (ipv6.disable=1, or disable_ipv6 on lo) has no ::1 and fails bind() with
112 // EADDRNOTAVAIL. Port 0 keeps the probe from touching the real port.
113 2649 static bool canBindIPv6Loopback() {
114 2649 int fd = socket(AF_INET6, SOCK_STREAM, 0);
115
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2648 times.
2649 if (fd < 0) {
116
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogInfo(VB_HTTP, "IPv6 unavailable (%s); HTTP API listening on IPv4 loopback only\n", strerror(errno));
117 1 return false;
118 }
119 2648 int on = 1;
120 2648 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
121 2648 struct sockaddr_in6 addr = {};
122 2648 addr.sin6_family = AF_INET6;
123 2648 addr.sin6_addr = in6addr_loopback;
124 2648 addr.sin6_port = 0;
125 2648 bool ok = bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0;
126
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2647 times.
2648 if (!ok) {
127
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogInfo(VB_HTTP, "Cannot bind [::1] (%s); HTTP API listening on IPv4 loopback only\n", strerror(errno));
128 }
129
1/2
✓ Branch 0 taken 2648 times.
✗ Branch 1 not taken.
2648 close(fd);
130 2648 return ok;
131 }
132 // Read by status requests on the HTTP threads, written by periodicWork() on
133 // the main loop.
134 static std::atomic<bool> piPowerBad{ false };
135
136 /*
137 * The status payload is polled by every open page, fppoled, remotes and MQTT,
138 * and some callers poll several times a second for the playback position. The
139 * parts that cost the most change slowly: the sensors (bus reads, over half of
140 * a build), the identity settings, and the clock strings. Those are cached
141 * here; everything that moves within a second (player, playlist and media
142 * position, slots, status, warnings) is built fresh on every call.
143 */
144 static std::mutex statusCacheLock;
145 // Identity and sensors, rebuilt at most once a second.
146 static Json::Value statusSlowCache;
147 static long long statusSlowBuiltMS = 0;
148 // Clock strings and fppd's uptime, rebuilt when the wall-clock second or the
149 // uptime second changes -- never stale at the resolution they report.
150 static Json::Value statusClockCache;
151 static time_t statusClockWallSec = 0;
152 static long long statusClockUptimeSec = -1;
153
154 5844 static void BuildSlowStatus(Json::Value& result) {
155
4/8
✓ Branch 0 taken 2645 times.
✓ Branch 1 taken 3199 times.
✓ Branch 2 taken 2645 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2645 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
5844 static std::string host_name = getSetting("HostName");
156
5/10
✓ Branch 0 taken 2645 times.
✓ Branch 1 taken 3199 times.
✓ Branch 2 taken 2645 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2645 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2645 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
11134 static std::string fpp_version = getFPPVersion();
157
5/10
✓ Branch 0 taken 2645 times.
✓ Branch 1 taken 3199 times.
✓ Branch 2 taken 2645 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2645 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2645 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
11134 static std::string fppd_branch = getFPPBranch();
158
4/8
✓ Branch 0 taken 2645 times.
✓ Branch 1 taken 3199 times.
✓ Branch 2 taken 2645 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2645 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
5844 static std::string platform = getPlatform();
159
160
2/4
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
5844 result["version"] = fpp_version;
161
2/4
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
5844 result["branch"] = fppd_branch;
162
2/4
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
5844 result["platform"] = platform;
163
3/6
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5844 times.
✗ Branch 5 not taken.
5844 result["uuid"] = getSetting("SystemUUID");
164
2/4
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
5844 result["host_name"] = host_name;
165
3/6
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5844 times.
✗ Branch 5 not taken.
5844 result["host_description"] = getSetting("HostDescription");
166
3/6
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5844 times.
✗ Branch 5 not taken.
5844 result["mode"] = getFPPmode();
167
5/10
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5844 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5844 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5844 times.
✗ Branch 9 not taken.
5844 result["mode_name"] = toStdStringAndFree(modeToString(getFPPmode()));
168
2/4
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
5844 result["multisync"] = multiSync->isMultiSyncEnabled();
169
3/6
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5844 times.
✗ Branch 5 not taken.
5844 result["channelInputsEnabled"] = InputsEnabled();
170
3/6
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5844 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5844 times.
✗ Branch 5 not taken.
5844 result["channelOutputsEnabled"] = HasUniverseOutputs();
171 5844 Sensors::INSTANCE.reportSensors(result);
172 5844 }
173
174 7289 static void BuildClockStatus(Json::Value& result, time_t t, int totalseconds) {
175 struct tm tm;
176 7289 localtime_r(&t, &tm);
177
1/2
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
7289 std::stringstream sstr;
178
1/2
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
7289 sstr << std::put_time(&tm, "%a %b %d %H:%M:%S %Z %Y");
179
3/6
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7289 times.
✗ Branch 5 not taken.
7289 result["time"] = sstr.str();
180
181
1/2
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
7289 std::string fmt = getSetting("TimeFormat");
182
3/6
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7289 times.
✗ Branch 5 not taken.
27825 replaceAll(fmt, "%M", "%M:%S");
183
4/8
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7289 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7289 times.
✗ Branch 7 not taken.
8620 result["timeStrFull"] = GetTimeStr(fmt.c_str());
184
4/8
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7289 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7289 times.
✗ Branch 7 not taken.
7289 result["timeStr"] = GetTimeStr(getSetting("TimeFormat"));
185
4/8
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7289 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7289 times.
✗ Branch 7 not taken.
7289 result["dateStr"] = GetDateStr(getSetting("DateFormat"));
186
187 // FPPD process uptime (time since fppd started)
188 7289 int days = totalseconds / 86400;
189 7289 int hours = (totalseconds % 86400) / 3600;
190 7289 int minutes = (totalseconds % 3600) / 60;
191 7289 int seconds = totalseconds % 60;
192
193
3/6
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7289 times.
✗ Branch 5 not taken.
7289 result["uptime"] = secondsToTime(totalseconds);
194
2/4
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
7289 result["uptimeTotalSeconds"] = totalseconds;
195
2/4
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
7289 result["uptimeSeconds"] = seconds;
196
2/4
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
7289 result["uptimeMinutes"] = minutes;
197
2/4
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
7289 result["uptimeHours"] = hours;
198
2/4
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
7289 result["uptimeDays"] = days;
199
200
1/2
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
7289 std::stringstream totalTime;
201
8/16
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7289 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7289 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7289 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 7289 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7289 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 7289 times.
✗ Branch 15 not taken.
7289 totalTime << days << " days, " << hours << " hours, " << minutes << " minutes, " << seconds << " seconds";
202
3/6
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7289 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7289 times.
✗ Branch 5 not taken.
7289 result["uptimeStr"] = totalTime.str();
203 7289 }
204
205 273338 static void MergeStatus(Json::Value& result, const Json::Value& from) {
206
5/8
✓ Branch 0 taken 273338 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3282219 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3282219 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3008881 times.
✓ Branch 7 taken 273338 times.
3282219 for (auto it = from.begin(); it != from.end(); ++it) {
207
5/10
✓ Branch 0 taken 3008881 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3008881 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3008881 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3008881 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3008881 times.
✗ Branch 9 not taken.
3008881 result[it.name()] = *it;
208 }
209 273338 }
210
211 /*
212 Build a Status JSON String
213 */
214 136669 void GetCurrentFPPDStatus(Json::Value& result) {
215 {
216 // Built under the lock so concurrent pollers share one sensor read
217 // rather than each doing their own.
218
1/2
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
136669 std::lock_guard<std::mutex> lk(statusCacheLock);
219
1/2
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
136669 long long nowMS = GetMonotonicTimeMS();
220
7/8
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 134024 times.
✓ Branch 3 taken 2645 times.
✓ Branch 4 taken 3199 times.
✓ Branch 5 taken 130825 times.
✓ Branch 6 taken 5844 times.
✓ Branch 7 taken 130825 times.
136669 if (statusSlowCache.isNull() || nowMS - statusSlowBuiltMS >= 1000) {
221
1/2
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
5844 Json::Value slow;
222
1/2
✓ Branch 0 taken 5844 times.
✗ Branch 1 not taken.
5844 BuildSlowStatus(slow);
223 5844 statusSlowCache = std::move(slow);
224 5844 statusSlowBuiltMS = nowMS;
225 5844 }
226 136669 time_t wallSec = std::time(nullptr);
227 136669 long long uptimeSec = (nowMS - startupTimeMS) / 1000;
228
4/4
✓ Branch 0 taken 130620 times.
✓ Branch 1 taken 6049 times.
✓ Branch 2 taken 1240 times.
✓ Branch 3 taken 129380 times.
136669 if (wallSec != statusClockWallSec || uptimeSec != statusClockUptimeSec) {
229
1/2
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
7289 Json::Value clock;
230
1/2
✓ Branch 0 taken 7289 times.
✗ Branch 1 not taken.
7289 BuildClockStatus(clock, wallSec, (int)uptimeSec);
231 7289 statusClockCache = std::move(clock);
232 7289 statusClockWallSec = wallSec;
233 7289 statusClockUptimeSec = uptimeSec;
234 7289 }
235
1/2
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
136669 MergeStatus(result, statusSlowCache);
236
1/2
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
136669 MergeStatus(result, statusClockCache);
237 136669 }
238
239 // System uptime: one syscall, so read on every build rather than cached.
240 136669 int systemUptimeSecs = 0;
241 #ifdef PLATFORM_OSX
242 struct timeval boot;
243 struct timeval now;
244 int mib[] = { CTL_KERN, KERN_BOOTTIME };
245 size_t size = sizeof(boot);
246 if (sysctl(mib, 2, &boot, &size, 0, 0) == 0 && gettimeofday(&now, 0) == 0) {
247 systemUptimeSecs = (int)(now.tv_sec - boot.tv_sec);
248 }
249 #else
250 struct sysinfo sysInf;
251
1/2
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
136669 if (sysinfo(&sysInf) == 0) {
252 136669 systemUptimeSecs = (int)sysInf.uptime;
253 }
254 #endif
255
2/4
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136669 times.
✗ Branch 3 not taken.
136669 result["systemUptimeTotalSeconds"] = systemUptimeSecs;
256
257
1/2
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
136669 int mode = getFPPmode();
258
2/4
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136669 times.
✗ Branch 3 not taken.
136669 result["fppd"] = "running";
259
3/6
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136669 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 136669 times.
✗ Branch 5 not taken.
136669 result["status"] = Player::INSTANCE.GetStatus();
260
3/6
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136669 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 136669 times.
✗ Branch 5 not taken.
136669 result["bridging"] = HasBridgeData();
261
2/4
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136669 times.
✗ Branch 3 not taken.
136669 result["powerBad"] = piPowerBad.load();
262
263
3/4
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 562 times.
✓ Branch 3 taken 136107 times.
136669 if (ChannelTester::INSTANCE.Testing()) {
264
2/4
✓ Branch 0 taken 562 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 562 times.
✗ Branch 3 not taken.
562 result["status_name"] = "testing";
265 // Which test is running (same shape as GET api/testmode, minus any
266 // per-output "config" blob). Pushed over the status WebSocket, so
267 // every open page can track a test started or stopped elsewhere.
268
1/2
✓ Branch 0 taken 562 times.
✗ Branch 1 not taken.
562 Json::Value tm = ChannelTester::INSTANCE.GetStatusJson();
269
2/4
✓ Branch 0 taken 562 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 562 times.
✗ Branch 3 not taken.
562 if (!tm.isNull())
270
2/4
✓ Branch 0 taken 562 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 562 times.
✗ Branch 3 not taken.
562 result["testMode"] = tm;
271 562 } else {
272
8/11
✓ Branch 0 taken 136107 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136107 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59014 times.
✓ Branch 5 taken 71008 times.
✓ Branch 6 taken 161 times.
✓ Branch 7 taken 48 times.
✓ Branch 8 taken 85 times.
✓ Branch 9 taken 5791 times.
✗ Branch 10 not taken.
136107 switch (result["status"].asInt()) {
273 59014 case FPP_STATUS_IDLE:
274
2/4
✓ Branch 0 taken 59014 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59014 times.
✗ Branch 3 not taken.
59014 result["status_name"] = "idle";
275 59014 break;
276 71008 case FPP_STATUS_PLAYLIST_PLAYING:
277
2/4
✓ Branch 0 taken 71008 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71008 times.
✗ Branch 3 not taken.
71008 result["status_name"] = "playing";
278 71008 break;
279 161 case FPP_STATUS_STOPPING_GRACEFULLY:
280
2/4
✓ Branch 0 taken 161 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 161 times.
✗ Branch 3 not taken.
161 result["status_name"] = "stopping gracefully";
281 161 break;
282 48 case FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP:
283
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
48 result["status_name"] = "stopping gracefully after loop";
284 48 break;
285 85 case FPP_STATUS_STOPPING_NOW:
286
2/4
✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
✗ Branch 3 not taken.
85 result["status_name"] = "stopping now";
287 85 break;
288 5791 case FPP_STATUS_PLAYLIST_PAUSED:
289
2/4
✓ Branch 0 taken 5791 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5791 times.
✗ Branch 3 not taken.
5791 result["status_name"] = "paused";
290 5791 break;
291 ✗ default:
292 ✗ result["status_name"] = "unknown";
293 }
294 }
295
296
3/6
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136669 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 136669 times.
✗ Branch 5 not taken.
136669 result["volume"] = getVolume();
297
298
3/4
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19433 times.
✓ Branch 3 taken 136669 times.
156102 for (auto& warn : WarningHolder::GetWarnings()) {
299
3/6
✓ Branch 0 taken 19433 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19433 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19433 times.
✗ Branch 5 not taken.
19433 result["warnings"].append(warn.message());
300
3/6
✓ Branch 0 taken 19433 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19433 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19433 times.
✗ Branch 5 not taken.
19433 result["warningInfo"].append(warn.toJsonValue());
301 136669 }
302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136669 times.
136669 if (mode == 1) {
303 // bridge mode only returns the base information
304 ✗ return;
305 }
306
307 // MQTT
308
3/6
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136669 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 136669 times.
✗ Branch 5 not taken.
136669 result["MQTT"]["configured"] = false;
309
3/6
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136669 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 136669 times.
✗ Branch 5 not taken.
136669 result["MQTT"]["connected"] = false;
310
2/2
✓ Branch 0 taken 9288 times.
✓ Branch 1 taken 127381 times.
136669 if (mqtt) {
311
3/6
✓ Branch 0 taken 9288 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9288 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9288 times.
✗ Branch 5 not taken.
9288 result["MQTT"]["configured"] = true;
312
4/8
✓ Branch 0 taken 9288 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9288 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9288 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9288 times.
✗ Branch 7 not taken.
9288 result["MQTT"]["connected"] = mqtt->IsConnected();
313 }
314
315
3/4
✓ Branch 0 taken 136669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✓ Branch 3 taken 112228 times.
136669 if (getFPPmode() == REMOTE_MODE) {
316 24441 int secsElapsed = 0;
317 24441 int secsRemaining = 0;
318 24441 std::string seqFilename;
319 24441 std::string mediaFilename;
320
3/4
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 24433 times.
24441 if (sequence->IsSequenceRunning()) {
321
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 seqFilename = sequence->GetSeqFilenameCopy();
322 8 secsElapsed = sequence->m_seqMSElapsed / 1000;
323 8 secsRemaining = sequence->m_seqMSRemaining / 1000;
324 }
325 {
326 // CloseMediaOutput() deletes mediaOutput under mediaOutputLock at
327 // every media transition, and this status build runs on the HTTP
328 // threads, the drogon status-push timer and the warning notify
329 // thread. Copy the fields out under the lock rather than reading
330 // through the raw pointer while building the JSON. Nothing in here
331 // re-enters media code, so the hold is a string copy long.
332
1/2
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
24441 std::unique_lock<std::mutex> lock(mediaOutputLock);
333
2/2
✓ Branch 0 taken 24309 times.
✓ Branch 1 taken 132 times.
24441 if (mediaOutput) {
334
1/2
✓ Branch 0 taken 24309 times.
✗ Branch 1 not taken.
24309 mediaFilename = mediaOutput->m_mediaFilename;
335
1/2
✓ Branch 0 taken 24309 times.
✗ Branch 1 not taken.
24309 std::lock_guard<std::mutex> fl(MediaOutputStatus::FieldsLock());
336 24309 secsElapsed = mediaOutputStatus.secondsElapsed;
337 24309 secsRemaining = mediaOutputStatus.secondsRemaining;
338 24309 }
339 24441 }
340
341
8/10
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24433 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 24433 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24309 times.
✓ Branch 7 taken 124 times.
✓ Branch 8 taken 24317 times.
✓ Branch 9 taken 124 times.
24441 if (seqFilename != "" || mediaFilename != "") {
342
2/4
✓ Branch 0 taken 24317 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24317 times.
✗ Branch 3 not taken.
24317 result["status"] = 1;
343
2/4
✓ Branch 0 taken 24317 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24317 times.
✗ Branch 3 not taken.
24317 result["status_name"] = "playing";
344 }
345
346
2/4
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
24441 result["playlist"] = seqFilename;
347
2/4
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
24441 result["sequence_filename"] = seqFilename;
348
3/6
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24441 times.
✗ Branch 5 not taken.
24441 result["media_filename"] = mediaFilename.substr(mediaFilename.find_last_of("/\\") + 1);
349
2/4
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
24441 result["current_sequence"] = seqFilename;
350
3/6
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24441 times.
✗ Branch 5 not taken.
24441 result["current_song"] = result["media_filename"];
351
2/4
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
24441 result["seconds_played"] = std::to_string(secsElapsed);
352
2/4
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
24441 result["seconds_elapsed"] = std::to_string(secsElapsed);
353
2/4
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
24441 result["seconds_remaining"] = std::to_string(secsRemaining);
354
3/6
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24441 times.
✗ Branch 5 not taken.
24441 result["time_elapsed"] = secondsToTime(secsElapsed);
355
3/6
✓ Branch 0 taken 24441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24441 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24441 times.
✗ Branch 5 not taken.
24441 result["time_remaining"] = secondsToTime(secsRemaining);
356 24441 } else {
357 // GetInfo() already resolved the next playlist; reuse it rather than
358 // walking the schedule again for each field.
359
1/2
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
112228 Json::Value schedInfo = scheduler->GetInfo();
360
5/10
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 112228 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 112228 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 112228 times.
✗ Branch 9 not taken.
112228 result["next_playlist"]["playlist"] = schedInfo["nextPlaylist"]["playlistName"];
361
5/10
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 112228 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 112228 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 112228 times.
✗ Branch 9 not taken.
112228 result["next_playlist"]["start_time"] = schedInfo["nextPlaylist"]["scheduledStartTimeStr"];
362
363
1/2
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
112228 Player::INSTANCE.GetCurrentStatus(result);
364
1/2
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
112228 result["scheduler"] = std::move(schedInfo);
365
366 // Add multi-stream slot status
367
2/4
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
112228 Json::Value slots = StreamSlotManager::Instance().GetAllSlotsStatus();
368
2/4
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
112228 result["streamSlots"] = slots;
369
370 // Media started outside a playlist -- "Play Media", a PSA, background
371 // music -- runs on a stream slot rather than through the player, so
372 // status_name read "idle" while audio was audibly playing. The slot
373 // data was already here; nothing looked at it. That cost real
374 // debugging time more than once: a box was declared silent on the
375 // strength of this field while a track was running.
376 //
377 // Only the display fields move. result["status"] deliberately stays
378 // FPP_STATUS_IDLE, because the scheduler gates on it in eight places
379 // and Player::StopNowAllLevels() stops levels while
380 // `GetStatus() != FPP_STATUS_IDLE`. It stops the playlist, not a
381 // slot, so reporting a slot as player activity would make it think
382 // a level was still playing.
383 112228 bool anyForeground = false, anyBackground = false;
384 112228 int lead = -1;
385
3/4
✓ Branch 0 taken 673368 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 561140 times.
✓ Branch 3 taken 112228 times.
673368 for (Json::ArrayIndex i = 0; i < slots.size(); i++) {
386
6/10
✓ Branch 0 taken 561140 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 561140 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 561140 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 561140 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 541700 times.
✓ Branch 9 taken 19440 times.
561140 if (slots[i]["status"].asString() != "playing") {
387 541700 continue;
388 }
389 // StreamSlot::isBackground exists but nothing currently sets it,
390 // so it cannot be the only test or this never fires. The manager
391 // already treats slots 2-5 as background everywhere else --
392 // StopBackgroundSlots() and ProcessBackgroundSlots() both operate
393 // on exactly that range -- so follow the same rule here, and keep
394 // honouring the flag for when it does get populated.
395
4/8
✓ Branch 0 taken 19440 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19440 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19440 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 19440 times.
✗ Branch 7 not taken.
38880 const bool bg = slots[i]["isBackground"].asBool() ||
396
5/8
✓ Branch 0 taken 19440 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19440 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19440 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 47 times.
✓ Branch 7 taken 19393 times.
19440 slots[i]["slot"].asInt() > 1;
397 19440 anyForeground |= !bg;
398 19440 anyBackground |= bg;
399 // Prefer a foreground slot as the one to describe; fall back to a
400 // background slot so a PSA or background music still names itself.
401
2/14
✗ Branch 0 not taken.
✓ Branch 1 taken 19440 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 19440 times.
✗ Branch 13 not taken.
19440 if (lead < 0 || (!bg && slots[lead]["isBackground"].asBool())) {
402 19440 lead = (int)i;
403 }
404 }
405
406
6/8
✓ Branch 0 taken 92835 times.
✓ Branch 1 taken 19393 times.
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 92788 times.
✓ Branch 4 taken 112228 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 112228 times.
✗ Branch 7 not taken.
112228 result["media_playing"] = anyForeground || anyBackground;
407 // Only describe a stream slot when the player itself is idle. Slot 1
408 // IS the playlist's own media, so an active playlist always has a
409 // "playing" slot; overwriting status_name here would demote a
410 // "playing" playlist (sequence + media) to "playing media" and hide
411 // the sequence name on consumers such as the multisync page.
412 // Testing also sets its own status_name; leave that alone too.
413
6/8
✓ Branch 0 taken 19440 times.
✓ Branch 1 taken 92788 times.
✓ Branch 2 taken 19440 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19440 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 716 times.
✓ Branch 7 taken 18724 times.
112944 if (lead >= 0 && result["status"].asInt() == FPP_STATUS_IDLE &&
414
8/14
✓ Branch 0 taken 716 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 716 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 716 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 716 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 716 times.
✓ Branch 9 taken 111512 times.
✓ Branch 10 taken 716 times.
✓ Branch 11 taken 111512 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
112944 result["status_name"].asString() == "idle") {
415
4/6
✓ Branch 0 taken 680 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 716 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 716 times.
✗ Branch 5 not taken.
716 result["status_name"] = anyForeground ? "playing media" : "playing background";
416
3/6
✓ Branch 0 taken 716 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 716 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 716 times.
✗ Branch 5 not taken.
716 const std::string f = slots[lead]["mediaFilename"].asString();
417
3/6
✓ Branch 0 taken 716 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 716 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 716 times.
✗ Branch 5 not taken.
716 result["current_song"] = f.substr(f.find_last_of("/\\") + 1);
418 // Only publish a position when the slot actually tracks one.
419 // Nothing drives slot 1's Process() when media is started outside
420 // a playlist -- both StreamSlotManager loops begin at slot 2,
421 // because slot 1 is normally the playlist's own media and the
422 // playlist pumps it -- so setMediaElapsed() never runs and these
423 // stay 0 for the whole track. Reporting that as a real position
424 // is worse than omitting it.
425
3/6
✓ Branch 0 taken 716 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 716 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 716 times.
✗ Branch 5 not taken.
716 const int elapsed = slots[lead]["secondsElapsed"].asInt();
426
3/6
✓ Branch 0 taken 716 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 716 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 716 times.
✗ Branch 5 not taken.
716 const int remaining = slots[lead]["secondsRemaining"].asInt();
427
4/4
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 173 times.
✓ Branch 3 taken 83 times.
716 if (elapsed > 0 || remaining > 0) {
428
2/4
✓ Branch 0 taken 633 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 633 times.
✗ Branch 3 not taken.
633 result["seconds_played"] = std::to_string(elapsed);
429
2/4
✓ Branch 0 taken 633 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 633 times.
✗ Branch 3 not taken.
633 result["seconds_remaining"] = std::to_string(remaining);
430 }
431 716 }
432
433 // A sequence started outside a playlist -- /api/sequence/.../start,
434 // the file manager's Play button, a "StartSequence" command preset --
435 // runs on the sequence engine, not through the player, so the idle
436 // branch above left current_sequence empty and status_name read
437 // "idle" (or "playing media" when media was also started on a slot)
438 // while channel data was visibly playing. Surface it the same way a
439 // playlist's sequence entry surfaces: status_name "playing" with
440 // current_sequence named, so the header badge and the multisync page
441 // agree on what is playing. A concurrent media slot keeps its
442 // current_song, so sequence + media outside a playlist names both.
443 //
444 // status goes with status_name, as it does for a playlist and for a
445 // remote playing a sequence: "playing" is FPP_STATUS_PLAYLIST_PLAYING.
446 // It was left at FPP_STATUS_IDLE, and the status page, which goes by
447 // status, said Idle beside a "playing" header badge. Only this JSON
448 // copy changes: the scheduler and Player::StopNowAllLevels() ask
449 // Player::GetStatus(), which stays idle.
450 //
451 // The allowlist matters: "testing" sets its own status_name above and
452 // must keep it, and the paused/stopping states are never idle, so
453 // only the three idle-family names can arrive here.
454
1/2
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
112228 if (result["status"].asInt() == FPP_STATUS_IDLE &&
455
7/12
✓ Branch 0 taken 35135 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35135 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35135 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1278 times.
✓ Branch 7 taken 33857 times.
✓ Branch 8 taken 3622 times.
✓ Branch 9 taken 108606 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
147363 (result["status_name"].asString() == "idle" ||
456
7/12
✓ Branch 0 taken 1278 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1278 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1278 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 598 times.
✓ Branch 7 taken 680 times.
✓ Branch 8 taken 35135 times.
✓ Branch 9 taken 77093 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
113506 result["status_name"].asString() == "playing media" ||
457
12/18
✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35135 times.
✓ Branch 3 taken 77093 times.
✓ Branch 4 taken 598 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 598 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 598 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 36 times.
✓ Branch 11 taken 562 times.
✓ Branch 12 taken 598 times.
✓ Branch 13 taken 111630 times.
✓ Branch 14 taken 1278 times.
✓ Branch 15 taken 110950 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
259627 result["status_name"].asString() == "playing background") &&
458
3/4
✓ Branch 0 taken 34573 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3622 times.
✓ Branch 3 taken 30951 times.
34573 sequence->IsSequenceRunning()) {
459
1/2
✓ Branch 0 taken 3622 times.
✗ Branch 1 not taken.
3622 const std::string sf = sequence->GetSeqFilenameCopy();
460
2/4
✓ Branch 0 taken 3622 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3622 times.
✗ Branch 3 not taken.
3622 if (sf != "") {
461
3/6
✓ Branch 0 taken 3622 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3622 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3622 times.
✗ Branch 5 not taken.
3622 result["current_sequence"] = sf.substr(sf.find_last_of("/\\") + 1);
462
2/4
✓ Branch 0 taken 3622 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3622 times.
✗ Branch 3 not taken.
3622 result["status"] = FPP_STATUS_PLAYLIST_PLAYING;
463
2/4
✓ Branch 0 taken 3622 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3622 times.
✗ Branch 3 not taken.
3622 result["status_name"] = "playing";
464 }
465 3622 }
466 112228 }
467 }
468
469 /*
470 *
471 */
472 2650 APIServer::APIServer() {
473 2650 }
474
475 /*
476 *
477 */
478 // Set once fppd is stopping: the sync advice registered in Init() then turns
479 // every new request (and WebSocket upgrade) away before it reaches a router.
480 static std::atomic<bool> s_httpQuiescing{ false };
481 // Set by the server thread once drogon::app().run() has returned.
482 static std::atomic<bool> s_httpServerStopped{ false };
483
484 // drogon's quit() frees its routers on the main loop *before* it stops the IO
485 // loops: an IO thread still routing a request (the UI's status poll, say)
486 // then reads a freed router (TSan: StaticFileRouter::route() reading the
487 // default handler of a router the main loop just deleted). So before quit(),
488 // new requests are refused, and each IO loop is made to run a task: a loop
489 // runs queued tasks only between requests, so once every loop has run one,
490 // none is inside a router, and none will enter one again.
491 2620 static void QuiesceHttpServer() {
492 2620 s_httpQuiescing = true;
493
4/6
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2619 times.
2620 if (!drogon::app().isRunning()) {
494 1 return;
495 }
496 struct Barrier {
497 std::mutex lock;
498 std::condition_variable done;
499 size_t left = 0;
500 };
501 // Shared with the tasks: one still queued when the wait gives up runs later.
502
1/2
✓ Branch 0 taken 2619 times.
✗ Branch 1 not taken.
2619 auto barrier = std::make_shared<Barrier>();
503
2/4
✓ Branch 0 taken 2619 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2619 times.
✗ Branch 3 not taken.
2619 size_t loops = drogon::app().getThreadNum();
504
2/2
✓ Branch 0 taken 26190 times.
✓ Branch 1 taken 2619 times.
28809 for (size_t i = 0; i < loops; i++) {
505
2/4
✓ Branch 0 taken 26190 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26190 times.
✗ Branch 3 not taken.
26190 trantor::EventLoop* loop = drogon::app().getIOLoop(i);
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26190 times.
26190 if (!loop) {
507 ✗ continue;
508 }
509 {
510
1/2
✓ Branch 0 taken 26190 times.
✗ Branch 1 not taken.
26190 std::lock_guard<std::mutex> l(barrier->lock);
511 26190 barrier->left++;
512 26190 }
513
2/4
✓ Branch 0 taken 26190 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26190 times.
✗ Branch 3 not taken.
26190 loop->queueInLoop([barrier]() {
514
1/2
✓ Branch 0 taken 26190 times.
✗ Branch 1 not taken.
26190 std::lock_guard<std::mutex> l(barrier->lock);
515 26190 barrier->left--;
516 26190 barrier->done.notify_all();
517 26190 });
518 }
519
1/2
✓ Branch 0 taken 2619 times.
✗ Branch 1 not taken.
2619 std::unique_lock<std::mutex> l(barrier->lock);
520
2/4
✓ Branch 0 taken 2619 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2619 times.
10450 if (!barrier->done.wait_for(l, std::chrono::seconds(2), [&barrier]() { return barrier->left == 0; })) {
521 ✗ LogWarn(VB_HTTP, "%d HTTP IO loops still busy at shutdown\n", (int)barrier->left);
522 }
523 2619 }
524
525 2620 APIServer::~APIServer() {
526 // Before drogon stops: the status push registers a WarningHolder listener
527 // and holds connection pointers, both of which outlive quit() (which only
528 // queues teardown, so the close callbacks may never run). Init() turned it
529 // on from here, so it gets turned off from here too.
530 2620 StatusWebSocketShutdown();
531
532 2620 QuiesceHttpServer();
533 // quit() does nothing until drogon's main loop is running, and the server
534 // thread only gets there at the end of run(), after it has set up the
535 // listeners and IO loops. A stop or restart that comes in sooner (a
536 // scheduled playlist whose first entry restarts fppd) would be lost, and
537 // the join below would wait forever. So wait for that loop, then ask once.
538 //
539 // Only once: quit() is not idempotent in drogon 1.9 (Debian 13's). Each
540 // call it lets through queues the whole teardown on the main loop, and the
541 // first one frees the listener manager, so a second one dereferences it
542 // (SIGSEGV in ListenerManager::stopListening()). Asking every 10 ms until
543 // run() returned did exactly that whenever the teardown took longer.
544
1/2
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
2620 if (m_serverThread) {
545 2620 trantor::EventLoop* loop = drogon::app().getLoop();
546
5/6
✓ Branch 0 taken 2914 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 2620 times.
✓ Branch 4 taken 294 times.
✓ Branch 5 taken 2620 times.
2914 while (!s_httpServerStopped && !loop->isRunning()) {
547 294 std::this_thread::sleep_for(std::chrono::milliseconds(10));
548 }
549
1/2
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
2620 if (!s_httpServerStopped) {
550 2620 drogon::app().quit();
551 }
552 }
553 // Join the server thread so Drogon is fully stopped before we return.
554 // PluginManager::Cleanup() (called from main() after MainLoop() exits)
555 // will dlclose() plugin libraries; if Drogon IO threads are still running
556 // at that point they may execute or release plugin handler lambdas whose
557 // code is in those libraries -> SEGV_MAPERR. Joining here ensures all
558 // Drogon threads have exited before any dlclose() can happen.
559
3/6
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2620 times.
✗ Branch 5 not taken.
2620 if (m_serverThread && m_serverThread->joinable()) {
560 2620 m_serverThread->join();
561 }
562
1/2
✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
2620 delete m_serverThread;
563 2620 m_serverThread = nullptr;
564 2620 m_pr.reset();
565 2620 }
566
567 // drogon's registerHandler/registerHandlerViaRegex take the callable by
568 // rvalue reference and move out of it, so a handler that is registered on
569 // more than one route must be copied for each registration. Re-using the
570 // same variable would register a moved-from closure: harmless for the
571 // captureless lambdas below, but for capturing ones (e.g. handleFppd's
572 // shared_ptr) the later route ends up dereferencing a nulled capture and
573 // crashes. Every registration below goes through this explicit copy so
574 // adding a capture to any handler stays safe.
575 template<typename T>
576 158940 static T copyHandler(const T& handler) {
577 158940 return handler;
578 }
579
580 /*
581 *
582 */
583 // "1.9.13" -> "1.9"
584 4 static std::string drogonMajorMinor(const std::string& v) {
585 4 size_t first = v.find('.');
586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (first == std::string::npos) {
587 ✗ return v;
588 }
589 4 size_t second = v.find('.', first + 1);
590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 return second == std::string::npos ? v : v.substr(0, second);
591 }
592
593 // registerHandler() and friends are templates instantiated in fppd from the
594 // drogon headers it was compiled against, and they call into libdrogon by
595 // vtable slot. Built against one drogon's headers and run against another's
596 // library - headers from a drogon source install in /usr/local, library from
597 // the distro package, say - the first route registration jumps through the
598 // wrong slot and fppd segfaults on every start. drogon's SONAME stays
599 // libdrogon.so.1 across those releases, so the dynamic linker cannot catch it.
600 // Compare what we were built with against what we loaded, and refuse to run
601 // on a major.minor mismatch with a message that says what to fix. A patch
602 // difference (a distro update within a release) is only noted.
603 2650 static bool drogonVersionMatches() {
604
1/2
✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
2650 std::string built = DROGON_VERSION;
605
1/2
✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
2650 std::string loaded = drogon::getVersion();
606
2/2
✓ Branch 0 taken 2648 times.
✓ Branch 1 taken 2 times.
2650 if (built == loaded) {
607 2648 return true;
608 }
609
4/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 if (drogonMajorMinor(built) != drogonMajorMinor(loaded)) {
610
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogErr(VB_HTTP, "fppd was built against drogon %s headers but loaded libdrogon %s. "
611 "These are not compatible; rebuild fppd against the drogon that is installed "
612 "(or remove the other drogon's headers or library)\n",
613 built.c_str(), loaded.c_str());
614
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 fprintf(stderr, "fppd: built against drogon %s headers but loaded libdrogon %s; rebuild fppd\n",
615 built.c_str(), loaded.c_str());
616 1 return false;
617 }
618
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogWarn(VB_HTTP, "fppd was built against drogon %s headers and loaded libdrogon %s\n",
619 built.c_str(), loaded.c_str());
620 1 return true;
621 2650 }
622
623 2650 void APIServer::Init(void) {
624
3/4
✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2649 times.
2650 if (!drogonVersionMatches()) {
625 // _exit(), not exit(): fppd is half started, and the static
626 // destructors exit() runs can block on, or free memory under, the
627 // threads already running (see ExitWithoutTeardown() in fppd.cpp).
628
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 fflush(nullptr);
629 1 _exit(EXIT_FAILURE);
630 }
631
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 m_pr = std::make_shared<PlayerResource>();
632
633
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 auto& app = drogon::app();
634
635 // Register all handlers with path patterns that match the old libhttpserver routes.
636 // The "true" flag in the old register_resource() meant "family" (prefix match),
637 // so we register with {1} catch-all patterns.
638
639 // PlayerResource (/fppd/*)
640 234171 auto handleFppd = [pr = m_pr](const HttpRequestPtr& req,
641 std::function<void(const HttpResponsePtr&)>&& callback) {
642 231522 HttpResponsePtr resp;
643
7/10
✓ Branch 0 taken 231522 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9009 times.
✓ Branch 3 taken 222513 times.
✓ Branch 4 taken 9009 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9009 times.
✓ Branch 8 taken 222513 times.
✓ Branch 9 taken 9009 times.
231522 if (req->method() == drogon::Get || req->isHead())
644
1/2
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
222513 resp = pr->render_GET(req);
645
3/4
✓ Branch 0 taken 9009 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1263 times.
✓ Branch 3 taken 7746 times.
9009 else if (req->method() == drogon::Post)
646
2/2
✓ Branch 0 taken 1093 times.
✓ Branch 1 taken 170 times.
1263 resp = pr->render_POST(req);
647
2/4
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7746 times.
7746 else if (req->method() == drogon::Put)
648 ✗ resp = pr->render_PUT(req);
649
2/4
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
7746 else if (req->method() == drogon::Delete)
650
1/2
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
7746 resp = pr->render_DELETE(req);
651 else
652 ✗ resp = makeStringResponse("Method Not Allowed", 405);
653
1/2
✓ Branch 0 taken 231352 times.
✗ Branch 1 not taken.
231352 callback(resp);
654 234171 };
655 // Register /fppd exact match first; the catch-all regex is registered after
656 // the more specific /fppd/* routes below so they take priority. Bare /fppd
657 // has no content of its own -- it 404s from PlayerResource just like a bad
658 // sub-path would (confirmed directly against fppd:32322). Intentionally
659 // left undocumented, same reasoning as bare /command below.
660
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/fppd", copyHandler(handleFppd), {drogon::Get, drogon::Post, drogon::Put, drogon::Delete, drogon::Head});
661
662 // OutputMonitor (/fppd/ports/*)
663 277 auto handlePorts = [](const HttpRequestPtr& req,
664 std::function<void(const HttpResponsePtr&)>&& callback) {
665
2/4
✓ Branch 0 taken 277 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 277 times.
✗ Branch 3 not taken.
277 callback(OutputMonitor::INSTANCE.render_GET(req));
666 277 };
667
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/fppd/ports", copyHandler(handlePorts), {drogon::Get, drogon::Head});
668
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/fppd/ports/.*", copyHandler(handlePorts), {drogon::Get, drogon::Head});
669
670 // ChannelTester (/fppd/testing/*)
671 154 auto handleTesting = [](const HttpRequestPtr& req,
672 std::function<void(const HttpResponsePtr&)>&& callback) {
673 154 HttpResponsePtr resp;
674
7/10
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 118 times.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 36 times.
✓ Branch 8 taken 118 times.
✓ Branch 9 taken 36 times.
154 if (req->method() == drogon::Get || req->isHead())
675
1/2
✓ Branch 0 taken 118 times.
✗ Branch 1 not taken.
118 resp = ChannelTester::INSTANCE.render_GET(req);
676
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
36 else if (req->method() == drogon::Post)
677
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 1 times.
36 resp = ChannelTester::INSTANCE.render_POST(req);
678 else
679 ✗ resp = makeStringResponse("Method Not Allowed", 405);
680
1/2
✓ Branch 0 taken 153 times.
✗ Branch 1 not taken.
153 callback(resp);
681 154 };
682
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/fppd/testing(/.*)?", copyHandler(handleTesting), {drogon::Get, drogon::Post, drogon::Head});
683
684 #ifdef HAS_AES67_GSTREAMER
685 /**
686 * Get AES67 status: whether it's active, PTP sync state, discovered
687 * streams and pipelines.
688 *
689 * @route GET /api/aes67
690 * @response 200 AES67 status.
691 */
692 // AES67 status/test endpoint
693 1442 auto handleAES67 = [](const HttpRequestPtr& req,
694 std::function<void(const HttpResponsePtr&)>&& callback) {
695
2/4
✓ Branch 0 taken 1442 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1442 times.
✗ Branch 3 not taken.
1442 callback(AES67Manager::INSTANCE.render_GET(req));
696 1442 };
697
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/aes67", copyHandler(handleAES67), {drogon::Get, drogon::Head});
698
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/aes67/.*", copyHandler(handleAES67), {drogon::Get, drogon::Head});
699 #endif
700
701 #ifdef HAS_OPUS_RTP_GSTREAMER
702 /**
703 * Get Opus RTP status: whether it's active and the current pipelines.
704 *
705 * @route GET /api/opusrtp
706 * @response 200 Opus RTP status.
707 */
708 612 auto handleOpusRTP = [](const HttpRequestPtr& req,
709 std::function<void(const HttpResponsePtr&)>&& callback) {
710
2/4
✓ Branch 0 taken 612 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 612 times.
✗ Branch 3 not taken.
612 callback(OpusRTPManager::INSTANCE.render_GET(req));
711 612 };
712
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/opusrtp", copyHandler(handleOpusRTP), {drogon::Get, drogon::Head});
713
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/opusrtp/.*", copyHandler(handleOpusRTP), {drogon::Get, drogon::Head});
714 #endif
715
716 #ifdef HAS_RTSP_OUTPUT_GSTREAMER
717 /**
718 * Get RTSP output status: whether the server is running, its port, and
719 * the URL and audio state of each configured mount.
720 *
721 * @route GET /api/rtspoutput
722 * @response 200 RTSP output status.
723 */
724 20 auto handleRTSPOutput = [](const HttpRequestPtr& req,
725 std::function<void(const HttpResponsePtr&)>&& callback) {
726
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 callback(RTSPOutputManager::INSTANCE.render_GET(req));
727 20 };
728
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/rtspoutput", copyHandler(handleRTSPOutput), {drogon::Get, drogon::Head});
729
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/rtspoutput/.*", copyHandler(handleRTSPOutput), {drogon::Get, drogon::Head});
730 #endif
731
732 #ifdef HAS_AUDIO_LEVEL_MONITOR
733 // Subscribe to live signal levels for a set of PipeWire nodes. Internal to
734 // fppd -- the browser reaches it through the PHP passthrough at
735 // /api/pipewire/audio/meters, and reads the levels themselves off the
736 // /fppdws WebSocket rather than polling for them.
737 //
738 // Body: {"nodes":[{"name":"fpp_group_x","sink":true}, ...], "ttl": 6000}
739 // "sink" says how to capture the node -- see AudioLevelMonitor::StartMeter.
740 //
741 // Metering is kept alive by time rather than by a connection: a caller
742 // re-posts to hold it open, so a browser that goes away silently stops
743 // costing anything once the TTL lapses. An empty list stops it at once.
744 12 auto handleMeters = [](const HttpRequestPtr& req,
745 std::function<void(const HttpResponsePtr&)>&& callback) {
746
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 Json::Value body;
747 12 std::vector<AudioLevelMonitor::Target> nodes;
748 12 int ttl = 6000;
749
4/8
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 if (LoadJsonFromString(std::string(req->getBody()), body)) {
750
6/12
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
12 if (body.isMember("nodes") && body["nodes"].isArray()) {
751
8/14
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 21 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 33 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 21 times.
✓ Branch 13 taken 12 times.
33 for (const auto& n : body["nodes"]) {
752 21 AudioLevelMonitor::Target t;
753 // Objects carry the node's kind; a bare string is assumed
754 // to be a sink, which is what most metered nodes are.
755
2/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
21 if (n.isObject()) {
756
3/6
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 t.name = n.get("name", "").asString();
757
3/6
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 t.isSink = n.get("sink", true).asBool();
758 } else {
759 ✗ t.name = n.asString();
760 }
761
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 nodes.push_back(t);
762 21 }
763 }
764
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 if (body.isMember("ttl")) {
765
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 ttl = body["ttl"].asInt();
766 }
767 }
768
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 AudioLevelMonitor::INSTANCE.Subscribe(nodes, ttl);
769
4/8
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
36 callback(makeStringResponse("{\"status\":\"OK\"}", 200, "application/json"));
770 12 };
771
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/fppd/meters", copyHandler(handleMeters), {drogon::Post});
772 #endif
773
774 // Plugin-published PipeWire audio sources (AudioSourceRegistry). Internal
775 // to fppd -- the publicly documented route is the PHP passthrough,
776 // GetPipeWirePluginSources() in www/api/controllers/pipewire.php, which
777 // is what actually sits at /api/pipewire/audio/plugin-sources (this raw
778 // fppd path isn't Apache-proxied directly, so it has no /api/ route of
779 // its own to document here).
780 2 auto handlePluginSources = [](const HttpRequestPtr& req,
781 std::function<void(const HttpResponsePtr&)>&& callback) {
782
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 std::string body = SaveJsonToString(AudioSourceRegistry::INSTANCE.toJson());
783
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 callback(makeStringResponse(body, 200, "application/json"));
784 2 };
785
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/pipewire/audio/plugin-sources", copyHandler(handlePluginSources), {drogon::Get, drogon::Head});
786
787 // Internal-only endpoint, deliberately undocumented (no @route
788 // docblock) -- lists every HTTP route currently registered with the
789 // embedded Drogon server, FPP's own included, plus the loaded plugins'
790 // routes from FPP's plugin route registry, so ServeOpenApiSpec() in
791 // www/api/index.php can diff it against known @route docblocks and
792 // surface whatever's left over as plugin-supplied (e.g. fpp-brightness's
793 // /Brightness). Registered under /internal, not /fppd, specifically so
794 // it does NOT appear in Apache's direct-proxy namespace whitelist
795 // (etc/apache2.site) -- PHP reaches it the same way it reaches every
796 // other fppd endpoint, a direct call to localhost:32322, never through
797 // Apache. It's still technically reachable externally via the generic
798 // /api/plugin-apis/<path> passthrough (that rule proxies any fppd path
799 // unconditionally -- it's what makes third-party plugin routes work at
800 // all, so it can't be restricted just for this one path), but it's no
801 // longer listed anywhere or reachable at a guessable /api/ path.
802 ✗ auto handlePluginApiRoutes = [](const HttpRequestPtr& req,
803 std::function<void(const HttpResponsePtr&)>&& callback) {
804 static const char* methodNames[] = {"GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS", "PATCH", "INVALID"};
805 ✗ Json::Value result(Json::arrayValue);
806 ✗ for (auto& info : drogon::app().getHandlersInfo()) {
807 ✗ Json::Value entry;
808 ✗ entry["path"] = std::get<0>(info);
809 ✗ drogon::HttpMethod m = std::get<1>(info);
810 ✗ entry["method"] = (m >= 0 && m <= drogon::Invalid) ? methodNames[m] : "UNKNOWN";
811 ✗ entry["description"] = std::get<2>(info);
812 ✗ result.append(entry);
813 ✗ }
814 // Plugin paths are dispatched by FPP, not registered with drogon.
815 ✗ for (auto& [path, m] : FPPPlugins::listPluginApiRoutes()) {
816 ✗ Json::Value entry;
817 ✗ entry["path"] = path;
818 ✗ entry["method"] = (m >= 0 && m <= drogon::Invalid) ? methodNames[m] : "UNKNOWN";
819 ✗ entry["description"] = "";
820 ✗ result.append(entry);
821 ✗ }
822 ✗ callback(makeStringResponse(SaveJsonToString(result), 200, "application/json"));
823 ✗ };
824
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/internal/pluginApiRoutes", copyHandler(handlePluginApiRoutes), {drogon::Get, drogon::Head});
825
826 // Builds a -manual crash report for POST /api/crashes/report. The build
827 // runs off the event loop, and the answer is made and sent back on the
828 // request's own IO loop: the build's thread touches no drogon object. It
829 // used to call the callback itself, which hands the response to the loop
830 // through libtrantor's lock-free queue, where a TSan build can't see the
831 // ordering, so every field of the response looked raced. Here the thread
832 // passes only the result, under a lock; the callback never leaves the
833 // loop. The queued task holds a bare pointer, which std::function keeps
834 // inline: a closure it allocated would cross through that queue too.
835
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/internal/crashReport", [](const HttpRequestPtr&, std::function<void(const HttpResponsePtr&)>&& callback) {
836 struct Pending {
837 std::mutex lock;
838 Json::Value result;
839 std::function<void(const HttpResponsePtr&)> callback;
840 };
841
2/6
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 206 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
206 Pending* pending = new Pending;
842 206 pending->callback = std::move(callback);
843 206 trantor::EventLoop* loop = trantor::EventLoop::getEventLoopOfCurrentThread();
844 206 std::thread([loop, pending]() {
845
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 Json::Value result;
846 206 std::string error;
847
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
206 std::string file = BuildManualCrashReport(error);
848
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 3 times.
205 if (file.empty()) {
849
2/4
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
✗ Branch 3 not taken.
202 result["Status"] = "ERROR";
850
2/4
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
✗ Branch 3 not taken.
202 result["Code"] = error;
851 } else {
852
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 result["Status"] = "OK";
853
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 result["File"] = file;
854 }
855 {
856
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 std::lock_guard<std::mutex> l(pending->lock);
857 205 pending->result = std::move(result);
858 205 }
859 // fppd may have stopped drogon while the report was building
860
5/10
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 205 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 205 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 205 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 205 times.
205 if (!loop || !drogon::app().isRunning()) {
861 ✗ delete pending;
862 ✗ return;
863 }
864 // The loop owns pending from here
865
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 loop->queueInLoop([pending]() {
866 205 std::function<void(const HttpResponsePtr&)> answer;
867
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 Json::Value result;
868 {
869
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 std::lock_guard<std::mutex> l(pending->lock);
870 205 answer = std::move(pending->callback);
871 205 result = std::move(pending->result);
872 205 }
873
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 delete pending;
874
5/10
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 205 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 205 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 205 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 205 times.
✗ Branch 9 not taken.
615 answer(makeStringResponse(SaveJsonToString(result), 200, "application/json"));
875 205 });
876
5/10
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 205 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 205 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 205 times.
✗ Branch 9 not taken.
411 }).detach();
877 206 }, {drogon::Post});
878
879 /**
880 * Load or unload a plugin without restarting fppd, so installing a plugin can
881 * take effect and uninstalling one can stop having effect mid-show.
882 *
883 * PluginManager mutates state the main loop walks every tick, and unloading
884 * calls into the plugin to stop its threads, so the work is handed to the
885 * main loop via a one-shot timer and this thread waits for the result. The
886 * wait is bounded: a wedged main loop returns 503 rather than pinning one of
887 * drogon's small pool of I/O threads forever.
888 *
889 * Documented under readable parameter names rather than the positional
890 * {1}/{2} drogon registers it as - see the skip list in docs.php.
891 *
892 * @route POST /api/fppd/plugin/{PluginName}/{action}
893 * @response 200 The plugin was loaded or unloaded.
894 * ```json
895 * {"Status": "OK", "Message": "", "plugin": "fpp-brightness", "loaded": false}
896 * ```
897 * @response 503 The main loop did not answer in time; nothing was changed.
898 */
899 96 auto handlePluginLifecycle = [](const HttpRequestPtr& req,
900 std::function<void(const HttpResponsePtr&)>&& callback,
901 const std::string& name, const std::string& action) {
902
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 std::string clientIP = getEffectiveClientIP(req);
903 // name and action are raw URL path segments - unvalidated at this point
904 // (action isn't checked against "load" until below, and the reject branch
905 // is by definition reached with a malformed name), so truncate before
906 // logging rather than let a caller choose how many bytes of fppd.log a
907 // single rejected request consumes.
908 // The name becomes a path under the plugin directory, so "." and ".."
909 // would name the plugin directory itself or the media directory above
910 // it. Same rule as the PHP plugin API: ^[A-Za-z0-9_.-]+$, less those
911 // two.
912
7/10
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 94 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 94 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 93 times.
✓ Branch 9 taken 1 times.
96 bool validName = !name.empty() && name != "." && name != "..";
913
2/2
✓ Branch 0 taken 882 times.
✓ Branch 1 taken 93 times.
975 for (char c : name) {
914
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 879 times.
882 if (!validName) {
915 3 break;
916 }
917
6/12
✓ Branch 0 taken 771 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 771 times.
✓ Branch 3 taken 108 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 771 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 108 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 108 times.
✗ Branch 11 not taken.
1758 validName = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
918
4/6
✓ Branch 0 taken 771 times.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 108 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
1758 c == '_' || c == '.' || c == '-';
919 }
920
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 93 times.
96 if (!validName) {
921
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 LogWarn(VB_PLUGIN, "API - Rejected plugin %s request for invalid plugin name \"%s\" from %s\n",
922 TruncateForLog(action).c_str(), TruncateForLog(name).c_str(), clientIP.c_str());
923
4/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
9 callback(makeStringResponse("{\"Status\":\"ERROR\",\"Message\":\"invalid plugin name\"}",
924 400, "application/json"));
925 3 return;
926 }
927
1/2
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
93 bool load = (action == "load");
928
4/6
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 39 times.
✓ Branch 4 taken 93 times.
✗ Branch 5 not taken.
93 LogInfo(VB_PLUGIN, "API - %s plugin \"%s\" requested from %s\n",
929 load ? "Loading" : "Unloading", TruncateForLog(name).c_str(), clientIP.c_str());
930 // Timers replace a same-named entry, so a second request arriving while
931 // one is queued would silently drop the first. Keep the names distinct.
932 static std::atomic<uint64_t> seq{ 0 };
933
2/4
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
93 std::string timerName = "PluginLifecycle-" + std::to_string(seq++);
934
935 // The result carries whether the plugin is loaded afterwards too: the
936 // plugin lists are the main loop's, so they are read there, not here.
937
1/2
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
93 auto result = std::make_shared<std::promise<std::tuple<bool, std::string, bool>>>();
938
1/2
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
93 auto done = result->get_future();
939
4/12
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 93 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 93 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
93 Timers::INSTANCE.addTimer(timerName, GetTimeMS(), [result, name, load]() {
940 // This runs plugin code (constructor, registerApis, shutdown,
941 // destructor) on the main loop, where nothing else catches.
942 93 std::string err;
943 93 bool ok = false;
944 try {
945
4/4
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 1 times.
132 ok = load ? PluginManager::INSTANCE.loadPlugin(name, err)
946
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 : PluginManager::INSTANCE.unloadPlugin(name, err);
947
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 } catch (const std::exception& ex) {
948
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 err = std::string("plugin threw: ") + ex.what();
949
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 LogErr(VB_PLUGIN, "%s plugin \"%s\" threw: %s\n", load ? "Loading" : "Unloading",
950 TruncateForLog(name).c_str(), ex.what());
951 1 } catch (...) {
952 ✗ err = "plugin threw a non-standard exception";
953 ✗ LogErr(VB_PLUGIN, "%s plugin \"%s\" threw a non-standard exception\n", load ? "Loading" : "Unloading",
954 TruncateForLog(name).c_str());
955 ✗ }
956
3/6
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 93 times.
✗ Branch 5 not taken.
93 result->set_value({ ok, err, PluginManager::INSTANCE.isPluginLoaded(name) });
957 93 });
958
959
2/4
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 93 times.
93 if (done.wait_for(std::chrono::seconds(30)) != std::future_status::ready) {
960 ✗ LogErr(VB_PLUGIN, "API - %s plugin \"%s\" (from %s) timed out waiting for the main loop\n",
961 load ? "Loading" : "Unloading", TruncateForLog(name).c_str(), clientIP.c_str());
962 ✗ callback(makeStringResponse("{\"Status\":\"ERROR\",\"Message\":\"timed out waiting for the main loop\"}",
963 503, "application/json"));
964 ✗ return;
965 }
966
1/2
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
93 auto [ok, err, loaded] = done.get();
967 // err can carry dlerror() text, which is not length-bounded either.
968
9/12
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 89 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 93 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 54 times.
✓ Branch 9 taken 39 times.
✓ Branch 10 taken 93 times.
✗ Branch 11 not taken.
93 LogInfo(VB_PLUGIN, "API - %s plugin \"%s\" (from %s): %s%s%s\n",
969 load ? "Load" : "Unload", TruncateForLog(name).c_str(), clientIP.c_str(),
970 ok ? "OK" : "FAILED", err.empty() ? "" : " - ", TruncateForLog(err).c_str());
971
1/2
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
93 Json::Value resp(Json::objectValue);
972
4/6
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 93 times.
✗ Branch 5 not taken.
93 resp["Status"] = ok ? "OK" : "ERROR";
973
2/4
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
93 resp["Message"] = err;
974
2/4
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
93 resp["plugin"] = name;
975
2/4
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
93 resp["loaded"] = loaded;
976
7/12
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 93 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 93 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 93 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 93 times.
✗ Branch 11 not taken.
279 callback(makeStringResponse(SaveJsonToString(resp), ok ? 200 : 400, "application/json"));
977
5/8
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 93 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 93 times.
✓ Branch 7 taken 3 times.
96 };
978
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/fppd/plugin/{1}/{2}", handlePluginLifecycle, {drogon::Post});
979
980 // PlayerResource catch-all for all other /fppd/* paths (registered AFTER
981 // specific /fppd/ports and /fppd/testing routes so they match first)
982
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/fppd/.*", copyHandler(handleFppd), {drogon::Get, drogon::Post, drogon::Put, drogon::Delete, drogon::Head});
983
984 /**
985 * List/manage pixel overlay models. See /api/models/* and /api/overlays/*
986 * for per-model operations.
987 *
988 * @route GET /api/models
989 * @response 200 Array of overlay models.
990 */
991 // PixelOverlayManager (/models/*, /overlays/*). NOTE: despite the shared
992 // handler, methods are NOT uniformly supported across paths -- render_POST()
993 // only acts on p1=="models" and render_PUT() only acts on p1=="overlays"
994 // with a /model/{id}/... suffix (bare PUT /api/models 404s: "PUT Not
995 // found /models"). Confirmed live; verify before adding more @route
996 // docblocks here rather than assuming symmetry.
997 702619 auto handleModels = [](const HttpRequestPtr& req,
998 std::function<void(const HttpResponsePtr&)>&& callback) {
999 702619 HttpResponsePtr resp;
1000
7/10
✓ Branch 0 taken 702619 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 352766 times.
✓ Branch 3 taken 349853 times.
✓ Branch 4 taken 352766 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 352766 times.
✓ Branch 8 taken 349853 times.
✓ Branch 9 taken 352766 times.
702619 if (req->method() == drogon::Get || req->isHead())
1001
1/2
✓ Branch 0 taken 349853 times.
✗ Branch 1 not taken.
349853 resp = PixelOverlayManager::INSTANCE.render_GET(req);
1002
3/4
✓ Branch 0 taken 352766 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 352734 times.
352766 else if (req->method() == drogon::Post)
1003
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
32 resp = PixelOverlayManager::INSTANCE.render_POST(req);
1004
2/4
✓ Branch 0 taken 352734 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 352734 times.
✗ Branch 3 not taken.
352734 else if (req->method() == drogon::Put)
1005
2/2
✓ Branch 0 taken 352693 times.
✓ Branch 1 taken 41 times.
352734 resp = PixelOverlayManager::INSTANCE.render_PUT(req);
1006 else
1007 ✗ resp = makeStringResponse("Method Not Allowed", 405);
1008
1/2
✓ Branch 0 taken 702577 times.
✗ Branch 1 not taken.
702577 callback(resp);
1009 702619 };
1010
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/models", copyHandler(handleModels), {drogon::Get, drogon::Post, drogon::Put, drogon::Head});
1011
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/models/.*", copyHandler(handleModels), {drogon::Get, drogon::Post, drogon::Put, drogon::Head});
1012 // No bare "/overlays" registration: it was never a documented,
1013 // intentional endpoint (checked the full doc history -- the pre-FPP10
1014 // endpoints.json help page only ever listed "overlays/models" and
1015 // "overlays/model/:ModelName", never bare "overlays"), Apache has never
1016 // proxied it externally, and grep finds zero internal callers anywhere
1017 // in the codebase. Only the real sub-paths are registered.
1018
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/overlays/.*", copyHandler(handleModels), {drogon::Get, drogon::Post, drogon::Put, drogon::Head});
1019
1020 // CommandManager (/command/*, /commands/*, /commandPresets/*)
1021 174690 auto handleCommands = [](const HttpRequestPtr& req,
1022 std::function<void(const HttpResponsePtr&)>&& callback) {
1023 174690 HttpResponsePtr resp;
1024
7/10
✓ Branch 0 taken 174690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 174296 times.
✓ Branch 3 taken 394 times.
✓ Branch 4 taken 174296 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 174296 times.
✓ Branch 8 taken 394 times.
✓ Branch 9 taken 174296 times.
174690 if (req->method() == drogon::Get || req->isHead())
1025
1/2
✓ Branch 0 taken 394 times.
✗ Branch 1 not taken.
394 resp = CommandManager::INSTANCE.render_GET(req);
1026
2/4
✓ Branch 0 taken 174296 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 174296 times.
✗ Branch 3 not taken.
174296 else if (req->method() == drogon::Post)
1027
2/2
✓ Branch 0 taken 174277 times.
✓ Branch 1 taken 19 times.
174296 resp = CommandManager::INSTANCE.render_POST(req);
1028 else
1029 ✗ resp = makeStringResponse("Method Not Allowed", 405);
1030
1/2
✓ Branch 0 taken 174671 times.
✗ Branch 1 not taken.
174671 callback(resp);
1031 174690 };
1032 // Bare /command has no content of its own -- it 404s from CommandManager
1033 // just like a bad sub-path would (confirmed by hitting it directly against
1034 // fppd:32322). Registered anyway because /command/* needs a parent match;
1035 // intentionally left undocumented since there's nothing real to document.
1036
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/command", copyHandler(handleCommands), {drogon::Get, drogon::Post, drogon::Head});
1037
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/command/.*", copyHandler(handleCommands), {drogon::Get, drogon::Post, drogon::Head});
1038 /**
1039 * List all defined commands.
1040 *
1041 * @route GET /api/commands
1042 * @response 200 Array of commands.
1043 */
1044 // render_POST() only acts when the path's first segment is literally
1045 // "command" (POST /api/command/{name}, already documented there) --
1046 // bare POST here, and POST /api/commandPresets below, both 404
1047 // "Not Found". Confirmed live.
1048
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/commands", copyHandler(handleCommands), {drogon::Get, drogon::Post, drogon::Head});
1049
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/commands/.*", copyHandler(handleCommands), {drogon::Get, drogon::Post, drogon::Head});
1050 /**
1051 * List all defined command presets.
1052 *
1053 * @route GET /api/commandPresets
1054 * @response 200 Array of command presets.
1055 */
1056
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/commandPresets", copyHandler(handleCommands), {drogon::Get, drogon::Post, drogon::Head});
1057
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/commandPresets/.*", copyHandler(handleCommands), {drogon::Get, drogon::Post, drogon::Head});
1058
1059 // GPIOManager (/gpio/*)
1060 887 auto handleGpio = [](const HttpRequestPtr& req,
1061 std::function<void(const HttpResponsePtr&)>&& callback) {
1062 887 HttpResponsePtr resp;
1063
7/10
✓ Branch 0 taken 887 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 524 times.
✓ Branch 3 taken 363 times.
✓ Branch 4 taken 524 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 524 times.
✓ Branch 8 taken 363 times.
✓ Branch 9 taken 524 times.
887 if (req->method() == drogon::Get || req->isHead())
1064
1/2
✓ Branch 0 taken 363 times.
✗ Branch 1 not taken.
363 resp = GPIOManager::INSTANCE.render_GET(req);
1065
2/4
✓ Branch 0 taken 524 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 524 times.
✗ Branch 3 not taken.
524 else if (req->method() == drogon::Post)
1066
1/2
✓ Branch 0 taken 524 times.
✗ Branch 1 not taken.
524 resp = GPIOManager::INSTANCE.render_POST(req);
1067 else
1068 ✗ resp = makeStringResponse("Method Not Allowed", 405);
1069
1/2
✓ Branch 0 taken 887 times.
✗ Branch 1 not taken.
887 callback(resp);
1070 887 };
1071 /**
1072 * List all GPIO pins and their current state/configuration.
1073 *
1074 * @route GET /api/gpio
1075 * @response 200 Array of GPIO pins.
1076 */
1077 // render_POST() only acts on POST /api/gpio/{pin} (already documented
1078 // there); bare POST here 404s "Not Found". Confirmed live.
1079
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/gpio", copyHandler(handleGpio), {drogon::Get, drogon::Post, drogon::Head});
1080
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/gpio/.*", copyHandler(handleGpio), {drogon::Get, drogon::Post, drogon::Head});
1081
1082 // Variables (/variables/*, reachable externally as /api/variables/* via the
1083 // Apache proxy whitelist in etc/apache2.site — same pattern as /gpio above)
1084 16081 auto handleVariables = [](const HttpRequestPtr& req,
1085 std::function<void(const HttpResponsePtr&)>&& callback) {
1086 16081 HttpResponsePtr resp;
1087
7/10
✓ Branch 0 taken 16081 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 540 times.
✓ Branch 3 taken 15541 times.
✓ Branch 4 taken 540 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 540 times.
✓ Branch 8 taken 15541 times.
✓ Branch 9 taken 540 times.
16081 if (req->method() == drogon::Get || req->isHead())
1088
1/2
✓ Branch 0 taken 15541 times.
✗ Branch 1 not taken.
15541 resp = Variables::INSTANCE.render_GET(req);
1089
3/4
✓ Branch 0 taken 540 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 270 times.
✓ Branch 3 taken 270 times.
540 else if (req->method() == drogon::Post)
1090
1/2
✓ Branch 0 taken 270 times.
✗ Branch 1 not taken.
270 resp = Variables::INSTANCE.render_POST(req);
1091
2/4
✓ Branch 0 taken 270 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 270 times.
✗ Branch 3 not taken.
270 else if (req->method() == drogon::Delete)
1092
1/2
✓ Branch 0 taken 270 times.
✗ Branch 1 not taken.
270 resp = Variables::INSTANCE.render_DELETE(req);
1093 else
1094 ✗ resp = makeStringResponse("Method Not Allowed", 405);
1095
1/2
✓ Branch 0 taken 16081 times.
✗ Branch 1 not taken.
16081 callback(resp);
1096 16081 };
1097 /**
1098 * List all variables and their current values.
1099 *
1100 * @route GET /api/variables
1101 * @response 200 Array of variables.
1102 */
1103 // Variables::render_POST()/render_DELETE() both require a name segment
1104 // (POST /variables/{name}, DELETE /variables/{name} -- already
1105 // documented there); bare POST/DELETE 400 "Bad Request". Confirmed live.
1106
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/variables", copyHandler(handleVariables), { drogon::Get, drogon::Post, drogon::Delete, drogon::Head });
1107
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/variables/.*", copyHandler(handleVariables), { drogon::Get, drogon::Post, drogon::Delete, drogon::Head });
1108
1109 // Player (/player/*)
1110 32885 auto handlePlayer = [](const HttpRequestPtr& req,
1111 std::function<void(const HttpResponsePtr&)>&& callback) {
1112 32885 HttpResponsePtr resp;
1113
3/10
✓ Branch 0 taken 32885 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32885 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 32885 times.
✗ Branch 9 not taken.
32885 if (req->method() == drogon::Get || req->isHead())
1114
1/2
✓ Branch 0 taken 32885 times.
✗ Branch 1 not taken.
32885 resp = Player::INSTANCE.render_GET(req);
1115 ✗ else if (req->method() == drogon::Post)
1116 ✗ resp = Player::INSTANCE.render_POST(req);
1117 ✗ else if (req->method() == drogon::Put)
1118 ✗ resp = Player::INSTANCE.render_PUT(req);
1119 else
1120 ✗ resp = makeStringResponse("Method Not Allowed", 405);
1121
1/2
✓ Branch 0 taken 32885 times.
✗ Branch 1 not taken.
32885 callback(resp);
1122 32885 };
1123 /**
1124 * Get the current player state (playing/stopped, volume, current media, etc.).
1125 *
1126 * @route GET /api/player
1127 * @response 200 Current player state.
1128 */
1129 // Player::render_POST()/render_PUT() are both unconditional
1130 // `return makeStringResponse("Not Found", 404, ...)` -- registered for
1131 // completeness/future use but dead code today. Confirmed live. Do not
1132 // document POST/PUT here without checking Player.cpp again.
1133
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandler("/player", copyHandler(handlePlayer), {drogon::Get, drogon::Post, drogon::Put, drogon::Head});
1134
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
15894 app.registerHandlerViaRegex("/player/.*", copyHandler(handlePlayer), {drogon::Get, drogon::Post, drogon::Put, drogon::Head});
1135
1136 // Video input preview (/videoinput/preview?id=N)
1137 //
1138 // Returns a single JPEG frame tapped off a running video input source's
1139 // intervideo channel, so the config page can show the operator what the
1140 // capture device is actually producing. Tapping the channel (rather than
1141 // opening /dev/videoN again) means the preview works while the source is
1142 // live -- UVC cameras only allow a single opener.
1143 28 auto handleVideoInputPreview = [](const HttpRequestPtr& req,
1144 std::function<void(const HttpResponsePtr&)>&& callback) {
1145 28 int id = 0;
1146
3/6
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
56 auto idStr = req->getParameter("id");
1147
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if (!idStr.empty()) {
1148 28 id = std::atoi(idStr.c_str());
1149 }
1150 28 int width = 320;
1151
3/6
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
56 auto wStr = req->getParameter("width");
1152
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if (!wStr.empty()) {
1153 28 width = std::atoi(wStr.c_str());
1154 }
1155
1156 28 std::vector<uint8_t> jpeg;
1157
7/10
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✓ Branch 7 taken 17 times.
✓ Branch 8 taken 11 times.
✓ Branch 9 taken 17 times.
28 if (id <= 0 || !VideoInputManager::Instance().GrabSnapshotJPEG(id, width, 2000, jpeg)) {
1158
3/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
33 auto resp = makeStringResponse("No frame available", 503);
1159
3/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
44 resp->addHeader("Cache-Control", "no-store");
1160
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 callback(resp);
1161 11 return;
1162 11 }
1163
1164
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 auto resp = drogon::HttpResponse::newHttpResponse();
1165
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 resp->setStatusCode(drogon::k200OK);
1166
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 resp->setContentTypeCode(drogon::CT_IMAGE_JPG);
1167
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
34 resp->setBody(std::string(reinterpret_cast<const char*>(jpeg.data()), jpeg.size()));
1168
3/6
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✗ Branch 5 not taken.
68 resp->addHeader("Cache-Control", "no-store");
1169
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 callback(resp);
1170
6/6
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 17 times.
✓ Branch 5 taken 11 times.
50 };
1171 /**
1172 * Get a JPEG snapshot of a running video input source, for UI preview.
1173 *
1174 * @route GET /api/videoinput/preview
1175 * @response 200 JPEG image of the most recent frame.
1176 * @response 503 Source is not running or produced no frame.
1177 */
1178
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
13245 app.registerHandler("/videoinput/preview", copyHandler(handleVideoInputPreview), {drogon::Get, drogon::Head});
1179
1180 // Let plugins register their own routes. These live in FPP's plugin
1181 // route registry, reached through drogon's default handler, so plugins
1182 // loaded after run() can add routes too.
1183
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 FPPPlugins::installPluginApiRouter();
1184
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 PluginManager::INSTANCE.registerApis();
1185
1186 // Configure and start drogon in a separate thread (since app().run() blocks).
1187 // Bind both v4 and v6 loopback so Apache's reverse-proxy works no
1188 // matter how libc resolves "localhost" (modern glibc returns ::1
1189 // first per RFC 6724). Without IPv6, "localhost" can only resolve to
1190 // 127.0.0.1, so the v4 listener alone is enough.
1191
4/8
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
18248 app.addListener(FPP_BIND_ADDRESS, FPP_HTTP_PORT);
1192
3/4
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2647 times.
✓ Branch 3 taken 2 times.
2649 if (canBindIPv6Loopback()) {
1193
4/8
✓ Branch 0 taken 2647 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2647 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2647 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2647 times.
✗ Branch 7 not taken.
18529 app.addListener("::1", FPP_HTTP_PORT);
1194 }
1195
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 app.setThreadNum(10);
1196
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 app.disableSession();
1197
1198 // Drogon's defaults are a 1MB max request body and a 64KB in-memory body,
1199 // above which it spools the body to a temp file. Both are too small for
1200 // FPP. The bulk pixel endpoints (PUT /api/overlays/model/{m}/data) send a
1201 // whole frame per request -- a 1024x1024 RGB model is 3MB, well past the
1202 // 1MB cap -- and spooling every frame of a repeating client to the SD card
1203 // would make that endpoint slower than the per-pixel API it replaces.
1204 // POST /api/models (model-overlays.json) was silently capped at 1MB too.
1205 //
1206 // The in-memory limit is what bounds worst-case RAM: setThreadNum(10) means
1207 // up to 10 concurrent bodies held in memory, so 4MB each is ~40MB worst
1208 // case -- affordable even on a 480MB BeagleBone. Requests larger than that
1209 // still work, they just go through a temp file.
1210
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 app.setClientMaxBodySize(32 * 1024 * 1024);
1211
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 app.setClientMaxMemoryBodySize(4 * 1024 * 1024);
1212
1213 // Drogon drops a connection after 60s without reads or writes, even while
1214 // its request is still being answered. A Diagnostic Report
1215 // (/internal/crashReport) takes minutes to build on a Pi Zero or
1216 // BeagleBone; outlast its 240s build and PHP's 270s wait.
1217
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 app.setIdleConnectionTimeout(300);
1218
1219 // A sync advice runs before any router, for plain requests and WebSocket
1220 // upgrades alike; see QuiesceHttpServer().
1221
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 app.registerSyncAdvice([](const drogon::HttpRequestPtr&) -> drogon::HttpResponsePtr {
1222
1/2
✓ Branch 0 taken 1161786 times.
✗ Branch 1 not taken.
1161786 if (!s_httpQuiescing) {
1223 1161786 return nullptr;
1224 }
1225 ✗ auto resp = drogon::HttpResponse::newHttpResponse();
1226 ✗ resp->setStatusCode(drogon::k503ServiceUnavailable);
1227 ✗ resp->setCloseConnection(true);
1228 ✗ return resp;
1229 ✗ });
1230
1231 // SIGINT and SIGTERM are FPP's, not drogon's. Drogon's handlers only stop
1232 // drogon's own threads, leaving the main loop spinning, and they log (so
1233 // allocate) and then run any callback given to them inside the signal
1234 // handler: a signal landing in malloc could deadlock the shutdown. This
1235 // handler only clears runMainFPPDLoop, a lock-free atomic. The main loop
1236 // sees it and runs FPP's normal shutdown, which stops drogon from
1237 // ~APIServer(). It also sets fppdStopSignalled, so a stop that lands
1238 // while a restart is tearing down ends the process instead of being
1239 // lost to the execlp().
1240
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 app.disableSigtermHandling();
1241 2649 struct sigaction stopAct = {};
1242 2649 stopAct.sa_handler = [](int) {
1243 2601 fppdStopSignalled = 1;
1244 2601 runMainFPPDLoop = 0;
1245 2601 };
1246 2649 sigemptyset(&stopAct.sa_mask);
1247 2649 sigaction(SIGINT, &stopAct, nullptr);
1248 2649 sigaction(SIGTERM, &stopAct, nullptr);
1249 // A restart execs with both blocked (see the end of fppd's main()), so
1250 // a stop sent after its last check is still pending here: take it now
1251 // that the handler is in place.
1252 sigset_t stopSigs;
1253 2649 sigemptyset(&stopSigs);
1254 2649 sigaddset(&stopSigs, SIGINT);
1255 2649 sigaddset(&stopSigs, SIGTERM);
1256 2649 pthread_sigmask(SIG_UNBLOCK, &stopSigs, nullptr);
1257
1258 // Register the /fppdws status push endpoint and its 1s change-poll timer.
1259 // The explicit call also keeps StatusWebSocket.o's controller
1260 // self-registration from being dropped by the linker.
1261
1/2
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
2649 StatusWebSocketInit();
1262
1263
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2649 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2649 m_serverThread = new std::thread([]() {
1264 2649 drogon::app().run();
1265 2620 s_httpServerStopped = true;
1266
2/4
✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
2649 });
1267 // Do NOT detach: ~APIServer() joins this thread after quit() so Drogon is
1268 // fully stopped before PluginManager::Cleanup() calls dlclose() on plugin
1269 // libraries. Plugin route handlers are lambdas with code in those libraries;
1270 // Drogon IO threads running after dlclose() -> SEGV_MAPERR on the vtable.
1271 2649 }
1272
1273 /*
1274 *
1275 */
1276 231522 void LogRequest(const HttpRequestPtr& req) {
1277 // LOG_EXCESSIVE, not LOG_DEBUG: /fppd/status is polled about once a second
1278 // by fppoled, the web UI and anything else watching the player, so at debug
1279 // these three lines are a steady 3/sec. They never reach fppd.log at the
1280 // default level, but the crash-time log ring keeps everything <= LOG_DEBUG
1281 // (CrashLogRingWillCapture), and 256 slots of status polling is all a crash
1282 // report was left with - roughly 85 seconds of nothing. See log.cpp.
1283
4/8
✓ Branch 0 taken 231522 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 231522 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 229513 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 229513 times.
✗ Branch 7 not taken.
231522 LogExcess(VB_HTTP, "API Req: %s%s from %s\n", req->path().c_str(),
1284 req->query().c_str(), getEffectiveClientIP(req).c_str());
1285 231522 }
1286
1287 /*
1288 *
1289 */
1290 231174 void LogResponse(const HttpRequestPtr& req, int responseCode, const std::string& content) {
1291
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 231127 times.
231174 if (WillLog(LOG_EXCESSIVE, VB_HTTP)) {
1292 47 LogExcess(VB_HTTP, "API Res: %s%s %d %s\n",
1293 req->path().c_str(),
1294 req->query().c_str(),
1295 responseCode,
1296 content.c_str());
1297 }
1298 231174 }
1299
1300 2649 PlayerResource::PlayerResource() {
1301 #ifdef PLATFORM_PI
1302 #define DEVICE_FILE_NAME "/dev/vcio"
1303 #define MAJOR_NUM 100
1304 #define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char*)
1305 #define MAX_STRING 1024
1306 #define GET_GENCMD_RESULT 0x00030080
1307 91 piPowerFile = open(DEVICE_FILE_NAME, 0);
1308 #else
1309 2558 piPowerFile = -1;
1310 #endif
1311 2649 }
1312 2620 PlayerResource::~PlayerResource() {
1313
2/2
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 2529 times.
2620 if (piPowerFile > 0) {
1314 91 close(piPowerFile);
1315 }
1316 2620 }
1317
1318 /*
1319 *
1320 */
1321 // --------------------------------------------------------------------------
1322 // OpenAPI docs for the /fppd/* GET endpoints handled below.
1323 // These @route docblocks are parsed by www/api/tools/generate_openapi.py; the
1324 // fppd daemon serves them on port 32322 and Apache proxies them under /api/*.
1325 // --------------------------------------------------------------------------
1326
1327 /**
1328 * List the effects currently running on the player.
1329 *
1330 * @route GET /api/fppd/effects
1331 * @response 200 Object with a `runningEffects` array.
1332 */
1333
1334 /**
1335 * Get the current fppd logging configuration (log level and enabled channels).
1336 *
1337 * @route GET /api/fppd/log
1338 * @response 200 Current log settings.
1339 */
1340
1341 /**
1342 * Get the full current player status (playlist, sequence, time, mode, etc.).
1343 *
1344 * @route GET /api/fppd/status
1345 * @response 200 Current player status JSON.
1346 */
1347
1348 /**
1349 * List the messages for all currently active warnings.
1350 *
1351 * @route GET /api/fppd/warnings
1352 * @response 200 Array of warning message strings.
1353 * ```json
1354 * ["Low disk space", "No network connection"]
1355 * ```
1356 */
1357
1358 /**
1359 * List all currently active warnings as full objects (message plus metadata).
1360 *
1361 * @route GET /api/fppd/warnings_full
1362 * @response 200 Array of warning objects.
1363 */
1364
1365 /**
1366 * Get the number of E1.31/sACN bytes received per universe.
1367 *
1368 * @route GET /api/fppd/e131stats
1369 * @response 200 E1.31 receive statistics.
1370 */
1371
1372 /**
1373 * List the MultiSync systems discovered on the network.
1374 *
1375 * @route GET /api/fppd/multiSyncSystems
1376 * @param int localOnly Set to 1 to return only the local system.
1377 * @response 200 MultiSync systems.
1378 */
1379
1380 /**
1381 * Get MultiSync packet statistics.
1382 *
1383 * @route GET /api/fppd/multiSyncStats
1384 * @param int reset Set to 1 to reset the statistics after reading them.
1385 * @response 200 MultiSync statistics.
1386 */
1387
1388 /**
1389 * List the playlists that are currently running.
1390 *
1391 * @route GET /api/fppd/playlists
1392 * @response 200 Currently running playlists.
1393 */
1394
1395 /**
1396 * Get the last-modified time of the running playlist file.
1397 *
1398 * @route GET /api/fppd/playlist/filetime
1399 * @response 200 Playlist file time.
1400 */
1401
1402 /**
1403 * Get the configuration of the running playlist.
1404 *
1405 * @route GET /api/fppd/playlist/config
1406 * @response 200 Playlist configuration.
1407 */
1408
1409 /**
1410 * Get the currently loaded schedule.
1411 *
1412 * @route GET /api/fppd/schedule
1413 * @response 200 Object with a `schedule` member.
1414 */
1415
1416 /**
1417 * Expand the schedule over an arbitrary date range.
1418 *
1419 * Unlike `/api/fppd/schedule`, which reports only the rolling window fppd has
1420 * actually scheduled out, this expands the configured schedule rules across any
1421 * requested range so past and future dates can be previewed. Occurrences are
1422 * advisory - they describe what the schedule says should happen, not what fppd
1423 * has committed to running.
1424 *
1425 * @route GET /api/fppd/schedule/range
1426 * @param int start Range start as epoch seconds.
1427 * @param int end Range end as epoch seconds. Must be after `start` and no more than 420 days later.
1428 * @param boolean includeDisabled Set to `1` to also expand disabled schedule entries.
1429 * @param boolean summary Set to `1` to collapse to one item per schedule entry per day, each carrying a `count` of that day's occurrences. Intended for month and other coarse views, where a repeating entry would otherwise return thousands of items.
1430 * @response 200 Object with a `schedule` member containing `entries`, `items`, `rangeStart` and `rangeEnd`.
1431 * @response 400 Missing, malformed, or excessively large range.
1432 */
1433
1434 /**
1435 * Get FPP version information.
1436 *
1437 * @route GET /api/fppd/version
1438 * @response 200 Version details.
1439 * ```json
1440 * {"version": "9.0", "majorVersion": 9, "minorVersion": 0, "branch": "master", "fppdAPI": 4, "Status": "OK"}
1441 * ```
1442 */
1443
1444 /**
1445 * Get (or set) the master output volume.
1446 *
1447 * @route GET /api/fppd/volume
1448 * @param int set New volume (0-100) to apply before returning.
1449 * @param boolean simple Return the volume as a bare text/plain integer instead of JSON.
1450 * @response 200 Object with a `volume` member (0-100).
1451 */
1452
1453 /**
1454 * Get the list of running sequences.
1455 *
1456 * @route GET /api/fppd/sequence
1457 * @response 200 Running sequences.
1458 */
1459
1460 /**
1461 * Dump the cached MQTT messages.
1462 *
1463 * @route GET /api/fppd/mqtt/cache
1464 * @response 200 Object keyed by topic, each value the topic's last cached message as a plain string.
1465 * Per-topic last-updated timestamps are exposed separately via
1466 * `GET /api/variables?mqtt=true` (`mqtt-<topic>` entries), not on this route.
1467 * @response 400 MQTT is not initialized.
1468 */
1469 222513 HttpResponsePtr PlayerResource::render_GET(const HttpRequestPtr& req) {
1470
1/2
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
222513 LogRequest(req);
1471
1472
1/2
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
222513 Json::Value result;
1473
1/2
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
222513 std::string resultStr = "";
1474
2/4
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 222513 times.
✗ Branch 3 not taken.
222513 std::string url(req->path());
1475
1476
4/8
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 222513 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 222513 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 222513 times.
890052 if (!replaceStart(url, "/fppd/", ""))
1477 ✗ replaceStart(url, "/fppd", "");
1478
1479 // Strip trailing slash to match endpoint definitions
1480
4/6
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 222513 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 222512 times.
445026 if (endsWith(url, "/"))
1481
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 url = url.substr(0, url.length() - 1);
1482
1483 // LOG_EXCESSIVE for the same reason as LogRequest() above.
1484
2/4
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 222513 times.
✗ Branch 3 not taken.
222513 LogExcess(VB_HTTP, "URL: %s %s\n", url.c_str(), req->query().c_str());
1485
1486 // Keep IF statement in alphabetical order
1487
3/4
✓ Branch 0 taken 222513 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 332 times.
✓ Branch 3 taken 222181 times.
222513 if (url == "effects") {
1488
1/2
✓ Branch 0 taken 332 times.
✗ Branch 1 not taken.
332 GetRunningEffects(result);
1489
3/4
✓ Branch 0 taken 222181 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 222161 times.
222181 } else if (url == "log") {
1490
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 GetLogSettings(result);
1491
3/4
✓ Branch 0 taken 222161 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136353 times.
✓ Branch 3 taken 85808 times.
222161 } else if (url == "status") {
1492
1/2
✓ Branch 0 taken 136353 times.
✗ Branch 1 not taken.
136353 GetCurrentStatus(result);
1493
3/4
✓ Branch 0 taken 85808 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 85488 times.
85808 } else if (url == "warnings") {
1494
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 result = Json::Value(Json::ValueType::arrayValue);
1495
3/4
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 219 times.
✓ Branch 3 taken 320 times.
539 for (auto& warn : WarningHolder::GetWarnings()) {
1496
2/4
✓ Branch 0 taken 219 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 219 times.
✗ Branch 3 not taken.
219 result.append(warn.message());
1497 320 }
1498
3/4
✓ Branch 0 taken 85488 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✓ Branch 3 taken 85384 times.
85488 } else if (url == "warnings_full") {
1499
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 result = Json::Value(Json::ValueType::arrayValue);
1500
3/4
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
✓ Branch 3 taken 104 times.
167 for (auto& warn : WarningHolder::GetWarnings()) {
1501
2/4
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
63 result.append(warn.toJsonValue());
1502 104 }
1503
3/4
✓ Branch 0 taken 85384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13922 times.
✓ Branch 3 taken 71462 times.
85384 } else if (url == "e131stats") {
1504
1/2
✓ Branch 0 taken 13922 times.
✗ Branch 1 not taken.
13922 GetE131BytesReceived(result);
1505
3/4
✓ Branch 0 taken 71462 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12549 times.
✓ Branch 3 taken 58913 times.
71462 } else if (url == "multiSyncSystems") {
1506 12549 bool localOnly = false;
1507
1508
5/8
✓ Branch 0 taken 12549 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12549 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12549 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 12548 times.
25098 if (getRequestArg(req, "localOnly") == "1")
1509 1 localOnly = true;
1510
1511
1/2
✓ Branch 0 taken 12549 times.
✗ Branch 1 not taken.
12549 GetMultiSyncSystems(result, localOnly);
1512
3/4
✓ Branch 0 taken 58913 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
✓ Branch 3 taken 58824 times.
58913 } else if (url == "multiSyncStats") {
1513 89 bool reset = false;
1514
1515
5/8
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 89 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 87 times.
178 if (getRequestArg(req, "reset") == "1")
1516 2 reset = true;
1517
1518
1/2
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
89 GetMultiSyncStats(result, reset);
1519
3/4
✓ Branch 0 taken 58824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 58819 times.
58824 } else if (url == "playlists") {
1520
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 GetCurrentPlaylists(result);
1521
3/4
✓ Branch 0 taken 58819 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 58814 times.
58819 } else if (url == "playlist/filetime") {
1522
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 GetPlaylistFileTime(result);
1523
3/4
✓ Branch 0 taken 58814 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 58807 times.
58814 } else if (url == "playlist/config") {
1524
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 GetPlaylistConfig(result);
1525
3/4
✓ Branch 0 taken 58807 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 58752 times.
58807 } else if (url == "recurringtasks") {
1526
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 GetRecurringTasks(result);
1527
3/4
✓ Branch 0 taken 58752 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 58736 times.
58752 } else if (url == "condition/preview") {
1528
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 GetConditionPreview(req, result);
1529
3/4
✓ Branch 0 taken 58736 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47263 times.
✓ Branch 3 taken 11473 times.
58736 } else if (url == "schedule") {
1530
2/4
✓ Branch 0 taken 47263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47263 times.
✗ Branch 3 not taken.
47263 result["schedule"] = scheduler->GetSchedule();
1531
2/4
✓ Branch 0 taken 47263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47263 times.
✗ Branch 3 not taken.
94526 SetOKResult(result, "");
1532
3/4
✓ Branch 0 taken 11473 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 11439 times.
11473 } else if (url == "schedule/range") {
1533 // Expanding the schedule costs time proportional to the range, so cap
1534 // what a single request can ask for rather than letting a stray query
1535 // hold the scheduler lock.
1536 34 constexpr int MAX_SCHEDULE_RANGE_DAYS = 420;
1537
1538
2/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
68 time_t rangeStart = (time_t)std::atoll(getRequestArg(req, "start").c_str());
1539
2/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
34 time_t rangeEnd = (time_t)std::atoll(getRequestArg(req, "end").c_str());
1540
1541
4/4
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 25 times.
34 if ((rangeStart <= 0) || (rangeEnd <= rangeStart)) {
1542
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
18 SetErrorResult(result, 400, "start and end must be epoch seconds with end after start");
1543
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
25 } else if ((rangeEnd - rangeStart) > ((time_t)MAX_SCHEDULE_RANGE_DAYS * 86400)) {
1544
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 SetErrorResult(result, 400, "range may not exceed " + std::to_string(MAX_SCHEDULE_RANGE_DAYS) + " days");
1545 } else {
1546
3/6
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
48 bool includeDisabled = getRequestArg(req, "includeDisabled") == "1";
1547
3/6
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
24 bool daySummary = getRequestArg(req, "summary") == "1";
1548
1549
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
48 result["schedule"] = scheduler->GetScheduleRange(rangeStart, rangeEnd,
1550 24 includeDisabled, daySummary);
1551
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
48 SetOKResult(result, "");
1552 }
1553
3/4
✓ Branch 0 taken 11439 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 11433 times.
11439 } else if (url == "version") {
1554
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 result["version"] = getFPPVersion();
1555
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 result["majorVersion"] = getFPPMajorVersion();
1556
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 result["minorVersion"] = getFPPMinorVersion();
1557
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 result["branch"] = getFPPBranch();
1558
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 result["fppdAPI"] = FPPD_API_VERSION;
1559
1560
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 SetOKResult(result, "");
1561
3/4
✓ Branch 0 taken 11433 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 11380 times.
11433 } else if (url == "volume") {
1562
4/8
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 53 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 53 times.
106 if (getRequestArg(req, "set") != "") {
1563 ✗ int i = std::atoi(getRequestArg(req, "set").c_str());
1564 ✗ setVolume(i);
1565 }
1566
5/8
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 53 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 52 times.
106 if (getRequestArg(req, "simple") == "true") {
1567
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string v = std::to_string(getVolume());
1568
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 return makeStringResponse(v, 200, "text/plain");
1569 1 }
1570
3/6
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 52 times.
✗ Branch 5 not taken.
52 result["volume"] = getVolume();
1571
2/4
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
104 SetOKResult(result, "");
1572
3/4
✓ Branch 0 taken 11380 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11345 times.
✓ Branch 3 taken 35 times.
11380 } else if (url == "sequence") {
1573
1/2
✓ Branch 0 taken 11345 times.
✗ Branch 1 not taken.
11345 LogDebug(VB_HTTP, "API - Getting list of running sequences\n");
1574
2/4
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
35 } else if (url == "mqtt/cache") {
1575
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 LogDebug(VB_HTTP, "API - Getting MQTT Cached data\n");
1576
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 5 times.
35 if (mqtt) {
1577
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 result["respCode"] = 200;
1578
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 result["Status"] = "OK";
1579
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 mqtt->dumpMessageCache(result);
1580 } else {
1581
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 result["Status"] = "ERROR";
1582
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 result["respCode"] = 400;
1583
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 result["Message"] = "Mqtt not Initialized";
1584 }
1585 } else {
1586 // url is an unvalidated caller-supplied path - truncate so an unknown
1587 // endpoint can't let a caller choose how many bytes of fppd.log each
1588 // request costs (bounded only by Apache's request-line limit).
1589 ✗ LogErr(VB_HTTP, "API - Error unknown GET request: %s\n", TruncateForLog(url).c_str());
1590
1591 ✗ result["Status"] = "ERROR";
1592 ✗ result["respCode"] = 404;
1593 ✗ result["Message"] = std::string("endpoint fppd/") + url + " does not exist";
1594 }
1595
1596 222512 int responseCode = 200;
1597
6/8
✓ Branch 0 taken 222512 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 222512 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 222088 times.
✓ Branch 5 taken 424 times.
✓ Branch 6 taken 222088 times.
✓ Branch 7 taken 424 times.
222512 if (resultStr.empty() && !result.isArray()) {
1598
3/4
✓ Branch 0 taken 222088 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11345 times.
✓ Branch 3 taken 210743 times.
222088 if (result.empty()) {
1599
2/4
✓ Branch 0 taken 11345 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11345 times.
✗ Branch 3 not taken.
11345 result["Status"] = "ERROR";
1600
2/4
✓ Branch 0 taken 11345 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11345 times.
✗ Branch 3 not taken.
11345 result["respCode"] = 400;
1601
2/4
✓ Branch 0 taken 11345 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11345 times.
✗ Branch 3 not taken.
11345 result["Message"] = "GET endpoint helper did not set result JSON";
1602
3/4
✓ Branch 0 taken 210743 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 74390 times.
✓ Branch 3 taken 136353 times.
210743 } else if (result.isMember("respCode")) {
1603
2/4
✓ Branch 0 taken 74390 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 74390 times.
✗ Branch 3 not taken.
74390 responseCode = result["respCode"].asInt();
1604 }
1605 }
1606
1/2
✓ Branch 0 taken 222512 times.
✗ Branch 1 not taken.
222512 if (resultStr.empty()) {
1607
2/4
✓ Branch 0 taken 222512 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 222512 times.
✗ Branch 3 not taken.
445024 resultStr = SaveJsonToString(result);
1608 }
1609
1/2
✓ Branch 0 taken 222512 times.
✗ Branch 1 not taken.
222512 LogResponse(req, responseCode, resultStr);
1610
1611
2/4
✓ Branch 0 taken 222512 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 222512 times.
✗ Branch 3 not taken.
445024 return makeStringResponse(resultStr, responseCode, "application/json");
1612 222513 }
1613
1614 /*
1615 *
1616 */
1617 // --------------------------------------------------------------------------
1618 // OpenAPI docs for the /fppd/* POST endpoints handled below.
1619 // --------------------------------------------------------------------------
1620
1621 /**
1622 * Start (or update) a named overlay effect on the player.
1623 *
1624 * @route POST /api/fppd/effects/{name}
1625 * @response 200 Effect started.
1626 */
1627
1628 /**
1629 * Re-read the Falcon hardware (e.g. cape/receiver) configuration.
1630 *
1631 * @route POST /api/fppd/falcon/hardware
1632 * @response 200 Hardware refreshed.
1633 */
1634
1635 /**
1636 * Set an external GPIO input state.
1637 *
1638 * @route POST /api/fppd/gpio/ext
1639 * @response 200 GPIO state updated.
1640 */
1641
1642 /**
1643 * Set logging levels.
1644 *
1645 * There is no separate channel parameter: the {level} path segment carries both
1646 * the level and the optional channel targeting. A bare level name - one of
1647 * error, warn, info, debug, or excess - sets that level globally for every log
1648 * channel. To target specific channels instead, use level:channel,channel and
1649 * separate multiple groups with a semicolon, e.g. debug:Schedule,Player;info:Sync.
1650 * Channel names are case-sensitive and match those returned by GET /api/fppd/log
1651 * (for example Command, Control, HTTP, Schedule, Sync).
1652 *
1653 * @route POST /api/fppd/log/level/{level}
1654 * @pathparam level enum:error,warn,info,debug,excess example:debug Log level to apply globally, or a level:channel[,channel] targeting expression.
1655 * @response 200 Log level updated.
1656 * @response 400 Invalid or unrecognized log level.
1657 */
1658
1659 /**
1660 * Apply a new channel-output configuration.
1661 *
1662 * @route POST /api/fppd/outputs
1663 * @response 200 Outputs updated.
1664 */
1665
1666 /**
1667 * Remap channel outputs.
1668 *
1669 * @route POST /api/fppd/outputs/remap
1670 * @response 200 Outputs remapped.
1671 */
1672
1673 /**
1674 * Replace the active schedule.
1675 *
1676 * @route POST /api/fppd/schedule
1677 * @response 200 Schedule updated.
1678 */
1679
1680 /**
1681 * Set the master output volume (0-100).
1682 *
1683 * @route POST /api/fppd/volume/{volume}
1684 * @response 200 Object with the new `volume`.
1685 */
1686
1687 /**
1688 * Shut down the fppd daemon.
1689 *
1690 * @route POST /api/fppd/shutdown
1691 * @response 200 fppd shutting down.
1692 */
1693 1263 HttpResponsePtr PlayerResource::render_POST(const HttpRequestPtr& req) {
1694
1/2
✓ Branch 0 taken 1263 times.
✗ Branch 1 not taken.
1263 LogRequest(req);
1695
1696
1/2
✓ Branch 0 taken 1263 times.
✗ Branch 1 not taken.
1263 Json::Value data;
1697
1/2
✓ Branch 0 taken 1263 times.
✗ Branch 1 not taken.
1263 Json::Value result;
1698
2/4
✓ Branch 0 taken 1263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1263 times.
✗ Branch 3 not taken.
1263 std::string url(req->path());
1699
1700
4/8
✓ Branch 0 taken 1263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1263 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1263 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1263 times.
5052 if (!replaceStart(url, "/fppd/", ""))
1701 ✗ replaceStart(url, "/fppd", "");
1702
1703 // Strip trailing slash to match endpoint definitions
1704
4/6
✓ Branch 0 taken 1263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1263 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47 times.
✓ Branch 5 taken 1216 times.
2526 if (endsWith(url, "/"))
1705
1/2
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
47 url = url.substr(0, url.length() - 1);
1706
1707
2/4
✓ Branch 0 taken 1263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1263 times.
✗ Branch 3 not taken.
1263 LogDebug(VB_HTTP, "POST URL: %s %s\n", url.c_str(), req->query().c_str());
1708
1709
4/6
✓ Branch 0 taken 1263 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1263 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1041 times.
✓ Branch 5 taken 222 times.
1263 if (getRequestContent(req) != "") {
1710
5/6
✓ Branch 0 taken 1041 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 982 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 177 times.
✓ Branch 5 taken 805 times.
1100 if (!LoadJsonFromString(getRequestContent(req), data)) {
1711
1/2
✓ Branch 0 taken 177 times.
✗ Branch 1 not taken.
177 LogErr(VB_CHANNELOUT, "Error parsing POST content\n");
1712
3/6
✓ Branch 0 taken 177 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 177 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 177 times.
✗ Branch 5 not taken.
708 return makeStringResponse("Error parsing POST content", 400);
1713 }
1714 }
1715
1716 // Keep IF statement in alphabetical order
1717
5/8
✓ Branch 0 taken 1027 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1027 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1027 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 187 times.
✓ Branch 7 taken 840 times.
4108 if (replaceStart(url, "effects/")) {
1718
2/2
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 85 times.
187 PostEffects(url, data, result);
1719
4/8
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 840 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 840 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 840 times.
3360 } else if (replaceStart(url, "falcon/hardware")) {
1720 ✗ PostFalconHardware(result);
1721
5/8
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 840 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 840 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✓ Branch 7 taken 829 times.
3360 } else if (replaceStart(url, "gpio/ext")) {
1722
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 4 times.
11 PostGPIOExt(data, result);
1723
5/8
✓ Branch 0 taken 829 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 829 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 829 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 248 times.
✓ Branch 7 taken 581 times.
3316 } else if (replaceStart(url, "log/level/")) {
1724 // SetLogLevelComplex returns false when the level (or targeted channel)
1725 // is not recognized and nothing was changed. Report that back rather
1726 // than falsely claiming success.
1727
3/4
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
✓ Branch 3 taken 189 times.
248 if (SetLogLevelComplex(url)) {
1728 // Persist the resulting per-channel levels to the settings file so
1729 // they survive a restart and stay in sync with the Logging settings
1730 // page (which reads/writes the LogLevel_* settings).
1731
2/2
✓ Branch 0 taken 944 times.
✓ Branch 1 taken 59 times.
1003 for (FPPLoggerInstance* logger : FPPLogger::INSTANCE.allInstances()) {
1732
4/8
✓ Branch 0 taken 944 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 944 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 944 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 944 times.
✗ Branch 7 not taken.
944 setSetting("LogLevel_" + logger->name, LogLevelToString(FacilityLevel(*logger)), true);
1733 }
1734
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 WarningHolder::UpdateLogLevelWarnings();
1735
2/4
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
✗ Branch 3 not taken.
118 SetOKResult(result, "Log Level Updated");
1736 } else {
1737
2/4
✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
189 SetErrorResult(result, 400, "Invalid or unrecognized log level: " + url);
1738 }
1739
3/4
✓ Branch 0 taken 581 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 567 times.
581 } else if (url == "outputs") {
1740
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 5 times.
14 PostOutputs(data, result);
1741
3/4
✓ Branch 0 taken 567 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 556 times.
567 } else if (url == "outputs/remap") {
1742
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 5 times.
11 PostOutputsRemap(data, result);
1743
3/4
✓ Branch 0 taken 556 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 524 times.
556 } else if (url == "recurringtasks") {
1744
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 7 times.
32 PostRecurringTasks(data, result);
1745
3/4
✓ Branch 0 taken 524 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 261 times.
✓ Branch 3 taken 263 times.
524 } else if (url == "schedule") {
1746
3/4
✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256 times.
✓ Branch 3 taken 5 times.
266 PostSchedule(data, result);
1747
2/2
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 34 times.
263 } else if (url.find("volume/") == 0) {
1748 // A whole number, or nothing changes: atoi() read garbage ("x", a
1749 // number too big for an int) as 0 or -1, and that muted the show.
1750
1/2
✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
229 std::string v = url.substr(7);
1751 229 char* endp = nullptr;
1752 229 errno = 0;
1753 229 long volume = strtol(v.c_str(), &endp, 10);
1754 // the whole value must be digits: an embedded NUL ("%00") stops
1755 // strtol() as if the string had ended
1756
7/8
✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 157 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 60 times.
✓ Branch 6 taken 169 times.
✓ Branch 7 taken 60 times.
229 if (v.empty() || endp != v.c_str() + v.size() || errno == ERANGE) {
1757
2/4
✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 169 times.
✗ Branch 3 not taken.
338 SetErrorResult(result, 400, "Volume must be a whole number, 0-100");
1758 } else {
1759
2/4
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
60 setVolume((int)std::clamp(volume, 0L, 100L));
1760
3/6
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
60 result["volume"] = getVolume();
1761
2/4
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
120 SetOKResult(result, "Volume set");
1762 }
1763
2/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
263 } else if (url == "shutdown") {
1764 ✗ SetOKResult(result, "Shutting down fppd");
1765 ✗ ShutdownFPPD();
1766 } else {
1767
2/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
34 LogErr(VB_HTTP, "API - Error unknown POST request: %s\n", TruncateForLog(url).c_str());
1768
1769
2/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
34 result["Status"] = "ERROR";
1770
2/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
34 result["respCode"] = 404;
1771
5/10
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 34 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 34 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 34 times.
✗ Branch 9 not taken.
68 result["Message"] = std::string("endpoint fppd/") + url + " does not exist";
1772 }
1773
1774
3/4
✓ Branch 0 taken 916 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 912 times.
916 if (!result.isMember("Status")) {
1775
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 result["Status"] = "ERROR";
1776
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 result["respCode"] = 400;
1777
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 result["Message"] = "POST endpoint helper did not set result JSON";
1778 }
1779
1780
2/4
✓ Branch 0 taken 916 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 916 times.
✗ Branch 3 not taken.
916 std::string resultStr = SaveJsonToString(result);
1781
3/6
✓ Branch 0 taken 916 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 916 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 916 times.
✗ Branch 5 not taken.
916 LogResponse(req, result["respCode"].asInt(), resultStr);
1782
1783
5/10
✓ Branch 0 taken 916 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 916 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 916 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 916 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 916 times.
✗ Branch 9 not taken.
2748 return makeStringResponse(resultStr.c_str(), result["respCode"].asInt(), "application/json");
1784 1603 }
1785
1786 /*
1787 *
1788 */
1789 /**
1790 * Reset the E1.31/sACN receive statistics.
1791 *
1792 * @route DELETE /api/fppd/e131stats
1793 * @response 200 Statistics cleared.
1794 */
1795 7746 HttpResponsePtr PlayerResource::render_DELETE(const HttpRequestPtr& req) {
1796
1/2
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
7746 LogRequest(req);
1797
1798
1/2
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
7746 Json::Value result;
1799
2/4
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
7746 std::string url(req->path());
1800
1801
4/8
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7746 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 7746 times.
30984 if (!replaceStart(url, "/fppd/", ""))
1802 ✗ replaceStart(url, "/fppd", "");
1803
1804 // Strip trailing slash to match endpoint definitions
1805
4/6
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7745 times.
15492 if (endsWith(url, "/"))
1806
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 url = url.substr(0, url.length() - 1);
1807
1808
2/4
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
7746 LogDebug(VB_HTTP, "DELETE URL: %s %s\n", url.c_str(), req->query().c_str());
1809
1810 // Keep IF statement in alphabetical order
1811
2/4
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
7746 if (url == "e131stats") {
1812
1/2
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
7746 LogDebug(VB_HTTP, "Resetting E131 Statistics");
1813
1/2
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
7746 ResetBytesReceived();
1814
2/4
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
15492 SetOKResult(result, "Stats Cleared");
1815 } else {
1816 ✗ LogErr(VB_HTTP, "API - Error unknown DELETE request: %s\n", TruncateForLog(url).c_str());
1817
1818 ✗ result["Status"] = "ERROR";
1819 ✗ result["respCode"] = 404;
1820 ✗ result["Message"] = std::string("endpoint fppd/") + url + " does not exist";
1821 }
1822
1823
2/4
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7746 times.
7746 if (!result.isMember("Status")) {
1824 ✗ result["Status"] = "ERROR";
1825 ✗ result["respCode"] = 400;
1826 ✗ result["Message"] = "DELETE endpoint helper did not set result JSON";
1827 }
1828
1829
2/4
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
7746 std::string resultStr = SaveJsonToString(result);
1830
1831
3/6
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7746 times.
✗ Branch 5 not taken.
7746 LogResponse(req, result["respCode"].asInt(), resultStr);
1832
1833
5/10
✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7746 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7746 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7746 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7746 times.
✗ Branch 9 not taken.
30984 return makeStringResponse(resultStr.c_str(), result["respCode"].asInt());
1834 7746 }
1835
1836 /*
1837 *
1838 */
1839 ✗ HttpResponsePtr PlayerResource::render_PUT(const HttpRequestPtr& req) {
1840 ✗ LogRequest(req);
1841
1842 ✗ Json::Value result;
1843 ✗ std::string url(req->path());
1844
1845 ✗ if (!replaceStart(url, "/fppd/", ""))
1846 ✗ replaceStart(url, "/fppd", "");
1847
1848 // Strip trailing slash to match endpoint definitions
1849 ✗ if (endsWith(url, "/"))
1850 ✗ url = url.substr(0, url.length() - 1);
1851
1852 ✗ LogDebug(VB_HTTP, "PUT URL: %s %s\n", url.c_str(), req->query().c_str());
1853
1854 // No PUT endpoints are currently implemented under /fppd/*.
1855 ✗ LogErr(VB_HTTP, "API - Error unknown PUT request: %s\n", TruncateForLog(url).c_str());
1856
1857 ✗ result["Status"] = "ERROR";
1858 ✗ result["respCode"] = 404;
1859 ✗ result["Message"] = std::string("endpoint fppd/") + url + " does not exist";
1860
1861 ✗ std::string resultStr = SaveJsonToString(result);
1862
1863 ✗ LogResponse(req, result["respCode"].asInt(), resultStr);
1864
1865 ✗ return makeStringResponse(resultStr.c_str(), result["respCode"].asInt());
1866 ✗ }
1867
1868 /*
1869 *
1870 */
1871 82499 void PlayerResource::SetOKResult(Json::Value& result, const std::string& msg) {
1872
2/4
✓ Branch 0 taken 82499 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 82499 times.
✗ Branch 3 not taken.
82499 result["Status"] = "OK";
1873
2/4
✓ Branch 0 taken 82499 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 82499 times.
✗ Branch 3 not taken.
82499 result["respCode"] = 200;
1874
2/4
✓ Branch 0 taken 82499 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 82499 times.
✗ Branch 3 not taken.
82499 result["Message"] = msg;
1875 82499 }
1876
1877 /*
1878 *
1879 */
1880 480 void PlayerResource::SetErrorResult(Json::Value& result, const int respCode, const std::string& msg) {
1881
2/4
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 480 times.
✗ Branch 3 not taken.
480 result["Status"] = "ERROR";
1882
2/4
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 480 times.
✗ Branch 3 not taken.
480 result["respCode"] = respCode;
1883
2/4
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 480 times.
✗ Branch 3 not taken.
480 result["Message"] = msg;
1884 480 }
1885
1886 /*
1887 *
1888 */
1889 332 void PlayerResource::GetRunningEffects(Json::Value& result) {
1890 332 LogDebug(VB_HTTP, "API - Getting list of running effects\n");
1891
2/4
✓ Branch 0 taken 332 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 332 times.
✗ Branch 3 not taken.
332 SetOKResult(result, "");
1892
2/4
✓ Branch 0 taken 332 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 332 times.
✗ Branch 3 not taken.
332 result["runningEffects"] = GetRunningEffectsJson();
1893 332 }
1894
1895 /*
1896 *
1897 */
1898 20 void PlayerResource::GetLogSettings(Json::Value& result) {
1899
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 SetOKResult(result, "");
1900
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 Json::Value log;
1901
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 std::vector<FPPLoggerInstance*> allLoggers = FPPLogger::INSTANCE.allInstances();
1902 20 std::vector<FPPLoggerInstance*>::iterator it;
1903
1904
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 20 times.
340 for (it = allLoggers.begin(); it != allLoggers.end(); it++) {
1905 320 FPPLoggerInstance* ptr = *it;
1906
4/8
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 320 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 320 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 320 times.
✗ Branch 7 not taken.
320 log[ptr->name] = LogLevelToString(FacilityLevel(*ptr));
1907 }
1908
1909
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 result["log"] = log;
1910 20 }
1911
1912 /*
1913 *
1914 */
1915 136353 void PlayerResource::GetCurrentStatus(Json::Value& result) {
1916 // LOG_EXCESSIVE for the same reason as LogRequest() above.
1917 136353 LogExcess(VB_HTTP, "API - Getting fppd status\n");
1918 136353 GetCurrentFPPDStatus(result);
1919 136353 }
1920
1921 /*
1922 *
1923 */
1924 5 void PlayerResource::GetCurrentPlaylists(Json::Value& result) {
1925
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 LogDebug(VB_HTTP, "API - Getting current playlist\n");
1926
1927
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Json::Value names(Json::arrayValue);
1928
1929
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (Player::INSTANCE.IsPlaying())
1930
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 names.append(Player::INSTANCE.GetPlaylistName());
1931
1932
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 result["playlists"] = names;
1933
1934
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 SetOKResult(result, "");
1935 5 }
1936
1937 /*
1938 *
1939 */
1940 13922 void PlayerResource::GetE131BytesReceived(Json::Value& result) {
1941
1/2
✓ Branch 0 taken 13922 times.
✗ Branch 1 not taken.
13922 result = GetE131UniverseBytesReceived(); // e131bridge.cpp
1942
1943
1/2
✓ Branch 0 taken 13922 times.
✗ Branch 1 not taken.
13922 if (result.isMember("universes"))
1944
2/4
✓ Branch 0 taken 13922 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13922 times.
✗ Branch 3 not taken.
27844 SetOKResult(result, "");
1945 else
1946 ✗ SetErrorResult(result, 400, "GetE131UniverseBytesReceived() did not return any universes.");
1947 13922 }
1948
1949 /*
1950 *
1951 */
1952 12549 void PlayerResource::GetMultiSyncSystems(Json::Value& result, bool localOnly) {
1953
1/2
✓ Branch 0 taken 12549 times.
✗ Branch 1 not taken.
12549 result = multiSync->GetSystems(localOnly);
1954
1955
1/2
✓ Branch 0 taken 12549 times.
✗ Branch 1 not taken.
12549 if (result.isMember("systems"))
1956
2/4
✓ Branch 0 taken 12549 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12549 times.
✗ Branch 3 not taken.
25098 SetOKResult(result, "");
1957 else
1958 ✗ SetErrorResult(result, 400, "MultiSync did not return any systems.");
1959 12549 }
1960
1961 89 void PlayerResource::GetMultiSyncStats(Json::Value& result, bool reset) {
1962
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 87 times.
89 if (reset)
1963 2 multiSync->ResetSyncStats();
1964
1965
1/2
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
89 result = multiSync->GetSyncStats();
1966
1967
1/2
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
89 if (result.isMember("systems"))
1968
2/4
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
✗ Branch 3 not taken.
178 SetOKResult(result, "");
1969 else
1970 ✗ SetErrorResult(result, 400, "MultiSync did not return any systems.");
1971 89 }
1972
1973 /*
1974 *
1975 */
1976 5 void PlayerResource::GetPlaylistFileTime(Json::Value& result) {
1977
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (Player::INSTANCE.IsPlaying()) {
1978 5 uint64_t fileTime = Player::INSTANCE.GetFileTime();
1979
1980
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 result["fileTime"] = (Json::UInt64)fileTime;
1981 } else {
1982 ✗ result["fileTime"] = 0;
1983 }
1984
1985
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 SetOKResult(result, "");
1986 5 }
1987
1988 /*
1989 *
1990 */
1991 7 void PlayerResource::GetPlaylistConfig(Json::Value& result) {
1992
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (Player::INSTANCE.IsPlaying())
1993
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 result = Player::INSTANCE.GetConfig();
1994
1995
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 SetOKResult(result, "");
1996 7 }
1997
1998 /**
1999 * Report the configured Recurring Tasks merged with last-run status, for the
2000 * Recurring Tasks admin page (www/recurringtasks.php).
2001 *
2002 * @route GET /api/fppd/recurringtasks
2003 * @response 200 {"tasks": [...]}
2004 */
2005 55 void PlayerResource::GetRecurringTasks(Json::Value& result) {
2006
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 result["tasks"] = Json::Value(Json::arrayValue);
2007 55 RecurringTasks::INSTANCE.reportStatus(result["tasks"]);
2008
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 SetOKResult(result, "");
2009 55 }
2010
2011 /**
2012 * Preview a single If/Conditional Check leaf - the same lookup evaluate()
2013 * uses internally (Variable/Expression/Time/GPIO Pin/Sun), before any
2014 * comparator/Value is applied. Backs the If condition editor's "Show Current
2015 * Value" button, so picking the right Value to compare against isn't
2016 * guesswork.
2017 *
2018 * When a "comparator" param is also supplied (the consolidated eye-preview
2019 * modal's full-leaf mode), also evaluates Value the same way Value is
2020 * unconditionally evaluated at runtime and applies the comparator, returning
2021 * the RHS value and the boolean result too - reuses
2022 * ConditionNode::PreviewLeafResult(), the exact same evaluation path a real
2023 * saved leaf's evaluate() takes, so this can never drift from runtime
2024 * behavior.
2025 *
2026 * @route GET /api/fppd/condition/preview
2027 * @param string source One of the If Check "Source" dropdown values (e.g. "Variable", "GPIO Pin").
2028 * @param string name The Name/Expression field for that source.
2029 * @param string comparator Optional - one of the Check "Comparator" values. Enables full-leaf mode.
2030 * @param string value Optional - the Value field, only used when "comparator" is also given.
2031 * @param string not Optional - "true" to negate the result, only used when "comparator" is also given.
2032 * @response 200 {"found": true, "value": "..."} (source/name-only mode) or
2033 * {"found": true, "value": "...", "rhsValue": "...", "result": true} (full-leaf mode, LHS resolved) or
2034 * {"found": false, "rhsValue": "...", "result": true} (full-leaf mode, LHS not found - rhsValue/result
2035 * are still evaluated, since Value always evaluates and a missing LHS just yields `negate`) or
2036 * {"found": false} if the source/name doesn't currently resolve (source/name-only mode).
2037 */
2038 16 void PlayerResource::GetConditionPreview(const HttpRequestPtr& req, Json::Value& result) {
2039
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
32 std::string source = getRequestArg(req, "source");
2040
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 std::string name = getRequestArg(req, "name");
2041
4/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 4 times.
48 if (req->getParameter("comparator").empty()) {
2042
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 LogDebug(VB_HTTP, "API - Getting condition preview for source \"%s\" name \"%s\"\n", source.c_str(), name.c_str());
2043 12 bool found = false;
2044
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 std::string value = ConditionNode::PreviewSourceValue(source, name, found);
2045
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 result["found"] = found;
2046
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 7 times.
12 if (found) {
2047
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 result["value"] = value;
2048 }
2049
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 SetOKResult(result, "");
2050 12 return;
2051 12 }
2052
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 std::string comparator = getRequestArg(req, "comparator");
2053
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 std::string value = getRequestArg(req, "value");
2054
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 bool negate = getRequestArg(req, "not") == "true";
2055
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 LogDebug(VB_HTTP, "API - Getting full condition preview for source \"%s\" name \"%s\" %s%s \"%s\"\n",
2056 source.c_str(), name.c_str(), negate ? "NOT " : "", comparator.c_str(), value.c_str());
2057 4 bool lhsFound = false;
2058 4 std::string lhsValue, rhsValue;
2059 4 bool leafResult = false;
2060
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 ConditionNode::PreviewLeafResult(source, name, comparator, value, negate, lhsFound, lhsValue, rhsValue, leafResult);
2061
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 result["found"] = lhsFound;
2062
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 if (lhsFound) {
2063
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 result["value"] = lhsValue;
2064 }
2065 // rhsValue/result are always resolvable (Value is unconditionally
2066 // evaluated, and a not-found LHS still yields a definite result of
2067 // `negate`), so return them regardless of lhsFound - lets the eye-preview
2068 // modal show what Value evaluates to instead of stopping cold when only
2069 // the LHS side is missing.
2070
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 result["rhsValue"] = rhsValue;
2071
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 result["result"] = leafResult;
2072
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 SetOKResult(result, "");
2073
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 12 times.
28 }
2074
2075 /*
2076 *
2077 */
2078 187 void PlayerResource::PostEffects(const std::string& effectName, const Json::Value& data, Json::Value& result) {
2079
4/4
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 85 times.
✓ Branch 3 taken 34 times.
187 if (!data.isMember("command")) {
2080
2/4
✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
✗ Branch 3 not taken.
85 SetErrorResult(result, 400, "'command' field not specified");
2081 85 return;
2082 }
2083
2084
3/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 17 times.
34 std::string command = data["command"].asString();
2085
2086
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 LogDebug(VB_HTTP, "API - PostEffect(%s) cmd: %s\n", effectName.c_str(), command.c_str());
2087
2088
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
17 SetOKResult(result, "PostEffect result would go here");
2089 17 }
2090
2091 /*
2092 *
2093 */
2094 ✗ void PlayerResource::PostFalconHardware(Json::Value& result) {
2095 ✗ LogDebug(VB_HTTP, "API - Reloading hardware config\n");
2096
2097 ✗ SetOKResult(result, "PostFalconHardware result would go here");
2098 ✗ }
2099
2100 /*
2101 *
2102 */
2103 11 void PlayerResource::PostGPIOExt(const Json::Value& data, Json::Value& result) {
2104
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
11 if (!data.isMember("config")) {
2105
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 SetErrorResult(result, 400, "'config' field not specified");
2106 7 return;
2107 }
2108
2109 ✗ LogDebug(VB_HTTP, "API - Doing something with gpio\n");
2110 }
2111
2112 /*
2113 *
2114 */
2115 14 void PlayerResource::PostOutputs(const Json::Value& data, Json::Value& result) {
2116
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
14 if (!data.isMember("command")) {
2117
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 SetErrorResult(result, 400, "'command' field not specified");
2118 5 return;
2119 }
2120
2121
6/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 3 times.
5 if (data["command"].asString() == "enable") {
2122 1 EnableChannelOutput();
2123
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 SetOKResult(result, "channel output enabled");
2124
5/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
3 } else if (data["command"].asString() == "disable") {
2125 2 DisableChannelOutput();
2126
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 SetOKResult(result, "channel output disabled");
2127 }
2128 }
2129
2130 /*
2131 *
2132 */
2133 11 void PlayerResource::PostOutputsRemap(const Json::Value& data, Json::Value& result) {
2134
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
11 if (!data.isMember("command")) {
2135
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 SetErrorResult(result, 400, "'command' field not specified");
2136 5 return;
2137 }
2138
2139
5/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
2 if (data["command"].asString() == "reload") {
2140 // FIXME, need to fix this function to lock the remap array
2141 // LoadChannelRemapData();
2142 ✗ SetOKResult(result, "channel remaps reloaded");
2143 }
2144 }
2145
2146 /**
2147 * Re-read config/recurringtasks.json and re-schedule all Recurring Task
2148 * timers to match, so a save on www/recurringtasks.php (which writes that
2149 * file via the generic api/configfile endpoint) takes effect without an
2150 * fppd restart. Also handles an immediate "Test Run" of one task, run
2151 * synchronously against the posted task definition (not a saved name), so
2152 * the admin page can preview unsaved edits.
2153 *
2154 * @route POST /api/fppd/recurringtasks
2155 * @body {"command": "reload"}
2156 * @body {"command": "test", "task": {"name": "...", "type": "command", "command": "URL", "args": [...], "filterType": "json", "filterJsonPath": "data.temp"}}
2157 * @response 200 Recurring tasks reloaded, or {"ok":bool,"raw":string,"filtered":string,"error":string} for "test".
2158 * @response 400 'command' field not specified.
2159 */
2160 32 void PlayerResource::PostRecurringTasks(const Json::Value& data, Json::Value& result) {
2161
4/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 23 times.
32 if (!data.isMember("command")) {
2162
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 SetErrorResult(result, 400, "'command' field not specified");
2163 5 return;
2164 }
2165
2166
3/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 1 times.
23 std::string command = data["command"].asString();
2167
3/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 17 times.
22 if (command == "reload") {
2168
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 RecurringTasks::INSTANCE.Reload();
2169
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
10 SetOKResult(result, "Recurring tasks reloaded");
2170
3/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 1 times.
17 } else if (command == "test") {
2171
3/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 2 times.
16 Json::Value testResult = RecurringTasks::INSTANCE.TestRunTask(data["task"]);
2172
3/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 14 times.
71 for (auto const& key : testResult.getMemberNames()) {
2173
3/6
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
57 result[key] = testResult[key];
2174 14 }
2175
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
14 SetOKResult(result, "");
2176 14 }
2177 22 }
2178
2179 /*
2180 *
2181 */
2182 261 void PlayerResource::PostSchedule(const Json::Value data, Json::Value& result) {
2183
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 252 times.
261 if (!data.isMember("command")) {
2184
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 SetErrorResult(result, 400, "'command' field not specified");
2185 5 return;
2186 }
2187
2188
6/8
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 251 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 250 times.
✓ Branch 7 taken 1 times.
252 if (data["command"].asString() == "reload") {
2189 250 scheduler->ReloadScheduleFile();
2190
2191
2/4
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 250 times.
✗ Branch 3 not taken.
500 SetOKResult(result, "Schedule reload triggered");
2192 }
2193 }
2194
2195 32442 void PlayerResource::periodicWork() {
2196
1/2
✓ Branch 0 taken 4599 times.
✗ Branch 1 not taken.
32442 if (piPowerFile > 0) {
2197 #ifdef PLATFORM_PI
2198 // The main loop calls this on any wake that follows an idle timeout,
2199 // which can be many times a second while playing. Each read is a
2200 // firmware mailbox round trip, and the >5-readings hysteresis below
2201 // is meant in seconds, so read at most once a second.
2202 static long long nextReadMS = 0;
2203
1/2
✓ Branch 0 taken 4599 times.
✗ Branch 1 not taken.
4599 long long nowMS = GetMonotonicTimeMS();
2204
2/2
✓ Branch 0 taken 3535 times.
✓ Branch 1 taken 1064 times.
4599 if (nowMS < nextReadMS) {
2205 3535 return;
2206 }
2207 1064 nextReadMS = nowMS + 1000;
2208 1064 int i = 0;
2209 int32_t p[(MAX_STRING >> 2) + 7];
2210 1064 p[i++] = 0; // size
2211 1064 p[i++] = 0x00000000; // process request
2212
2213 1064 p[i++] = GET_GENCMD_RESULT; // (the tag id)
2214 1064 p[i++] = MAX_STRING; // buffer_len
2215 1064 p[i++] = 0; // request_len (set to response length)
2216 1064 p[i++] = 0; // error repsonse
2217
2218 1064 memcpy(p + i, "get_throttled", strlen("get_throttled") + 1);
2219 1064 i += MAX_STRING >> 2;
2220 1064 p[i++] = 0x00000000; // end tag
2221 1064 p[0] = i * sizeof *p; // actual size
2222
2223 1064 int ret_val = ioctl(piPowerFile, IOCTL_MBOX_PROPERTY, p);
2224
1/2
✓ Branch 0 taken 1064 times.
✗ Branch 1 not taken.
1064 std::string s = (char*)&p[6];
2225
1/2
✓ Branch 0 taken 1064 times.
✗ Branch 1 not taken.
1064 if (s.starts_with("throttled=0x")) {
2226
1/2
✓ Branch 0 taken 1064 times.
✗ Branch 1 not taken.
1064 s = s.substr(12);
2227
1/2
✓ Branch 0 taken 1064 times.
✗ Branch 1 not taken.
1064 uint32_t res = std::stol(s, nullptr, 16);
2228 1064 bool bad = res & 0x1;
2229 1064 piPowerBad = bad;
2230 // Shared by the add and the remove: RemoveWarning() matches on the
2231 // exact text.
2232 1064 constexpr int PI_POWER_WARNING_ID = 15;
2233 1064 constexpr const char* PI_POWER_WARNING_MSG = "Raspberry Pi Voltage Too Low";
2234 // The banner goes up after more than 5 bad readings in a row and
2235 // comes down after more than 5 good ones, so a supply hovering at
2236 // the threshold doesn't flap it. It used to stay up until fppd
2237 // restarted, long after the supply had been fixed.
2238 static int goodCount = 0;
2239
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1058 times.
1064 if (bad) {
2240 6 goodCount = 0;
2241 6 piPowerWarningCount++;
2242
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
6 if (piPowerWarningCount > 5 && !piPowerWarningAdded) {
2243
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 WarningHolder::AddWarning(PI_POWER_WARNING_ID, PI_POWER_WARNING_MSG);
2244 1 piPowerWarningAdded = true;
2245 }
2246 } else {
2247 1058 piPowerWarningCount = 0;
2248
6/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1052 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1057 times.
1058 if (piPowerWarningAdded && ++goodCount > 5) {
2249
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
3 WarningHolder::RemoveWarning(PI_POWER_WARNING_ID, PI_POWER_WARNING_MSG);
2250 1 piPowerWarningAdded = false;
2251 1 goodCount = 0;
2252 }
2253 }
2254 }
2255 #endif
2256 1064 }
2257 27843 }
2258
2259 32442 void APIServer::periodicWork() {
2260
1/2
✓ Branch 0 taken 32442 times.
✗ Branch 1 not taken.
32442 if (m_pr) {
2261 32442 m_pr->periodicWork();
2262 }
2263 32442 }
2264