From 6132c2ef3066e813acb1237afeca266f32c53a21 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sat, 28 Nov 2009 16:00:34 +0100 Subject: Engine and VFS API cleanup * also split threaded operations into UCoreWorkers.pas * symlinks should be properly resolved now, even in archives * no more relative/absolute path confusion * moved FillDirFiles outside engines, made it more universal --- vfs/uVFSprototypes.pas | 240 +++++++++++++++++++------------------------------ 1 file changed, 94 insertions(+), 146 deletions(-) (limited to 'vfs/uVFSprototypes.pas') diff --git a/vfs/uVFSprototypes.pas b/vfs/uVFSprototypes.pas index 5da4bc9..75c7349 100644 --- a/vfs/uVFSprototypes.pas +++ b/vfs/uVFSprototypes.pas @@ -27,6 +27,8 @@ unit uVFSprototypes; interface +uses glib2; + {$IFDEF FPC} {$PACKRECORDS C} {$ENDIF} @@ -34,18 +36,6 @@ interface const cVFSVersion = 5; // current version of the VFS API - // Capabilities - capVFS_nil = 0; - capVFS_List = 1; - capVFS_CopyOut = 2; - capVFS_CopyIn = 4; - capVFS_NeedsTemp = 8; // if not set, the seek operation is available - capVFS_Multiple = 16; // support multiple files - ? - capVFS_Execute = 32; - capVFS_Writable = 64; - capVFS_NeedsLogin = 128; // Anonymous is login operation too - - // Error codes (TVFSResult) cVFS_OK = 0; cVFS_Failed = 1; // also No such file @@ -79,70 +69,43 @@ const type TVFSResult = longint; - TVFSGlobs = Pointer; + // Plugin private data for each connection/instance + TVFSGlobs = Pointer; // File descriptor for Open, Read, Write, Close, Seek operations TVFSFileDes = Pointer; TVFSAskPasswordFlags = Longint; + // Let the plugin save password, usually to gnome-keyring PVFSPasswordSave = ^TVFSPasswordSave; - // Let plugin save the password, usually to gnome-keyring TVFSPasswordSave = (VFS_PASSWORD_SAVE_NEVER, VFS_PASSWORD_SAVE_FOR_SESSION, VFS_PASSWORD_SAVE_PERMANENTLY); - TVFSItemType = (vRegular=0, vSymlink=1, vChardev=2, vBlockdev=3, vDirectory=4, vFifo=5, vSock=6, vOther=7); - -{$IFDEF KYLIX} - DWORD = Cardinal; -// ShortBool = boolean; -{$ENDIF} -{$IFNDEF CPU64} - ShortBool = boolean; -{$ENDIF} - - - //* TODO: FName/FDisplayName: napsat presne pravidla pro absolutni/relativni cesty a opravit v modulech i v UVFSCore + TVFSItemType = (vRegular=0, vChardev=1, vBlockdev=2, vDirectory=3, vFifo=4, vSock=5, vOther=6); PVFSItem = ^TVFSItem; TVFSItem = record -{$IFNDEF CPU64} // 32-bit platform FName: PChar; - // FDisplayName - plugins must ensure correct UTF-8 string - FDisplayName: PChar; - iSize: Int64; - // iPackedSize - set to -1 if plugin doesn't support this feature - iPackedSize: Int64; - m_time: DWORD; - a_time: DWORD; - c_time: DWORD; - iMode: Integer; + FDisplayName: PChar; // FDisplayName - plugins must return valid UTF-8 string + iSize: guint64; + iPackedSize: gint64; // iPackedSize - set to -1 if plugin doesn't support this feature + m_time: guint32; + a_time: guint32; + c_time: guint32; + iMode: guint32; + IsLink: gboolean; sLinkTo: PChar; - iUID: Integer; - iGID: Integer; - ItemType: Integer; -{$ELSE} // 64-bit platform - FName: PChar; - FDisplayName: PChar; - iSize: Int64; - iPackedSize: Int64; - m_time: QWORD; - a_time: QWORD; - c_time: QWORD; - iMode: Longint; - __padding1: array[1..4] of byte; - sLinkTo: PChar; - iUID: Longint; - iGID: Longint; - ItemType: Longint; - __padding: array[1..4] of byte; -{$ENDIF} + iUID: guint32; + iGID: guint32; + ItemType: TVFSItemType; end; - // This structure contains basic informations about the plugin + + // Basic information about the plugin PVFSInfo = ^TVFSInfo; TVFSInfo = record ID: PChar; // unique identifier, not shown in GUI @@ -161,10 +124,10 @@ type cancel_choice: Integer; user_data: Pointer); cdecl; - PVFSAskPasswordCallback = ^TVFSAskPasswordCallback; // Remember to allocate passed strings separately (use strdup() when setting reply) // Modules are eligible for keeping passwords during one session; calling callback again means the last password was wrong and user should enter new one // Returns True (1) if succeeded or False (0) if cancelled + PVFSAskPasswordCallback = ^TVFSAskPasswordCallback; TVFSAskPasswordCallback = function (const AMessage: PChar; const default_user: PChar; const default_domain: PChar; @@ -172,104 +135,116 @@ type flags: TVFSAskPasswordFlags; username: PPChar; password: PPChar; - anonymous: PInteger; + anonymous: Pgboolean; domain: PPChar; password_save: PVFSPasswordSave; - user_data: Pointer): LongBool; cdecl; + user_data: Pointer): gboolean; cdecl; // Return False to break the operation PVFSProgressCallback = ^TVFSProgressCallback; - TVFSProgressCallback = function (position: Int64; - max: Int64; - user_data: Pointer): LongBool; cdecl; + TVFSProgressCallback = function (position: guint64; + max: guint64; + user_data: Pointer): gboolean; cdecl; type // Log function for plugin debugging output - host application will print or save these messages + // TODO: add log_level? PVFSLogFunc = ^TVFSLogFunc; TVFSLogFunc = procedure(const S: PChar); cdecl; + // Set callbacks, the user_data value will be passed into them + TVFSSetCallbacks = procedure (g: TVFSGlobs; ask_question_callback: PVFSAskQuestionCallback; + ask_password_callback: PVFSAskPasswordCallback; + progress_func: PVFSProgressCallback; + user_data: Pointer); cdecl; - TVFSNew = function (LogFunc: PVFSLogFunc): TVFSGlobs; cdecl; // Allocates memory for the globs structure and performs intialization of the plugin + TVFSNew = function (LogFunc: PVFSLogFunc): TVFSGlobs; cdecl; + // Performs cleanup and destroys all objects TVFSFree = procedure (g: TVFSGlobs); cdecl; - // Performs cleanup and destroy all objects - TVFSVersion = function: integer; cdecl; - // Returns VFS API Version; must match version hardcoded in the host program, otherwise the module is not loaded + // Returns VFS API Version; must match version hardcoded in the host program, otherwise module is not loaded // Please use the cVFSVersion constant as a return value - TVFSGetInfo = function: PVFSInfo; cdecl; + TVFSVersion = function: integer; cdecl; // Returns module info struct, tuxcmd will take care of memory deallocation - TVFSGetArchiveExts = function: PChar; cdecl; + TVFSGetInfo = function: PVFSInfo; cdecl; // Returns the list of filename extensions which the module can handle separated by ';' (without a leading dots) // Returning NULL or not defining the symbol at all means plugin can't handle archives // tuxcmd will take care of memory deallocation - TVFSGetNetworkServices = function: PChar; cdecl; + TVFSGetArchiveExts = function: PChar; cdecl; // Returns the list of supported remote protocols separated by ';' (without the '://') // Returning NULL or not defining the symbol at all means plugin can't access network services // tuxcmd will take care of memory deallocation - TVFSSetProtocolLogFunc = procedure (g:TVFSGlobs; ProtocolLogFunc: TVFSLogFunc); cdecl; + TVFSGetNetworkServices = function: PChar; cdecl; // TODO: Sets the protocol log function (unlike module debug log func this is intended only for server messages (FTP mainly)) - TVFSSetBlockSize = procedure (g:TVFSGlobs; Value: Cardinal); cdecl; - // Sets the block size for I/O operations (not all modules supports this) + TVFSSetProtocolLogFunc = procedure (g:TVFSGlobs; ProtocolLogFunc: TVFSLogFunc); cdecl; + // Sets block size for I/O operations (not supported by all modules) + TVFSSetBlockSize = procedure (g:TVFSGlobs; Value: guint32); cdecl; + // Opens specified archive. This will also switch engine into an archiving mode TVFSOpenArchive = function (g:TVFSGlobs; const sName: PChar): TVFSResult; cdecl; - // Opens specified archive. This will also switch plugin (an instance) into archiving mode - TVFSOpenURI = function (g:TVFSGlobs; const sURI: PChar): TVFSResult; cdecl; - // Opens specified network location. This will also switch plugin (an instance) into networking mode + // Opens specified network location. This will also switch engine into a networking mode // In case of URI, do not supply password encoded in the string; plugin will automatically spawn the TVFSAskPasswordCallback callback when needed - TVFSClose = function (g:TVFSGlobs): TVFSResult; cdecl; + TVFSOpenURI = function (g:TVFSGlobs; const sURI: PChar): TVFSResult; cdecl; // Closes the file or connection to the server - TVFSMkDir = function (g:TVFSGlobs; const sDirName: PChar): TVFSResult; cdecl; - TVFSRename = function (g:TVFSGlobs; const sSrcName, sDstName: PChar): TVFSResult; cdecl; - // Only rename/move in this function, the two files/directories have to be on the same filesystem - otherway it needs to be copied and deleted manually - TVFSRemove = function (g:TVFSGlobs; const APath: PChar): TVFSResult; cdecl; - // Removes the file/directory (empty only!) - TVFSFileExists = function (g:TVFSGlobs; const FileName: PChar; const Use_lstat: LongBool): LongBool; cdecl; - // This function checks for existing location; the Use_lstat parameter specifies to not follow the symlinks (default false = follow symlinks) - TVFSMakeSymLink = function (g:TVFSGlobs; const NewFileName, PointTo: PChar): TVFSResult; cdecl; - TVFSChmod = function (g:TVFSGlobs; const FileName: PChar; const Mode: integer): TVFSResult; cdecl; - // The parameter for this function is in classic unix format (glibc) - a bit mask - TVFSChown = function (g:TVFSGlobs; const FileName: PChar; const UID, GID: integer): TVFSResult; cdecl; - TVFSChangeTimes = function (g:TVFSGlobs; APath: PChar; mtime, atime: Longint): TVFSResult; cdecl; - // Changes times for the file/directory - mtime and atime are __time_t parameters (glibc) + TVFSClose = function (g:TVFSGlobs): TVFSResult; cdecl; + + + // These functions serves for listing contents of a directory + // Before calling VFSListFirst, it is recommended to change target directory (VFSChangeDir) to check it really exists + // First call the VFSListFirst function and then repeat call of VFSListNext until it returns NULL. + // Then call VFSListClose to make cleanup + TVFSListFirst = function (g:TVFSGlobs; const sDir: PChar; VFSItem: PVFSItem; FollowSymlinks, AddFullPath: gboolean): TVFSResult; cdecl; + TVFSListNext = function (g:TVFSGlobs; VFSItem: PVFSItem): TVFSResult; cdecl; + TVFSListClose = function (g:TVFSGlobs): TVFSResult; cdecl; + // Gets a single info item without need to list a whole directory + TVFSFileInfo = function (g:TVFSGlobs; const AFileName: PChar; VFSItem: PVFSItem; FollowSymlinks, AddFullPath: gboolean): TVFSResult; cdecl; + + + // Try to change directory, checks real access TVFSChangeDir = function (g:TVFSGlobs; const NewPath: PChar): TVFSResult; cdecl; - // Try to change the directory when correct permissions + // Returns current working path, tuxcmd will take care of memory deallocation TVFSGetPath = function (g:TVFSGlobs): PChar; cdecl; - // Returns the current working path (not all plugins can support this; just return '/' in this case) - // tuxcmd will take care of memory deallocation + // Returns the current working path in the URI form, tuxcmd will take care of memory deallocation TVFSGetPathURI = function (g:TVFSGlobs): PChar; cdecl; - // Returns the current working path in the URI form - // tuxcmd will take care of memory deallocation - TVFSGetFileSystemSize = function (g:TVFSGlobs; const APath: PChar): Int64; cdecl; - // Gets the size of filesystem; the path is optional, specified to recognize various mounted filesystems in the tree - TVFSGetFileSystemFree = function (g:TVFSGlobs; const APath: PChar): Int64; cdecl; - TVFSGetFSLabel = function (g:TVFSGlobs; const APath: PChar): PChar; cdecl; - // Gets the filesystem label, tuxcmd will take care of memory deallocation - TVFSIsOnSameFS = function (g:TVFSGlobs; const Path1, Path2: PChar): boolean; cdecl; - TVFSTwoSameFiles = function (g:TVFSGlobs; const Path1, Path2: PChar): boolean; cdecl; + // Gets filesystem info; tuxcmd will take care of memory deallocation + TVFSGetFileSystemInfo = function (g:TVFSGlobs; const APath: PChar; FSSize, FSFree: PInt64; FSLabel: PPChar): TVFSResult; cdecl; + TVFSIsOnSameFS = function (g:TVFSGlobs; const Path1, Path2: PChar; FollowSymlinks: gboolean): gboolean; cdecl; // Checks if the two files are simmilar (used to test the case-insensitive filesystem - or hardlinks) - TVFSGetDirSize = function (g:TVFSGlobs; APath: PChar): Int64; cdecl; - // Calculates recursively the size of the tree specified under the path APath - TVFSBreakGetDirSize = procedure (g:TVFSGlobs); cdecl; + TVFSTwoSameFiles = function (g:TVFSGlobs; const Path1, Path2: PChar; FollowSymlinks: gboolean): gboolean; cdecl; + // Calculates recursively the size of a tree specified + TVFSGetDirSize = function (g:TVFSGlobs; const APath: PChar): guint64; cdecl; // Call this function to break the calculation performed by VFSGetDirSize - TVFSRun = function (g:TVFSGlobs; const sName: PChar): TVFSResult; cdecl; - // TODO: Runs the command read from inside the archive (typically installing the rpm package) + TVFSBreakGetDirSize = procedure (g:TVFSGlobs); cdecl; + + // Operations + TVFSMkDir = function (g:TVFSGlobs; const sDirName: PChar): TVFSResult; cdecl; + // Rename/Move, the two files/directories have to be on the same filesystem (do manual copy and delete otherway) + TVFSRename = function (g:TVFSGlobs; const sSrcName, sDstName: PChar): TVFSResult; cdecl; + // Removes file/directory (empty only!) + TVFSRemove = function (g:TVFSGlobs; const APath: PChar): TVFSResult; cdecl; + TVFSMakeSymLink = function (g:TVFSGlobs; const NewFileName, PointTo: PChar): TVFSResult; cdecl; + // Mode is classic unix format (glibc) - a bit mask + TVFSChmod = function (g:TVFSGlobs; const FileName: PChar; Mode: guint32): TVFSResult; cdecl; + TVFSChown = function (g:TVFSGlobs; const FileName: PChar; UID, GID: guint32): TVFSResult; cdecl; + // Changes times for the file/directory - mtime and atime are __time_t parameters (glibc) + TVFSChangeTimes = function (g:TVFSGlobs; const APath: PChar; mtime, atime: guint32): TVFSResult; cdecl; - TVFSCopyToLocal = function (g:TVFSGlobs; const sSrcName, sDstName: PChar; Append: LongBool): TVFSResult; cdecl; - // Performs the copy process from inside of module to the file in the local system + // Performs the copy process from inside of module to local filesystem // (thus sSrcName is a path from inside of module and sDstName is path in the local filesystem where the file should be copied) - // The data pointer is then used to call the callback function in - // Note: if you need to transfer a file between two VFS modules, you need to do it manually - either first copy to local FS or use the Open, Read, Write functions of the module (NOTE: both VFS modules have to support these functions) + // Note: if you need to transfer a file between two VFS modules, you need to do it manually - + // - either first copy to local FS or use the Open, Read, Write functions of the module (NOTE: both VFS modules have to support these functions) + TVFSCopyToLocal = function (g:TVFSGlobs; const sSrcName, sDstName: PChar; Append: gboolean): TVFSResult; cdecl; + // Performs the copy process from local filesystem into the module + TVFSCopyFromLocal = function (g:TVFSGlobs; const sSrcName, sDstName: PChar; Append: gboolean): TVFSResult; cdecl; - TVFSCopyFromLocal = function (g:TVFSGlobs; const sSrcName, sDstName: PChar; Append: LongBool): TVFSResult; cdecl; - // Performs the copy process from the local filesystem into the module - - // Prototype function for packing new files into archive + // TODO: Prototype function for packing new files into archive TVFSPack = function (g:TVFSGlobs; const sSrcName, sDstName: PChar; CompressionLevel: integer; const Password: PChar): TVFSResult; cdecl; - // This is the set of basic functions which can manipulate with the data + // TODO: not implemented at all + // This is the set of basic functions which can manipulate with data // There is a TVFSFileDes object which identifies the processed file (filedescriptor) // All these functions needs a pointer to an int variable to store the error code // NOTE: not all modules could support this set of functions due to its design (unable to set a solid block size) @@ -284,41 +259,14 @@ type // Sets the position in the file from the start and returns real current position - // These are the functions used to list the contents of the directory - // First call the VFSListFirst function and then repeat call of VFSListNext until it returns NULL. - // Then call VFSListClose to make cleanup - TVFSListFirst = function (g:TVFSGlobs; const sDir: PChar; VFSItem: PVFSItem): TVFSResult; cdecl; - TVFSListNext = function (g:TVFSGlobs; const sDir: PChar; VFSItem: PVFSItem): TVFSResult; cdecl; - TVFSListClose = function (g:TVFSGlobs): TVFSResult; cdecl; - - //* TODO: napsat presne pravidla pro absolutni/relativni cesty a opravit v modulech i v UVFSCore - TVFSFileInfo = function (g:TVFSGlobs; AFileName: PChar; VFSItem: PVFSItem): TVFSResult; cdecl; - // Gets a single info item without need to list a whole directory - - TVFSGetPasswordRequired = function (g:TVFSGlobs): LongBool; cdecl; - - - // Reset stored session password in the plugin + // Returns flag indicating whether password is required for some files in the archive + TVFSGetPasswordRequired = function (g:TVFSGlobs): gboolean; cdecl; + // Reset stored password in the plugin session TVFSResetPassword = procedure (g: TVFSGlobs); cdecl; - - - /// pridat neco jako set_loglevel ?? - -//// pridat typ pluginu - jestli archive nebo protocol - prip. jeste pridat ktery protokoly je to schopno handlovat - - - - TVFSSetCallbacks = procedure (g: TVFSGlobs; ask_question_callback: PVFSAskQuestionCallback; - ask_password_callback: PVFSAskPasswordCallback; - progress_func: PVFSProgressCallback; - user_data: Pointer); cdecl; - - - // TODO: some function to check the CRC of the archive - it should need also some progress feedback - the processed file and percentage progress -// Prekopat error logging - asi neco na zpusob GError, stringy se budou vracet i z pluginu +// TODO: port error logging subsystem to glib's GError implementation -- cgit v1.2.3