Kodi Development  19.0
for Binary and Script based Add-Ons
filesystem.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 #ifndef C_API_FILESYSTEM_H
12 #define C_API_FILESYSTEM_H
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 #include <time.h>
17 
18 #ifdef _WIN32 // windows
19 #ifndef _SSIZE_T_DEFINED
20 typedef intptr_t ssize_t;
21 #define _SSIZE_T_DEFINED
22 #endif // !_SSIZE_T_DEFINED
23 
24 // Prevent conflicts with Windows macros where have this names.
25 #ifdef CreateDirectory
26 #undef CreateDirectory
27 #endif // CreateDirectory
28 #ifdef DeleteFile
29 #undef DeleteFile
30 #endif // DeleteFile
31 #ifdef RemoveDirectory
32 #undef RemoveDirectory
33 #endif // RemoveDirectory
34 #endif // _WIN32
35 
36 #ifdef TARGET_POSIX // Linux, Mac, FreeBSD
37 #include <sys/types.h>
38 #endif // TARGET_POSIX
39 
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif /* __cplusplus */
44 
45  //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
46  // "C" Definitions, structures and enumerators of filesystem
47  //{{{
48 
49  //============================================================================
58  typedef enum OpenFileFlags
59  {
64 
69 
73 
77 
81 
86 
91 
95 
98  ADDON_READ_REOPEN = 0x100
101  //----------------------------------------------------------------------------
102 
103  //============================================================================
109 
110  typedef enum CURLOptiontype
111  {
113  ADDON_CURL_OPTION_OPTION,
114 
135  ADDON_CURL_OPTION_PROTOCOL,
136 
138  ADDON_CURL_OPTION_CREDENTIALS,
139 
141  ADDON_CURL_OPTION_HEADER
142  } CURLOptiontype;
144  //----------------------------------------------------------------------------
145 
146  //============================================================================
154 
155  typedef enum FilePropertyTypes
156  {
158  ADDON_FILE_PROPERTY_RESPONSE_PROTOCOL,
160  ADDON_FILE_PROPERTY_RESPONSE_HEADER,
162  ADDON_FILE_PROPERTY_CONTENT_TYPE,
164  ADDON_FILE_PROPERTY_CONTENT_CHARSET,
166  ADDON_FILE_PROPERTY_MIME_TYPE,
168  ADDON_FILE_PROPERTY_EFFECTIVE_URL
169  } FilePropertyTypes;
171  //----------------------------------------------------------------------------
172 
173  //}}}
174 
175  //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
176  // "C" Internal interface tables for intercommunications between addon and kodi
177  //{{{
178 
180  {
181  void* handle;
182 
183  char* (*get_value)(void* kodiBase, void* handle, const char* param);
184  char** (*get_values)(void* kodiBase, void* handle, const char* param, int* length);
185  char* (*get_header)(void* kodiBase, void* handle);
186  char* (*get_mime_type)(void* kodiBase, void* handle);
187  char* (*get_charset)(void* kodiBase, void* handle);
188  char* (*get_proto_line)(void* kodiBase, void* handle);
189  };
190 
192  {
194  uint32_t deviceId;
196  uint64_t size;
198  time_t accessTime;
202  time_t statusTime;
206  bool isSymLink;
208  bool isBlock;
212  bool isFifo;
214  bool isRegular;
216  bool isSocket;
220  };
221 
223  {
224  uint64_t forward;
225  unsigned int maxrate;
226  unsigned int currate;
227  bool lowspeed;
228  };
229 
230  struct VFSProperty
231  {
232  char* name;
233  char* val;
234  };
235 
236  struct VFSDirEntry
237  {
238  char* label;
239  char* title;
240  char* path;
241  unsigned int num_props;
243  time_t date_time;
244  bool folder;
245  uint64_t size;
246  };
247 
249  {
250  bool (*can_open_directory)(void* kodiBase, const char* url);
251  bool (*create_directory)(void* kodiBase, const char* path);
252  bool (*remove_directory)(void* kodiBase, const char* path);
253  bool (*directory_exists)(void* kodiBase, const char* path);
254  bool (*get_directory)(void* kodiBase,
255  const char* path,
256  const char* mask,
257  struct VFSDirEntry** items,
258  unsigned int* num_items);
259  void (*free_directory)(void* kodiBase, struct VFSDirEntry* items, unsigned int num_items);
260 
261  bool (*file_exists)(void* kodiBase, const char* filename, bool useCache);
262  bool (*stat_file)(void* kodiBase, const char* filename, struct STAT_STRUCTURE* buffer);
263  bool (*delete_file)(void* kodiBase, const char* filename);
264  bool (*rename_file)(void* kodiBase, const char* filename, const char* newFileName);
265  bool (*copy_file)(void* kodiBase, const char* filename, const char* dest);
266 
267  char* (*get_file_md5)(void* kodiBase, const char* filename);
268  char* (*get_cache_thumb_name)(void* kodiBase, const char* filename);
269  char* (*make_legal_filename)(void* kodiBase, const char* filename);
270  char* (*make_legal_path)(void* kodiBase, const char* path);
271  char* (*translate_special_protocol)(void* kodiBase, const char* strSource);
272  bool (*is_internet_stream)(void* kodiBase, const char* path, bool strictCheck);
273  bool (*is_on_lan)(void* kodiBase, const char* path);
274  bool (*is_remote)(void* kodiBase, const char* path);
275  bool (*is_local)(void* kodiBase, const char* path);
276  bool (*is_url)(void* kodiBase, const char* path);
277  bool (*get_http_header)(void* kodiBase, const char* url, struct KODI_HTTP_HEADER* headers);
278  bool (*get_mime_type)(void* kodiBase, const char* url, char** content, const char* useragent);
279  bool (*get_content_type)(void* kodiBase,
280  const char* url,
281  char** content,
282  const char* useragent);
283  bool (*get_cookies)(void* kodiBase, const char* url, char** cookies);
284  bool (*http_header_create)(void* kodiBase, struct KODI_HTTP_HEADER* headers);
285  void (*http_header_free)(void* kodiBase, struct KODI_HTTP_HEADER* headers);
286 
287  void* (*open_file)(void* kodiBase, const char* filename, unsigned int flags);
288  void* (*open_file_for_write)(void* kodiBase, const char* filename, bool overwrite);
289  ssize_t (*read_file)(void* kodiBase, void* file, void* ptr, size_t size);
290  bool (*read_file_string)(void* kodiBase, void* file, char* szLine, int iLineLength);
291  ssize_t (*write_file)(void* kodiBase, void* file, const void* ptr, size_t size);
292  void (*flush_file)(void* kodiBase, void* file);
293  int64_t (*seek_file)(void* kodiBase, void* file, int64_t position, int whence);
294  int (*truncate_file)(void* kodiBase, void* file, int64_t size);
295  int64_t (*get_file_position)(void* kodiBase, void* file);
296  int64_t (*get_file_length)(void* kodiBase, void* file);
297  double (*get_file_download_speed)(void* kodiBase, void* file);
298  void (*close_file)(void* kodiBase, void* file);
299  int (*get_file_chunk_size)(void* kodiBase, void* file);
300  bool (*io_control_get_seek_possible)(void* kodiBase, void* file);
301  bool (*io_control_get_cache_status)(void* kodiBase,
302  void* file,
303  struct VFS_CACHE_STATUS_DATA* status);
304  bool (*io_control_set_cache_rate)(void* kodiBase, void* file, unsigned int rate);
305  bool (*io_control_set_retry)(void* kodiBase, void* file, bool retry);
306  char** (*get_property_values)(
307  void* kodiBase, void* file, int type, const char* name, int* numValues);
308 
309  void* (*curl_create)(void* kodiBase, const char* url);
310  bool (*curl_add_option)(
311  void* kodiBase, void* file, int type, const char* name, const char* value);
312  bool (*curl_open)(void* kodiBase, void* file, unsigned int flags);
313 
314  bool (*get_disk_space)(
315  void* kodiBase, const char* path, uint64_t* capacity, uint64_t* free, uint64_t* available);
316  bool (*remove_directory_recursive)(void* kodiBase, const char* path);
318 
319  //}}}
320 
321 #ifdef __cplusplus
322 } /* extern "C" */
323 #endif /* __cplusplus */
324 
325 #endif /* !C_API_FILESYSTEM_H */
STAT_STRUCTURE::isFifo
bool isFifo
The stat url is FIFO special.
Definition: filesystem.h:212
ADDON_READ_MULTI_STREAM
@ ADDON_READ_MULTI_STREAM
0000 0010 0000 : Indicate to the caller we will seek between multiple streams in the file frequently...
Definition: filesystem.h:85
ADDON_READ_AUDIO_VIDEO
@ ADDON_READ_AUDIO_VIDEO
0000 0100 0000 : indicate to the caller file is audio and/or video (and e.g. may grow).
Definition: filesystem.h:90
KODI_HTTP_HEADER
Definition: filesystem.h:180
VFSDirEntry::title
char * title
item title
Definition: filesystem.h:239
ADDON_READ_CHUNKED
@ ADDON_READ_CHUNKED
0000 0000 0010 : Indicate that that caller support read in the minimum defined chunk size,...
Definition: filesystem.h:68
VFSProperty
Definition: filesystem.h:231
ADDON_READ_CACHED
@ ADDON_READ_CACHED
0000 0000 0100 : Use cache to access this file.
Definition: filesystem.h:72
VFSDirEntry::num_props
unsigned int num_props
Number of properties attached to item.
Definition: filesystem.h:241
STAT_STRUCTURE::size
uint64_t size
Total size, in bytes.
Definition: filesystem.h:196
ADDON_READ_AFTER_WRITE
@ ADDON_READ_AFTER_WRITE
0000 1000 0000 : Indicate that caller will do write operations before reading.
Definition: filesystem.h:94
STAT_STRUCTURE::isSymLink
bool isSymLink
The stat url is a symbolic link.
Definition: filesystem.h:206
STAT_STRUCTURE::fileSerialNumber
uint64_t fileSerialNumber
Definition: filesystem.h:219
STAT_STRUCTURE::isDirectory
bool isDirectory
The stat url is a directory.
Definition: filesystem.h:204
VFSDirEntry::size
uint64_t size
Size of file represented by item.
Definition: filesystem.h:245
STAT_STRUCTURE::isSocket
bool isSocket
The stat url is socket.
Definition: filesystem.h:216
VFSDirEntry::label
char * label
item label
Definition: filesystem.h:238
VFSDirEntry::path
char * path
item path
Definition: filesystem.h:240
AddonToKodiFuncTable_kodi_filesystem
Definition: filesystem.h:249
ADDON_READ_TRUNCATED
@ ADDON_READ_TRUNCATED
0000 0000 0001 : Indicate that caller can handle truncated reads, where function returns before enti...
Definition: filesystem.h:63
ADDON_READ_BITRATE
@ ADDON_READ_BITRATE
0000 0001 0000 : Calcuate bitrate for file while reading.
Definition: filesystem.h:80
VFSDirEntry::date_time
time_t date_time
file creation date & time
Definition: filesystem.h:243
STAT_STRUCTURE::statusTime
time_t statusTime
Time of last status change.
Definition: filesystem.h:202
STAT_STRUCTURE::accessTime
time_t accessTime
Time of last access.
Definition: filesystem.h:198
STAT_STRUCTURE::isBlock
bool isBlock
The stat url is block special.
Definition: filesystem.h:208
STAT_STRUCTURE::modificationTime
time_t modificationTime
Time of last modification.
Definition: filesystem.h:200
VFSDirEntry::properties
struct VFSProperty * properties
Properties.
Definition: filesystem.h:242
ADDON_READ_REOPEN
@ ADDON_READ_REOPEN
0001 0000 0000 : Indicate that caller want to reopen a file if its already open.
Definition: filesystem.h:98
OpenFileFlags
OpenFileFlags
Definition: filesystem.h:59
STAT_STRUCTURE::isRegular
bool isRegular
The stat url is regular.
Definition: filesystem.h:214
ADDON_READ_NO_CACHE
@ ADDON_READ_NO_CACHE
0000 0000 1000 : Open without caching. regardless to file type.
Definition: filesystem.h:76
STAT_STRUCTURE::isCharacter
bool isCharacter
The stat url is character special.
Definition: filesystem.h:210
STAT_STRUCTURE::deviceId
uint32_t deviceId
ID of device containing file.
Definition: filesystem.h:194
VFS_CACHE_STATUS_DATA
Definition: filesystem.h:223
VFSDirEntry::folder
bool folder
Item is a folder.
Definition: filesystem.h:244
VFSDirEntry
Definition: filesystem.h:237
STAT_STRUCTURE
Definition: filesystem.h:192