kodi
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 
21 enum class LanCheckMode
22 {
24  ONLY_LOCAL_SUBNET,
26  ANY_PRIVATE_SUBNET
27 };
28 
29 class URIUtils
30 {
31 public:
32  static void RegisterAdvancedSettings(const CAdvancedSettings& advancedSettings);
33  static void UnregisterAdvancedSettings();
34 
35  static std::string GetDirectory(const std::string &strFilePath);
36 
37  static std::string GetFileName(const CURL& url);
38  static std::string GetFileName(const std::string& strFileNameAndPath);
39  static std::string GetFileOrFolderName(const std::string& path);
40 
41  static std::string GetExtension(const CURL& url);
42  static std::string GetExtension(const std::string& strFileName);
43 
44 
49  static bool HasPluginPath(const CFileItem& item);
50 
58  static bool HasExtension(const std::string& strFileName);
59 
70  static bool HasExtension(const std::string& strFileName, const std::string& strExtensions);
71  static bool HasExtension(const CURL& url, const std::string& strExtensions);
72 
73  static void RemoveExtension(std::string& strFileName);
74  static std::string ReplaceExtension(const std::string& strFile,
75  const std::string& strNewExtension);
76  static void Split(const std::string& strFileNameAndPath,
77  std::string& strPath, std::string& strFileName);
78  static std::vector<std::string> SplitPath(const std::string& strPath);
79 
80  static void GetCommonPath(std::string& strParent, const std::string& strPath);
81  static std::string GetParentPath(const std::string& strPath);
82  static bool GetParentPath(const std::string& strPath, std::string& strParent);
83 
88  static std::string GetBasePath(const std::string& strPath);
89 
90  /* \brief Change the base path of a URL: fromPath/fromFile -> toPath/toFile
91  Handles changes in path separator and filename URL encoding if necessary to derive toFile.
92  \param fromPath the base path of the original URL
93  \param fromFile the filename portion of the original URL
94  \param toPath the base path of the resulting URL
95  \return the full path.
96  */
97  static std::string ChangeBasePath(const std::string &fromPath, const std::string &fromFile, const std::string &toPath, const bool &bAddPath = true);
98 
99  static CURL SubstitutePath(const CURL& url, bool reverse = false);
100  static std::string SubstitutePath(const std::string& strPath, bool reverse = false);
101 
109  static bool IsProtocol(const std::string& url, const std::string& type);
110 
120  static bool PathHasParent(std::string path, std::string parent, bool translate = false);
121 
130  static bool PathEquals(std::string path1, std::string path2, bool ignoreTrailingSlash = false, bool ignoreURLOptions = false);
131 
132  static bool IsAddonsPath(const std::string& strFile);
133  static bool IsSourcesPath(const std::string& strFile);
134  static bool IsCDDA(const std::string& strFile);
135  static bool IsDAV(const std::string& strFile);
136  static bool IsDOSPath(const std::string &path);
137  static bool IsDVD(const std::string& strFile);
138  static bool IsFTP(const std::string& strFile);
139  static bool IsHTTP(const std::string& strFile, bool bTranslate = false);
140  static bool IsUDP(const std::string& strFile);
141  static bool IsTCP(const std::string& strFile);
142  static bool IsHD(const std::string& strFileName);
143  static bool IsInArchive(const std::string& strFile);
144  static bool IsInRAR(const std::string& strFile);
145  static bool IsInternetStream(const std::string& path, bool bStrictCheck = false);
146  static bool IsInternetStream(const CURL& url, bool bStrictCheck = false);
147  static bool IsStreamedFilesystem(const std::string& strPath);
148  static bool IsNetworkFilesystem(const std::string& strPath);
149  static bool IsInAPK(const std::string& strFile);
150  static bool IsInZIP(const std::string& strFile);
151  static bool IsISO9660(const std::string& strFile);
152  static bool IsLiveTV(const std::string& strFile);
153  static bool IsPVRRecording(const std::string& strFile);
154  static bool IsPVRRecordingFileOrFolder(const std::string& strFile);
155  static bool IsPVRTVRecordingFileOrFolder(const std::string& strFile);
156  static bool IsPVRRadioRecordingFileOrFolder(const std::string& strFile);
157  static bool IsMultiPath(const std::string& strPath);
158  static bool IsMusicDb(const std::string& strFile);
159  static bool IsNfs(const std::string& strFile);
160  static bool IsOnDVD(const std::string& strFile);
161  static bool IsOnLAN(const std::string& strFile,
162  LanCheckMode lanCheckMode = LanCheckMode::ONLY_LOCAL_SUBNET);
163  static bool IsHostOnLAN(const std::string& hostName,
164  LanCheckMode lanCheckMode = LanCheckMode::ONLY_LOCAL_SUBNET);
165  static bool IsPlugin(const std::string& strFile);
166  static bool IsScript(const std::string& strFile);
167  static bool IsRAR(const std::string& strFile);
168  static bool IsRemote(const std::string& strFile);
169  static bool IsSmb(const std::string& strFile);
170  static bool IsSpecial(const std::string& strFile);
171  static bool IsStack(const std::string& strFile);
172  static bool IsFavourite(const std::string& strFile);
173  static bool IsUPnP(const std::string& strFile);
174  static bool IsURL(const std::string& strFile);
175  static bool IsVideoDb(const std::string& strFile);
176  static bool IsAPK(const std::string& strFile);
177  static bool IsZIP(const std::string& strFile);
178  static bool IsArchive(const std::string& strFile);
179  static bool IsDiscImage(const std::string& file);
180  static bool IsDiscImageStack(const std::string& file);
181  static bool IsBluray(const std::string& strFile);
182  static bool IsAndroidApp(const std::string& strFile);
183  static bool IsLibraryFolder(const std::string& strFile);
184  static bool IsLibraryContent(const std::string& strFile);
185  static bool IsPVR(const std::string& strFile);
186  static bool IsPVRChannel(const std::string& strFile);
187  static bool IsPVRChannelGroup(const std::string& strFile);
188  static bool IsPVRGuideItem(const std::string& strFile);
189 
190  static std::string AppendSlash(std::string strFolder);
191  static void AddSlashAtEnd(std::string& strFolder);
192  static bool HasSlashAtEnd(const std::string& strFile, bool checkURL = false);
193  static void RemoveSlashAtEnd(std::string& strFolder);
194  static bool CompareWithoutSlashAtEnd(const std::string& strPath1, const std::string& strPath2);
195  static std::string FixSlashesAndDups(const std::string& path, const char slashCharacter = '/', const size_t startFrom = 0);
207  static std::string CanonicalizePath(const std::string& path, const char slashCharacter = '\\');
208 
209  static CURL CreateArchivePath(const std::string& type,
210  const CURL& archiveUrl,
211  const std::string& pathInArchive = "",
212  const std::string& password = "");
213 
214  static std::string AddFileToFolder(const std::string& strFolder, const std::string& strFile);
215  template <typename... T>
216  static std::string AddFileToFolder(const std::string& strFolder, const std::string& strFile, T... args)
217  {
218  auto newPath = AddFileToFolder(strFolder, strFile);
219  return AddFileToFolder(newPath, args...);
220  }
221 
222  static bool HasParentInHostname(const CURL& url);
223  static bool HasEncodedHostname(const CURL& url);
224  static bool HasEncodedFilename(const CURL& url);
225 
238  static std::string GetRealPath(const std::string &path);
239 
250  static bool UpdateUrlEncoding(std::string &strFilename);
251 
252 private:
253  static std::string resolvePath(const std::string &path);
254 
255  static const CAdvancedSettings* m_advancedSettings;
256 };
257 
Definition: URL.h:21
Definition: TestNfsFile.cpp:22
Definition: AdvancedSettings.h:102
Definition: URIUtils.h:29
Represents a file on a share.
Definition: FileItem.h:102