Debian Codegraph @

src/HLSAllowlist.cpp

raw
1 /*
2 * Copyright (C) 2021 flubshi
3 * https://github.com/flubshi
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 */
21
22 #include "HLSAllowlist.h"
23
24 #include "kodi/tools/StringUtils.h"
25
26 #include <kodi/Filesystem.h>
27
28 HLSAllowlist::HLSAllowlist() : m_hls_allowed()
29 {
30 LoadHLSAllowlist();
31 }
32
33 bool HLSAllowlist::contains(std::string channelid) const
34 {
35 return std::find(m_hls_allowed.begin(), m_hls_allowed.end(), channelid) != m_hls_allowed.end();
36 }
37
38 void HLSAllowlist::LoadHLSAllowlist()
39 {
40 const char* filePath = "special://home/addons/pvr.waipu/resources/hls_allowlist.txt";
41 if (!kodi::vfs::FileExists(filePath, false))
42 {
43 filePath = "special://xbmc/addons/pvr.waipu/resources/hls_allowlist.txt";
44 }
45
46 if (kodi::vfs::FileExists(filePath, false))
47 {
48 kodi::Log(ADDON_LOG_DEBUG, "%s: Loading hls allowlist from file '%s'", __FUNCTION__, filePath);
49 kodi::vfs::CFile file;
50 if (!file.OpenFile(filePath, 0))
51 {
52 kodi::Log(ADDON_LOG_ERROR, "%s: File '%s' failed to open", __FUNCTION__, filePath);
53 return;
54 }
55
56 std::string line;
57 while (file.ReadLine(line))
58 {
59 line = kodi::tools::StringUtils::TrimRight(line);
60 m_hls_allowed.push_back(line);
61 kodi::Log(ADDON_LOG_DEBUG, "%s: Add channel to hls allowlist '%s'", __FUNCTION__,
62 line.c_str());
63 }
64 }
65 else
66 {
67 kodi::Log(ADDON_LOG_INFO, "%s: File '%s' not found", __FUNCTION__, filePath);
68 }
69 }