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