xbmc
VFSEntry.h
1 /*
2  * Copyright (C) 2013 Arne Morten Kvarving
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  * See LICENSES/README.md for more information.
6  */
7 
8 #pragma once
9 
10 #include "FileItem.h"
11 #include "addons/binary-addons/AddonDll.h"
12 #include "addons/binary-addons/AddonInstanceHandler.h"
13 #include "addons/kodi-dev-kit/include/kodi/addon-instance/VFS.h"
14 #include "filesystem/IDirectory.h"
15 #include "filesystem/IFile.h"
16 #include "filesystem/IFileDirectory.h"
17 
18 #include <utility>
19 
20 namespace ADDON
21 {
22 struct AddonEvent;
23 
24 class CVFSEntry;
25 typedef std::shared_ptr<CVFSEntry> VFSEntryPtr;
26 
28 {
29 public:
30  virtual ~CVFSAddonCache();
31  void Init();
32  void Deinit();
33  const std::vector<VFSEntryPtr> GetAddonInstances();
34  VFSEntryPtr GetAddonInstance(const std::string& strId);
35 
36 protected:
37  void Update(const std::string& id);
38  void OnEvent(const AddonEvent& event);
39  bool IsInUse(const std::string& id) override;
40 
41  CCriticalSection m_critSection;
42  std::vector<VFSEntryPtr> m_addonsInstances;
43 };
44 
47  {
48  public:
50  struct ProtocolInfo
51  {
52  bool supportPath;
55  bool supportPort;
57  bool supportWrite;
59  std::string type;
60  int label;
61 
63  ProtocolInfo(const AddonInfoPtr& addonInfo);
64  };
65 
68  explicit CVFSEntry(const AddonInfoPtr& addonInfo);
69  ~CVFSEntry() override;
70 
71  // Things that MUST be supplied by the child classes
72  void* Open(const CURL& url);
73  void* OpenForWrite(const CURL& url, bool bOverWrite);
74  bool Exists(const CURL& url);
75  int Stat(const CURL& url, struct __stat64* buffer);
76  ssize_t Read(void* ctx, void* lpBuf, size_t uiBufSize);
77  ssize_t Write(void* ctx, const void* lpBuf, size_t uiBufSize);
78  int64_t Seek(void* ctx, int64_t iFilePosition, int iWhence = SEEK_SET);
79  int Truncate(void* ctx, int64_t size);
80  void Close(void* ctx);
81  int64_t GetPosition(void* ctx);
82  int64_t GetLength(void* ctx);
83  int GetChunkSize(void* ctx);
84  int IoControl(void* ctx, XFILE::EIoControl request, void* param);
85  bool Delete(const CURL& url);
86  bool Rename(const CURL& url, const CURL& url2);
87 
88  bool GetDirectory(const CURL& url, CFileItemList& items, void* ctx);
89  bool DirectoryExists(const CURL& url);
90  bool RemoveDirectory(const CURL& url);
91  bool CreateDirectory(const CURL& url);
92  void ClearOutIdle();
93  void DisconnectAll();
94 
95  bool ContainsFiles(const CURL& url, CFileItemList& items);
96 
97  const std::string& GetProtocols() const { return m_protocols; }
98  const std::string& GetExtensions() const { return m_extensions; }
99  bool HasFiles() const { return m_files; }
100  bool HasDirectories() const { return m_directories; }
101  bool HasFileDirectories() const { return m_filedirectories; }
102  const std::string& GetZeroconfType() const { return m_zeroconf; }
103  const ProtocolInfo& GetProtocolInfo() const { return m_protocolInfo; }
104  protected:
105  std::string m_protocols;
106  std::string m_extensions;
107  std::string m_zeroconf;
108  bool m_files;
112  };
113 
118  {
119  public:
122  explicit CVFSEntryIFileWrapper(VFSEntryPtr ptr);
123 
125  ~CVFSEntryIFileWrapper() override;
126 
130  bool Open(const CURL& url) override;
131 
136  bool OpenForWrite(const CURL& url, bool bOverWrite) override;
137 
140  bool Exists(const CURL& url) override;
141 
146  int Stat(const CURL& url, struct __stat64* buffer) override;
147 
152  ssize_t Read(void* lpBuf, size_t uiBufSize) override;
153 
158  ssize_t Write(const void* lpBuf, size_t uiBufSize) override;
159 
164  int64_t Seek(int64_t iFilePosition, int whence = SEEK_SET) override;
165 
168  int Truncate(int64_t size) override;
169 
171  void Close() override;
172 
174  int64_t GetPosition() override;
175 
177  int64_t GetLength() override;
178 
180  int GetChunkSize() override;
181 
183  int IoControl(XFILE::EIoControl request, void* param) override;
184 
187  bool Delete(const CURL& url) override;
188 
192  bool Rename(const CURL& url, const CURL& url2) override;
193  protected:
194  void* m_context;
195  VFSEntryPtr m_addon;
196  };
197 
202  {
203  public:
206  explicit CVFSEntryIDirectoryWrapper(VFSEntryPtr ptr);
207 
209  ~CVFSEntryIDirectoryWrapper() override = default;
210 
215  bool GetDirectory(const CURL& url, CFileItemList& items) override;
216 
219  bool Exists(const CURL& url) override;
220 
223  bool Remove(const CURL& url) override;
224 
227  bool Create(const CURL& url) override;
228 
230  static bool DoGetKeyboardInput(void* context, const char* heading,
231  char** input, bool hidden_input);
232 
234  bool GetKeyboardInput2(const char* heading, char** input, bool hidden_input);
235 
237  static void DoSetErrorDialog(void* ctx, const char* heading,
238  const char* line1, const char* line2,
239  const char* line3);
240 
242  void SetErrorDialog2(const char* heading, const char* line1,
243  const char* line2, const char* line3);
244 
246  static void DoRequireAuthentication(void* ctx, const char* url);
247 
249  void RequireAuthentication2(const CURL& url);
250  protected:
251  VFSEntryPtr m_addon;
252  };
253 
259  {
260  public:
263  explicit CVFSEntryIFileDirectoryWrapper(VFSEntryPtr ptr)
264  : CVFSEntryIDirectoryWrapper(std::move(ptr))
265  {
266  }
267 
269  ~CVFSEntryIFileDirectoryWrapper() override = default;
270 
273  bool ContainsFiles(const CURL& url) override
274  {
275  return m_addon->ContainsFiles(url, m_items);
276  }
277 
282  bool GetDirectory(const CURL& url, CFileItemList& items) override
283  {
284  return CVFSEntryIDirectoryWrapper::GetDirectory(url, items);
285  }
286 
289  bool Exists(const CURL& url) override
290  {
292  }
293 
296  bool Remove(const CURL& url) override
297  {
299  }
300 
303  bool Create(const CURL& url) override
304  {
306  }
307 
309  };
310 
311 } /*namespace ADDON*/
std::string m_protocols
Protocols for VFS entry.
Definition: VFSEntry.h:105
bool m_directories
VFS entry can list directories.
Definition: VFSEntry.h:109
Interface to the directory on a file system.
Definition: IDirectory.h:50
bool m_filedirectories
VFS entry contains file directories.
Definition: VFSEntry.h:110
std::string type
URL type for protocol.
Definition: VFSEntry.h:59
Wrapper equpping a CVFSEntry with an IFileDirectory interface.
Definition: VFSEntry.h:257
A virtual filesystem entry add-on.
Definition: VFSEntry.h:46
int defaultPort
Default port to use for protocol.
Definition: VFSEntry.h:58
Represents a list of files.
Definition: FileItem.h:713
Definition: URL.h:20
bool Exists(const CURL &url) override
Check if directory exists.
Definition: VFSEntry.h:289
int label
String ID to use as label in dialog.
Definition: VFSEntry.h:60
bool GetDirectory(const CURL &url, CFileItemList &items) override
Return directory listing.
Definition: VFSEntry.cpp:706
Information class for use on addon type managers.
Definition: AddonDll.h:43
CVFSEntryIFileDirectoryWrapper(VFSEntryPtr ptr)
The constructor initializes the reference to the wrapped CVFSEntry.
Definition: VFSEntry.h:263
Definition: IFile.h:42
CFileItemList m_items
Internal list of items, used for cache purposes.
Definition: VFSEntry.h:308
bool supportPort
Protocol supports port customization.
Definition: VFSEntry.h:55
bool supportPassword
Protocol supports passwords.
Definition: VFSEntry.h:54
bool Exists(const CURL &url) override
Check if directory exists.
Definition: VFSEntry.cpp:691
A structure encapsulating properties of supplied protocol.
Definition: VFSEntry.h:50
Definition: AddonInstanceHandler.h:33
Wrapper equipping a CVFSEntry with an IFile interface.
Definition: VFSEntry.h:117
std::string m_extensions
Extensions for VFS entry.
Definition: VFSEntry.h:106
VFSEntryPtr m_addon
Pointer to wrapper CVFSEntry.
Definition: VFSEntry.h:251
ProtocolInfo m_protocolInfo
Info about protocol for network dialog.
Definition: VFSEntry.h:111
bool supportWrite
Protocol supports write operations.
Definition: VFSEntry.h:57
bool Remove(const CURL &url) override
Delete directory.
Definition: VFSEntry.h:296
Definition: AddonEvents.h:18
bool m_files
Vfs entry can read files.
Definition: VFSEntry.h:108
VFSEntryPtr m_addon
Pointer to wrapped CVFSEntry.
Definition: VFSEntry.h:195
bool supportUsername
Protocol uses logins.
Definition: VFSEntry.h:53
std::string m_zeroconf
Zero conf announce string for VFS protocol.
Definition: VFSEntry.h:107
bool GetDirectory(const CURL &url, CFileItemList &items) override
Return directory listing.
Definition: VFSEntry.h:282
Wrapper equpping a CVFSEntry with an IDirectory interface.
Definition: VFSEntry.h:201
Definition: IFileDirectory.h:15
bool Remove(const CURL &url) override
Delete directory.
Definition: VFSEntry.cpp:696
void * m_context
Opaque add-on specific context for opened file.
Definition: VFSEntry.h:194
bool supportBrowsing
Protocol supports server browsing.
Definition: VFSEntry.h:56
bool supportPath
Protocol has path in addition to server name.
Definition: VFSEntry.h:52
Definition: Addon.cpp:39
Definition: VFSEntry.h:27
bool Create(const CURL &url) override
Create directory.
Definition: VFSEntry.h:303
bool ContainsFiles(const CURL &url) override
Check if the given file should be treated as a directory.
Definition: VFSEntry.h:273
bool Create(const CURL &url) override
Create directory.
Definition: VFSEntry.cpp:701