xbmc
URIUtils.h
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 
14 class CURL;
15 class CAdvancedSettings;
16 class CFileItem;
17 
18 class URIUtils
19 {
20 public:
21  static void RegisterAdvancedSettings(const CAdvancedSettings& advancedSettings);
22  static void UnregisterAdvancedSettings();
23 
24  static std::string GetDirectory(const std::string &strFilePath);
25 
26  static std::string GetFileName(const CURL& url);
27  static std::string GetFileName(const std::string& strFileNameAndPath);
28 
29  static std::string GetExtension(const CURL& url);
30  static std::string GetExtension(const std::string& strFileName);
31 
32 
37  static bool HasPluginPath(const CFileItem& item);
38 
46  static bool HasExtension(const std::string& strFileName);
47 
58  static bool HasExtension(const std::string& strFileName, const std::string& strExtensions);
59  static bool HasExtension(const CURL& url, const std::string& strExtensions);
60 
61  static void RemoveExtension(std::string& strFileName);
62  static std::string ReplaceExtension(const std::string& strFile,
63  const std::string& strNewExtension);
64  static void Split(const std::string& strFileNameAndPath,
65  std::string& strPath, std::string& strFileName);
66  static std::vector<std::string> SplitPath(const std::string& strPath);
67 
68  static void GetCommonPath(std::string& strParent, const std::string& strPath);
69  static std::string GetParentPath(const std::string& strPath);
70  static bool GetParentPath(const std::string& strPath, std::string& strParent);
71 
76  static std::string GetBasePath(const std::string& strPath);
77 
78  /* \brief Change the base path of a URL: fromPath/fromFile -> toPath/toFile
79  Handles changes in path separator and filename URL encoding if necessary to derive toFile.
80  \param fromPath the base path of the original URL
81  \param fromFile the filename portion of the original URL
82  \param toPath the base path of the resulting URL
83  \return the full path.
84  */
85  static std::string ChangeBasePath(const std::string &fromPath, const std::string &fromFile, const std::string &toPath, const bool &bAddPath = true);
86 
87  static CURL SubstitutePath(const CURL& url, bool reverse = false);
88  static std::string SubstitutePath(const std::string& strPath, bool reverse = false);
89 
97  static bool IsProtocol(const std::string& url, const std::string& type);
98 
108  static bool PathHasParent(std::string path, std::string parent, bool translate = false);
109 
118  static bool PathEquals(std::string path1, std::string path2, bool ignoreTrailingSlash = false, bool ignoreURLOptions = false);
119 
120  static bool IsAddonsPath(const std::string& strFile);
121  static bool IsSourcesPath(const std::string& strFile);
122  static bool IsCDDA(const std::string& strFile);
123  static bool IsDAV(const std::string& strFile);
124  static bool IsDOSPath(const std::string &path);
125  static bool IsDVD(const std::string& strFile);
126  static bool IsFTP(const std::string& strFile);
127  static bool IsHTTP(const std::string& strFile, bool bTranslate = false);
128  static bool IsUDP(const std::string& strFile);
129  static bool IsTCP(const std::string& strFile);
130  static bool IsHD(const std::string& strFileName);
131  static bool IsInArchive(const std::string& strFile);
132  static bool IsInRAR(const std::string& strFile);
133  static bool IsInternetStream(const std::string& path, bool bStrictCheck = false);
134  static bool IsInternetStream(const CURL& url, bool bStrictCheck = false);
135  static bool IsStreamedFilesystem(const std::string& strPath);
136  static bool IsNetworkFilesystem(const std::string& strPath);
137  static bool IsInAPK(const std::string& strFile);
138  static bool IsInZIP(const std::string& strFile);
139  static bool IsISO9660(const std::string& strFile);
140  static bool IsLiveTV(const std::string& strFile);
141  static bool IsPVRRecording(const std::string& strFile);
142  static bool IsPVRRecordingFileOrFolder(const std::string& strFile);
143  static bool IsPVRTVRecordingFileOrFolder(const std::string& strFile);
144  static bool IsPVRRadioRecordingFileOrFolder(const std::string& strFile);
145  static bool IsMultiPath(const std::string& strPath);
146  static bool IsMusicDb(const std::string& strFile);
147  static bool IsNfs(const std::string& strFile);
148  static bool IsOnDVD(const std::string& strFile);
149  static bool IsOnLAN(const std::string& strFile);
150  static bool IsHostOnLAN(const std::string& hostName, bool offLineCheck = false);
151  static bool IsPlugin(const std::string& strFile);
152  static bool IsScript(const std::string& strFile);
153  static bool IsRAR(const std::string& strFile);
154  static bool IsRemote(const std::string& strFile);
155  static bool IsSmb(const std::string& strFile);
156  static bool IsSpecial(const std::string& strFile);
157  static bool IsStack(const std::string& strFile);
158  static bool IsFavourite(const std::string& strFile);
159  static bool IsUPnP(const std::string& strFile);
160  static bool IsURL(const std::string& strFile);
161  static bool IsVideoDb(const std::string& strFile);
162  static bool IsAPK(const std::string& strFile);
163  static bool IsZIP(const std::string& strFile);
164  static bool IsArchive(const std::string& strFile);
165  static bool IsBluray(const std::string& strFile);
166  static bool IsAndroidApp(const std::string& strFile);
167  static bool IsLibraryFolder(const std::string& strFile);
168  static bool IsLibraryContent(const std::string& strFile);
169  static bool IsPVR(const std::string& strFile);
170  static bool IsPVRChannel(const std::string& strFile);
171  static bool IsPVRChannelGroup(const std::string& strFile);
172  static bool IsPVRGuideItem(const std::string& strFile);
173 
174  static std::string AppendSlash(std::string strFolder);
175  static void AddSlashAtEnd(std::string& strFolder);
176  static bool HasSlashAtEnd(const std::string& strFile, bool checkURL = false);
177  static void RemoveSlashAtEnd(std::string& strFolder);
178  static bool CompareWithoutSlashAtEnd(const std::string& strPath1, const std::string& strPath2);
179  static std::string FixSlashesAndDups(const std::string& path, const char slashCharacter = '/', const size_t startFrom = 0);
191  static std::string CanonicalizePath(const std::string& path, const char slashCharacter = '\\');
192 
193  static CURL CreateArchivePath(const std::string& type,
194  const CURL& archiveUrl,
195  const std::string& pathInArchive = "",
196  const std::string& password = "");
197 
198  static std::string AddFileToFolder(const std::string& strFolder, const std::string& strFile);
199  template <typename... T>
200  static std::string AddFileToFolder(const std::string& strFolder, const std::string& strFile, T... args)
201  {
202  auto newPath = AddFileToFolder(strFolder, strFile);
203  return AddFileToFolder(newPath, args...);
204  }
205 
206  static bool HasParentInHostname(const CURL& url);
207  static bool HasEncodedHostname(const CURL& url);
208  static bool HasEncodedFilename(const CURL& url);
209 
222  static std::string GetRealPath(const std::string &path);
223 
234  static bool UpdateUrlEncoding(std::string &strFilename);
235 
236 private:
237  static std::string resolvePath(const std::string &path);
238 
239  static const CAdvancedSettings* m_advancedSettings;
240 };
241 
static std::string GetRealPath(const std::string &path)
Cleans up the given path by resolving "." and ".." and returns it.
Definition: URIUtils.cpp:1397
Definition: URL.h:20
static bool PathEquals(std::string path1, std::string path2, bool ignoreTrailingSlash=false, bool ignoreURLOptions=false)
Check whether a path equals another path. Comparison is case-sensitive.
Definition: URIUtils.cpp:551
Definition: TestNfsFile.cpp:22
static bool PathHasParent(std::string path, std::string parent, bool translate=false)
Check whether a path has a given parent. Comparison is case-sensitive. Use IsProtocol() to compare th...
Definition: URIUtils.cpp:531
static bool IsProtocol(const std::string &url, const std::string &type)
Check whether a URL is a given URL scheme. Comparison is case-insensitive as per RFC1738.
Definition: URIUtils.cpp:526
static bool HasPluginPath(const CFileItem &item)
Check if the CFileItem has a plugin path.
Definition: URIUtils.cpp:69
static std::string GetBasePath(const std::string &strPath)
Retrieve the base path, accounting for stacks and files in rars.
Definition: URIUtils.cpp:421
static bool IsStreamedFilesystem(const std::string &strPath)
Definition: URIUtils.cpp:1041
Definition: AdvancedSettings.h:107
static std::string CanonicalizePath(const std::string &path, const char slashCharacter='\\')
Convert path to form without duplicated slashes and without relative directories Strip duplicated sla...
Definition: URIUtils.cpp:1293
Definition: URIUtils.h:18
static bool HasExtension(const std::string &strFileName)
Check if there is a file extension.
Definition: URIUtils.cpp:74
static bool UpdateUrlEncoding(std::string &strFilename)
Updates the URL encoded hostname of the given path.
Definition: URIUtils.cpp:1455
Represents a file on a share.
Definition: FileItem.h:102