10#include "../AddonBase.h"
11#include "../Filesystem.h"
12#include "../c-api/addon-instance/vfs.h"
85 std::string
GetURL()
const {
return m_cStructure->url; }
89 std::string
GetDomain()
const {
return m_cStructure->domain; }
94 std::string
GetHostname()
const {
return m_cStructure->hostname; }
98 std::string
GetFilename()
const {
return m_cStructure->filename; }
102 unsigned int GetPort()
const {
return m_cStructure->port; }
118 std::string
GetOptions()
const {
return m_cStructure->options; }
121 std::string
GetUsername()
const {
return m_cStructure->username; }
124 std::string
GetPassword()
const {
return m_cStructure->password; }
130 std::string
GetRedacted()
const {
return m_cStructure->redacted; }
140 std::string
GetProtocol()
const {
return m_cStructure->protocol; }
148 VFSUrl(
VFSURL* channel) : CStructHdl(channel) {}
447 if (CPrivateBase::m_interface->globalSingleInstance !=
nullptr)
448 throw std::logic_error(
"kodi::addon::CInstanceVFS: Creation of multiple together with single "
449 "instance way is not allowed!");
451 SetAddonStruct(instance);
804 bool GetKeyboardInput(
const std::string& heading, std::string& input,
bool hiddenInput =
false)
806 char* cInput =
nullptr;
807 bool ret = m_cb->get_keyboard_input(m_cb->ctx, heading.c_str(), &cInput, hiddenInput);
811 ::kodi::addon::CPrivateBase::m_interface->toKodi->free_string(
812 ::kodi::addon::CPrivateBase::m_interface->toKodi->kodiBase, cInput);
826 const std::string& line1,
827 const std::string& line2 =
"",
828 const std::string& line3 =
"")
830 m_cb->set_error_dialog(m_cb->ctx, heading.c_str(), line1.c_str(), line2.c_str(),
840 m_cb->require_authentication(m_cb->ctx, url.c_str());
875 std::vector<kodi::vfs::CDirEntry>& entries,
894 std::vector<kodi::vfs::CDirEntry>& entries,
895 std::string& rootPath)
905 m_instanceData = instance;
906 m_instanceData->hdl =
this;
907 m_instanceData->vfs->toAddon->addonInstance =
this;
908 m_instanceData->vfs->toAddon->open = ADDON_Open;
909 m_instanceData->vfs->toAddon->open_for_write = ADDON_OpenForWrite;
910 m_instanceData->vfs->toAddon->read = ADDON_Read;
911 m_instanceData->vfs->toAddon->write = ADDON_Write;
912 m_instanceData->vfs->toAddon->seek = ADDON_Seek;
913 m_instanceData->vfs->toAddon->truncate = ADDON_Truncate;
914 m_instanceData->vfs->toAddon->get_length = ADDON_GetLength;
915 m_instanceData->vfs->toAddon->get_position = ADDON_GetPosition;
916 m_instanceData->vfs->toAddon->get_chunk_size = ADDON_GetChunkSize;
917 m_instanceData->vfs->toAddon->io_control_get_seek_possible = ADDON_IoControlGetSeekPossible;
918 m_instanceData->vfs->toAddon->io_control_get_cache_status = ADDON_IoControlGetCacheStatus;
919 m_instanceData->vfs->toAddon->io_control_set_cache_rate = ADDON_IoControlSetCacheRate;
920 m_instanceData->vfs->toAddon->io_control_set_retry = ADDON_IoControlSetRetry;
921 m_instanceData->vfs->toAddon->stat = ADDON_Stat;
922 m_instanceData->vfs->toAddon->close = ADDON_Close;
923 m_instanceData->vfs->toAddon->exists = ADDON_Exists;
924 m_instanceData->vfs->toAddon->clear_out_idle = ADDON_ClearOutIdle;
925 m_instanceData->vfs->toAddon->disconnect_all = ADDON_DisconnectAll;
926 m_instanceData->vfs->toAddon->delete_it = ADDON_Delete;
927 m_instanceData->vfs->toAddon->rename = ADDON_Rename;
928 m_instanceData->vfs->toAddon->directory_exists = ADDON_DirectoryExists;
929 m_instanceData->vfs->toAddon->remove_directory = ADDON_RemoveDirectory;
930 m_instanceData->vfs->toAddon->create_directory = ADDON_CreateDirectory;
931 m_instanceData->vfs->toAddon->get_directory = ADDON_GetDirectory;
932 m_instanceData->vfs->toAddon->free_directory = ADDON_FreeDirectory;
933 m_instanceData->vfs->toAddon->contains_files = ADDON_ContainsFiles;
939 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Open(url);
946 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
947 ->OpenForWrite(url, overWrite);
951 VFS_FILE_HANDLE context,
955 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
956 ->Read(context, buffer, uiBufSize);
960 VFS_FILE_HANDLE context,
961 const uint8_t* buffer,
964 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
965 ->Write(context, buffer, uiBufSize);
969 VFS_FILE_HANDLE context,
973 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
974 ->Seek(context, position, whence);
978 VFS_FILE_HANDLE context,
981 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Truncate(context, size);
985 VFS_FILE_HANDLE context)
987 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->GetLength(context);
991 VFS_FILE_HANDLE context)
993 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->GetPosition(context);
997 VFS_FILE_HANDLE context)
999 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
GetChunkSize(context);
1003 VFS_FILE_HANDLE context)
1005 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1006 ->IoControlGetSeekPossible(context);
1010 VFS_FILE_HANDLE context,
1014 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1015 ->IoControlGetCacheStatus(context, cppStatus);
1019 VFS_FILE_HANDLE context,
1022 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1023 ->IoControlSetCacheRate(context, rate);
1027 VFS_FILE_HANDLE context,
1030 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1031 ->IoControlSetRetry(context, retry);
1039 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Stat(url, cppBuffer);
1044 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Close(context);
1049 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Exists(url);
1054 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->ClearOutIdle();
1059 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->DisconnectAll();
1064 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Delete(url);
1071 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Rename(url, url2);
1077 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
DirectoryExists(url);
1083 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
RemoveDirectory(url);
1089 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
CreateDirectory(url);
1098 std::vector<kodi::vfs::CDirEntry> addonEntries;
1099 bool ret =
static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1100 ->
GetDirectory(url, addonEntries, CVFSCallbacks(callbacks));
1105 for (
unsigned int i = 0; i < addonEntries.size(); ++i)
1107 entries[i].
label = strdup(addonEntries[i].Label().c_str());
1108 entries[i].
title = strdup(addonEntries[i].Title().c_str());
1109 entries[i].
path = strdup(addonEntries[i].Path().c_str());
1110 entries[i].
folder = addonEntries[i].IsFolder();
1111 entries[i].
size = addonEntries[i].Size();
1112 entries[i].
date_time = addonEntries[i].DateTime();
1115 const std::map<std::string, std::string>& props = addonEntries[i].GetProperties();
1120 for (
const auto& prop : props)
1130 *retEntries = entries;
1131 *num_entries =
static_cast<int>(addonEntries.size());
1140 for (
int i = 0; i < num_entries; ++i)
1142 if (entries[i].properties)
1144 for (
unsigned int j = 0; j < entries[i].
num_props; ++j)
1146 free(entries[i].properties[j].name);
1147 free(entries[i].properties[j].val);
1149 free(entries[i].properties);
1151 free(entries[i].label);
1152 free(entries[i].title);
1153 free(entries[i].path);
1164 std::string cppRootPath;
1165 std::vector<kodi::vfs::CDirEntry> addonEntries;
1166 bool ret =
static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1167 ->ContainsFiles(url, addonEntries, cppRootPath);
1170 strncpy(rootpath, cppRootPath.c_str(), ADDON_STANDARD_STRING_LENGTH);
1174 for (
size_t i = 0; i < addonEntries.size(); ++i)
1176 entries[i].
label = strdup(addonEntries[i].Label().c_str());
1177 entries[i].
title = strdup(addonEntries[i].Title().c_str());
1178 entries[i].
path = strdup(addonEntries[i].Path().c_str());
1179 entries[i].
folder = addonEntries[i].IsFolder();
1180 entries[i].
size = addonEntries[i].Size();
1181 entries[i].
date_time = addonEntries[i].DateTime();
1184 const std::map<std::string, std::string>& props = addonEntries[i].GetProperties();
1189 for (
const auto& prop : props)
1199 *retEntries = entries;
1200 *num_entries =
static_cast<int>(addonEntries.size());
Definition AddonBase.h:206
Definition AddonBase.h:565
Definition AddonBase.h:498
Definition Filesystem.h:229
Definition Filesystem.h:96
std::string GetFilename() const
With this variable the desired path to a folder or file within the hostname is given (e....
Definition VFS.h:98
std::string GetHostname() const
This includes the network address (e.g. 192.168.0.123) or if the addon refers to file packages the pa...
Definition VFS.h:94
std::string GetSharename() const
The name which is taken as the basis by source and would be first in folder view.
Definition VFS.h:137
std::string GetOptions() const
Special options on opened URL, this can e.g. on RAR packages ?flags=8&nextvalue=123 to inform about t...
Definition VFS.h:118
std::string GetPassword() const
Desired password.
Definition VFS.h:124
std::string GetURL() const
Desired URL of the file system to be edited.
Definition VFS.h:85
std::string GetProtocol() const
Protocol name used on this stream, e.g. sftp.
Definition VFS.h:140
std::string GetRedacted() const
The complete URL is passed on here, but the user name and password are not shown and only appear to t...
Definition VFS.h:130
unsigned int GetPort() const
Networking port to use for protocol.
Definition VFS.h:102
std::string GetUsername() const
Desired username.
Definition VFS.h:121
std::string GetDomain() const
The associated domain name, which is optional and not available in all cases.
Definition VFS.h:89
VFS_FILE_HANDLE VFSFileHandle
VFS add-on file handle This used to handle opened files of addon with related memory pointer about cl...
Definition VFS.h:33
virtual kodi::addon::VFSFileHandle Open(const kodi::addon::VFSUrl &url)
Open a file for input.
Definition VFS.h:493
virtual bool IoControlGetCacheStatus(kodi::addon::VFSFileHandle context, kodi::vfs::CacheStatus &status)
To check a running stream on file for state of his cache.
Definition VFS.h:630
virtual ssize_t Read(kodi::addon::VFSFileHandle context, uint8_t *buffer, size_t uiBufSize)
Read from a file.
Definition VFS.h:529
virtual int64_t Seek(kodi::addon::VFSFileHandle context, int64_t position, int whence)
Seek in a file.
Definition VFS.h:564
virtual int Truncate(kodi::addon::VFSFileHandle context, int64_t size)
Truncate a file.
Definition VFS.h:578
virtual int GetChunkSize(kodi::addon::VFSFileHandle context)
Get chunk size of a file.
Definition VFS.h:608
virtual int64_t GetPosition(kodi::addon::VFSFileHandle context)
Get current position in a file.
Definition VFS.h:598
virtual ssize_t Write(kodi::addon::VFSFileHandle context, const uint8_t *buffer, size_t uiBufSize)
Write to a file.
Definition VFS.h:544
virtual bool IoControlGetSeekPossible(kodi::addon::VFSFileHandle context)
To check seek possible on current stream by file.
Definition VFS.h:617
virtual bool IoControlSetCacheRate(kodi::addon::VFSFileHandle context, uint32_t rate)
Unsigned int with speed limit for caching in bytes per second.
Definition VFS.h:644
virtual bool Close(kodi::addon::VFSFileHandle context)
Close a file.
Definition VFS.h:517
virtual bool IoControlSetRetry(kodi::addon::VFSFileHandle context, bool retry)
Enable/disable retry within the protocol handler (if supported).
Definition VFS.h:657
virtual int64_t GetLength(kodi::addon::VFSFileHandle context)
Get total size of a file.
Definition VFS.h:588
virtual kodi::addon::VFSFileHandle OpenForWrite(const kodi::addon::VFSUrl &url, bool overWrite)
Open a file for output.
Definition VFS.h:504
void SetErrorDialog(const std::string &heading, const std::string &line1, const std::string &line2="", const std::string &line3="")
Display an error dialog.
Definition VFS.h:825
bool GetKeyboardInput(const std::string &heading, std::string &input, bool hiddenInput=false)
Require keyboard input.
Definition VFS.h:804
void RequireAuthentication(const std::string &url)
Prompt the user for authentication of a URL.
Definition VFS.h:838
virtual void ClearOutIdle()
Clear out any idle connections.
Definition VFS.h:692
virtual int Stat(const kodi::addon::VFSUrl &url, kodi::vfs::FileStatus &buffer)
Stat a file.
Definition VFS.h:675
virtual bool RemoveDirectory(const kodi::addon::VFSUrl &url)
Remove a directory.
Definition VFS.h:743
virtual void DisconnectAll()
Disconnect all connections.
Definition VFS.h:699
virtual bool ContainsFiles(const kodi::addon::VFSUrl &url, std::vector< kodi::vfs::CDirEntry > &entries, std::string &rootPath)
Check if file should be presented as a directory (multiple streams)
Definition VFS.h:893
virtual bool CreateDirectory(const kodi::addon::VFSUrl &url)
Create a directory.
Definition VFS.h:753
virtual bool GetDirectory(const kodi::addon::VFSUrl &url, std::vector< kodi::vfs::CDirEntry > &entries, CVFSCallbacks callbacks)
List a directory.
Definition VFS.h:874
virtual bool Delete(const kodi::addon::VFSUrl &url)
Delete a file.
Definition VFS.h:709
virtual bool Exists(const kodi::addon::VFSUrl &url)
Check for file existence.
Definition VFS.h:685
virtual bool DirectoryExists(const kodi::addon::VFSUrl &url)
Check for directory existence.
Definition VFS.h:733
virtual bool Rename(const kodi::addon::VFSUrl &url, const kodi::addon::VFSUrl &url2)
Rename a file.
Definition VFS.h:720
CInstanceVFS(const IInstanceInfo &instance)
VFS class constructor used to support multiple instance types.
Definition VFS.h:445
~CInstanceVFS() override=default
Destructor.
bool ATTR_DLL_LOCAL CreateDirectory(const std::string &path)
Make a directory.
Definition Filesystem.h:778
bool ATTR_DLL_LOCAL RemoveDirectory(const std::string &path, bool recursive=false)
Removes a directory.
Definition Filesystem.h:844
bool ATTR_DLL_LOCAL GetDirectory(const std::string &path, const std::string &mask, std::vector< kodi::vfs::CDirEntry > &items)
Lists a directory.
Definition Filesystem.h:893
bool ATTR_DLL_LOCAL DirectoryExists(const std::string &path)
Verifying the Existence of a Directory.
Definition Filesystem.h:810
unsigned int ATTR_DLL_LOCAL GetChunkSize(unsigned int chunk, unsigned int minimum)
Return a size aligned to the chunk size at least as large as the chunk size.
Definition Filesystem.h:1458
Definition addon_base.h:268
Definition filesystem.h:198
Definition filesystem.h:229
Definition filesystem.h:243
struct VFSProperty * properties
Properties.
Definition filesystem.h:248
char * path
item path
Definition filesystem.h:246
time_t date_time
file creation date & time
Definition filesystem.h:249
unsigned int num_props
Number of properties attached to item.
Definition filesystem.h:247
bool folder
Item is a folder.
Definition filesystem.h:250
char * label
item label
Definition filesystem.h:244
char * title
item title
Definition filesystem.h:245
uint64_t size
Size of file represented by item.
Definition filesystem.h:251
Definition filesystem.h:237