blob: 81a9982b788e6dbf8761156c5c20d1fea0cda086 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*
* Copyright (C) 2014-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "ResourceFile.h"
#include "ServiceBroker.h"
#include "URL.h"
#include "Util.h"
#include "addons/AddonManager.h"
#include "addons/Resource.h"
using namespace ADDON;
using namespace XFILE;
CResourceFile::CResourceFile()
: COverrideFile(false)
{ }
CResourceFile::~CResourceFile() = default;
bool CResourceFile::TranslatePath(const std::string &path, std::string &translatedPath)
{
return TranslatePath(CURL(path), translatedPath);
}
bool CResourceFile::TranslatePath(const CURL &url, std::string &translatedPath)
{
translatedPath = url.Get();
// only handle resource:// paths
if (!url.IsProtocol("resource"))
return false;
// the share name represents an identifier that can be mapped to an addon ID
const std::string& addonId = url.GetShareName();
std::string filePath;
if (url.GetFileName().length() > addonId.length())
filePath = url.GetFileName().substr(addonId.size() + 1);
if (addonId.empty())
return false;
AddonPtr addon;
if (!CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, OnlyEnabled::CHOICE_YES) ||
addon == NULL)
return false;
std::shared_ptr<CResource> resource = std::dynamic_pointer_cast<ADDON::CResource>(addon);
if (resource == NULL)
return false;
if (!resource->IsAllowed(filePath))
return false;
translatedPath = CUtil::ValidatePath(resource->GetFullPath(filePath));
return true;
}
std::string CResourceFile::TranslatePath(const CURL &url)
{
std::string translatedPath;
if (!TranslatePath(url, translatedPath))
return "";
return translatedPath;
}
|