summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/URIUtils.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/URIUtils.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/utils/URIUtils.h')
-rw-r--r--xbmc/utils/URIUtils.h228
1 files changed, 228 insertions, 0 deletions
diff --git a/xbmc/utils/URIUtils.h b/xbmc/utils/URIUtils.h
new file mode 100644
index 0000000..31db0ec
--- /dev/null
+++ b/xbmc/utils/URIUtils.h
@@ -0,0 +1,228 @@
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include <string>
12#include <vector>
13
14class CURL;
15class CAdvancedSettings;
16
17class URIUtils
18{
19public:
20 static void RegisterAdvancedSettings(const CAdvancedSettings& advancedSettings);
21 static void UnregisterAdvancedSettings();
22
23 static std::string GetDirectory(const std::string &strFilePath);
24
25 static std::string GetFileName(const CURL& url);
26 static std::string GetFileName(const std::string& strFileNameAndPath);
27
28 static std::string GetExtension(const CURL& url);
29 static std::string GetExtension(const std::string& strFileName);
30
31 /*!
32 \brief Check if there is a file extension
33 \param strFileName Path or URL to check
34 \return \e true if strFileName have an extension.
35 \note Returns false when strFileName is empty.
36 \sa GetExtension
37 */
38 static bool HasExtension(const std::string& strFileName);
39
40 /*!
41 \brief Check if filename have any of the listed extensions
42 \param strFileName Path or URL to check
43 \param strExtensions List of '.' prefixed lowercase extensions separated with '|'
44 \return \e true if strFileName have any one of the extensions.
45 \note The check is case insensitive for strFileName, but requires
46 strExtensions to be lowercase. Returns false when strFileName or
47 strExtensions is empty.
48 \sa GetExtension
49 */
50 static bool HasExtension(const std::string& strFileName, const std::string& strExtensions);
51 static bool HasExtension(const CURL& url, const std::string& strExtensions);
52
53 static void RemoveExtension(std::string& strFileName);
54 static std::string ReplaceExtension(const std::string& strFile,
55 const std::string& strNewExtension);
56 static void Split(const std::string& strFileNameAndPath,
57 std::string& strPath, std::string& strFileName);
58 static std::vector<std::string> SplitPath(const std::string& strPath);
59
60 static void GetCommonPath(std::string& strPath, const std::string& strPath2);
61 static std::string GetParentPath(const std::string& strPath);
62 static bool GetParentPath(const std::string& strPath, std::string& strParent);
63
64 /*! \brief Retrieve the base path, accounting for stacks and files in rars.
65 \param strPath path.
66 \return the folder that contains the item.
67 */
68 static std::string GetBasePath(const std::string& strPath);
69
70 /* \brief Change the base path of a URL: fromPath/fromFile -> toPath/toFile
71 Handles changes in path separator and filename URL encoding if necessary to derive toFile.
72 \param fromPath the base path of the original URL
73 \param fromFile the filename portion of the original URL
74 \param toPath the base path of the resulting URL
75 \return the full path.
76 */
77 static std::string ChangeBasePath(const std::string &fromPath, const std::string &fromFile, const std::string &toPath, const bool &bAddPath = true);
78
79 static CURL SubstitutePath(const CURL& url, bool reverse = false);
80 static std::string SubstitutePath(const std::string& strPath, bool reverse = false);
81
82 /*! \brief Check whether a URL is a given URL scheme.
83 Comparison is case-insensitive as per RFC1738
84 \param url a std::string path.
85 \param type a lower-case scheme name, e.g. "smb".
86 \return true if the url is of the given scheme, false otherwise.
87 \sa PathHasParent, PathEquals
88 */
89 static bool IsProtocol(const std::string& url, const std::string& type);
90
91 /*! \brief Check whether a path has a given parent.
92 Comparison is case-sensitive.
93 Use IsProtocol() to compare the protocol portion only.
94 \param path a std::string path.
95 \param parent the string the parent of the path should be compared against.
96 \param translate whether to translate any special paths into real paths
97 \return true if the path has the given parent string, false otherwise.
98 \sa IsProtocol, PathEquals
99 */
100 static bool PathHasParent(std::string path, std::string parent, bool translate = false);
101
102 /*! \brief Check whether a path equals another path.
103 Comparison is case-sensitive.
104 \param path1 a std::string path.
105 \param path2 the second path the path should be compared against.
106 \param ignoreTrailingSlash ignore any trailing slashes in both paths
107 \return true if the paths are equal, false otherwise.
108 \sa IsProtocol, PathHasParent
109 */
110 static bool PathEquals(std::string path1, std::string path2, bool ignoreTrailingSlash = false, bool ignoreURLOptions = false);
111
112 static bool IsAddonsPath(const std::string& strFile);
113 static bool IsSourcesPath(const std::string& strFile);
114 static bool IsCDDA(const std::string& strFile);
115 static bool IsDAV(const std::string& strFile);
116 static bool IsDOSPath(const std::string &path);
117 static bool IsDVD(const std::string& strFile);
118 static bool IsFTP(const std::string& strFile);
119 static bool IsHTTP(const std::string& strFile);
120 static bool IsUDP(const std::string& strFile);
121 static bool IsTCP(const std::string& strFile);
122 static bool IsHD(const std::string& strFileName);
123 static bool IsInArchive(const std::string& strFile);
124 static bool IsInRAR(const std::string& strFile);
125 static bool IsInternetStream(const std::string& path, bool bStrictCheck = false);
126 static bool IsInternetStream(const CURL& url, bool bStrictCheck = false);
127 static bool IsInAPK(const std::string& strFile);
128 static bool IsInZIP(const std::string& strFile);
129 static bool IsISO9660(const std::string& strFile);
130 static bool IsLiveTV(const std::string& strFile);
131 static bool IsPVRRecording(const std::string& strFile);
132 static bool IsPVRRecordingFileOrFolder(const std::string& strFile);
133 static bool IsMultiPath(const std::string& strPath);
134 static bool IsMusicDb(const std::string& strFile);
135 static bool IsNfs(const std::string& strFile);
136 static bool IsOnDVD(const std::string& strFile);
137 static bool IsOnLAN(const std::string& strFile);
138 static bool IsHostOnLAN(const std::string& hostName, bool offLineCheck = false);
139 static bool IsPlugin(const std::string& strFile);
140 static bool IsScript(const std::string& strFile);
141 static bool IsRAR(const std::string& strFile);
142 static bool IsRemote(const std::string& strFile);
143 static bool IsSmb(const std::string& strFile);
144 static bool IsSpecial(const std::string& strFile);
145 static bool IsStack(const std::string& strFile);
146 static bool IsUPnP(const std::string& strFile);
147 static bool IsURL(const std::string& strFile);
148 static bool IsVideoDb(const std::string& strFile);
149 static bool IsAPK(const std::string& strFile);
150 static bool IsZIP(const std::string& strFile);
151 static bool IsArchive(const std::string& strFile);
152 static bool IsBluray(const std::string& strFile);
153 static bool IsAndroidApp(const std::string& strFile);
154 static bool IsLibraryFolder(const std::string& strFile);
155 static bool IsLibraryContent(const std::string& strFile);
156 static bool IsPVR(const std::string& strFile);
157 static bool IsPVRChannel(const std::string& strFile);
158 static bool IsPVRChannelGroup(const std::string& strFile);
159 static bool IsPVRGuideItem(const std::string& strFile);
160
161 static std::string AppendSlash(std::string strFolder);
162 static void AddSlashAtEnd(std::string& strFolder);
163 static bool HasSlashAtEnd(const std::string& strFile, bool checkURL = false);
164 static void RemoveSlashAtEnd(std::string& strFolder);
165 static bool CompareWithoutSlashAtEnd(const std::string& strPath1, const std::string& strPath2);
166 static std::string FixSlashesAndDups(const std::string& path, const char slashCharacter = '/', const size_t startFrom = 0);
167 /**
168 * Convert path to form without duplicated slashes and without relative directories
169 * Strip duplicated slashes
170 * Resolve and remove relative directories ("/../" and "/./")
171 * Will ignore slashes with other direction than specified
172 * Will not resolve path starting from relative directory
173 * @warning Don't use with "protocol://path"-style URLs
174 * @param path string to process
175 * @param slashCharacter character to use as directory delimiter
176 * @return transformed path
177 */
178 static std::string CanonicalizePath(const std::string& path, const char slashCharacter = '\\');
179
180 static CURL CreateArchivePath(const std::string& type,
181 const CURL& archiveUrl,
182 const std::string& pathInArchive = "",
183 const std::string& password = "");
184
185 static std::string AddFileToFolder(const std::string& strFolder, const std::string& strFile);
186 template <typename... T>
187 static std::string AddFileToFolder(const std::string& strFolder, const std::string& strFile, T... args)
188 {
189 auto newPath = AddFileToFolder(strFolder, strFile);
190 return AddFileToFolder(newPath, args...);
191 }
192
193 static bool HasParentInHostname(const CURL& url);
194 static bool HasEncodedHostname(const CURL& url);
195 static bool HasEncodedFilename(const CURL& url);
196
197 /*!
198 \brief Cleans up the given path by resolving "." and ".."
199 and returns it.
200
201 This methods goes through the given path and removes any "."
202 (as it states "this directory") and resolves any ".." by
203 removing the previous directory from the path. This is done
204 for file paths and host names (in case of VFS paths).
205
206 \param path Path to be cleaned up
207 \return Actual path without any "." or ".."
208 */
209 static std::string GetRealPath(const std::string &path);
210
211 /*!
212 \brief Updates the URL encoded hostname of the given path
213
214 This method must only be used to update paths encoded with
215 the old (Eden) URL encoding implementation to the new (Frodo)
216 URL encoding implementation (which does not URL encode -_.!().
217
218 \param strFilename Path to update
219 \return True if the path has been updated/changed otherwise false
220 */
221 static bool UpdateUrlEncoding(std::string &strFilename);
222
223private:
224 static std::string resolvePath(const std::string &path);
225
226 static const CAdvancedSettings* m_advancedSettings;
227};
228