X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcsftp%2Fsilcsftp.h;h=1e438d9bbe6be89d4fd8e49e8b2323d2c9ef423e;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hp=4cda235ef261c769a87ab862dd20438f3c7cc71c;hpb=e5d8d3db6caa344b3d419b884556c21b15e7d123;p=silc.git diff --git a/lib/silcsftp/silcsftp.h b/lib/silcsftp/silcsftp.h index 4cda235e..1e438d9b 100644 --- a/lib/silcsftp/silcsftp.h +++ b/lib/silcsftp/silcsftp.h @@ -57,7 +57,7 @@ typedef struct SilcSFTPStruct *SilcSFTP; * * NAME * - * typedef uint32 SilcSFTPVersion; + * typedef SilcUInt32 SilcSFTPVersion; * * DESCRIPTION * @@ -65,7 +65,7 @@ typedef struct SilcSFTPStruct *SilcSFTP; * * SOURCE */ -typedef uint32 SilcSFTPVersion; +typedef SilcUInt32 SilcSFTPVersion; /***/ /* SFTP protocol version */ @@ -136,15 +136,15 @@ typedef enum { * ***/ typedef struct { - uint32 flags; /* Flags to indicate present attributes */ - uint64 size; /* Sife of the file in bytes */ - uint32 uid; /* Unix user ID */ - uint32 gid; /* Unix group ID */ - uint32 permissions; /* POSIX file permission bitmask */ - uint32 atime; /* Access time of file */ - uint32 mtime; /* Modification time of file */ - - uint32 extended_count; /* Extended type and data count */ + SilcUInt32 flags; /* Flags to indicate present attributes */ + SilcUInt64 size; /* Sife of the file in bytes */ + SilcUInt32 uid; /* Unix user ID */ + SilcUInt32 gid; /* Unix group ID */ + SilcUInt32 permissions; /* POSIX file permission bitmask */ + SilcUInt32 atime; /* Access time of file */ + SilcUInt32 mtime; /* Modification time of file */ + + SilcUInt32 extended_count; /* Extended type and data count */ SilcBuffer *extended_type; SilcBuffer *extended_data; } *SilcSFTPAttributes, SilcSFTPAttributesStruct; @@ -167,7 +167,7 @@ typedef struct { char **filename; char **long_filename; SilcSFTPAttributes *attrs; - uint32 count; /* Number of files */ + SilcUInt32 count; /* Number of files */ } *SilcSFTPName, SilcSFTPNameStruct; /****s* silcsftp/SilcSFTPAPI/SilcSFTPHandle @@ -280,7 +280,7 @@ typedef void (*SilcSFTPHandleCallback)(SilcSFTP sftp, * typedef void (*SilcSFTPDataCallback)(SilcSFTP sftp, * SilcSFTPStatus status, * const unsigned char *data, - * uint32 data_len, + * SilcUInt32 data_len, * void *context); * * DESCRIPTION @@ -293,7 +293,7 @@ typedef void (*SilcSFTPHandleCallback)(SilcSFTP sftp, typedef void (*SilcSFTPDataCallback)(SilcSFTP sftp, SilcSFTPStatus status, const unsigned char *data, - uint32 data_len, + SilcUInt32 data_len, void *context); /****f* silcsftp/SilcSFTPAPI/SilcSFTPNameCallback @@ -346,7 +346,7 @@ typedef void (*SilcSFTPAttrCallback)(SilcSFTP sftp, * typedef void (*SilcSFTPExtendedCallback)(SilcSFTP sftp, * SilcSFTPStatus status, * const unsigned char *data, - * uint32 data_len, + * SilcUInt32 data_len, * void *context); * * DESCRIPTION @@ -359,7 +359,7 @@ typedef void (*SilcSFTPAttrCallback)(SilcSFTP sftp, typedef void (*SilcSFTPExtendedCallback)(SilcSFTP sftp, SilcSFTPStatus status, const unsigned char *data, - uint32 data_len, + SilcUInt32 data_len, void *context); @@ -464,8 +464,8 @@ void silc_sftp_close(SilcSFTP sftp, * * void silc_sftp_read(SilcSFTP sftp, * SilcSFTPHandle handle, - * uint64 offset, - * uint32 len, + * SilcUInt64 offset, + * SilcUInt32 len, * SilcSFTPDataCallback callback, * void *context); * @@ -478,8 +478,8 @@ void silc_sftp_close(SilcSFTP sftp, ***/ void silc_sftp_read(SilcSFTP sftp, SilcSFTPHandle handle, - uint64 offset, - uint32 len, + SilcUInt64 offset, + SilcUInt32 len, SilcSFTPDataCallback callback, void *context); @@ -489,9 +489,9 @@ void silc_sftp_read(SilcSFTP sftp, * * void silc_sftp_write(SilcSFTP sftp, * SilcSFTPHandle handle, - * uint64 offset, + * SilcUInt64 offset, * const unsigned char *data, - * uint32 data_len, + * SilcUInt32 data_len, * SilcSFTPStatusCallback callback, * void *context); * @@ -504,9 +504,9 @@ void silc_sftp_read(SilcSFTP sftp, ***/ void silc_sftp_write(SilcSFTP sftp, SilcSFTPHandle handle, - uint64 offset, + SilcUInt64 offset, const unsigned char *data, - uint32 data_len, + SilcUInt32 data_len, SilcSFTPStatusCallback callback, void *context); @@ -813,7 +813,7 @@ void silc_sftp_realpath(SilcSFTP sftp, * void silc_sftp_extended(SilcSFTP sftp, * const char *request, * const unsigned char *data, - * uint32 data_len, + * SilcUInt32 data_len, * SilcSFTPExtendedCallback callback, * void *context); * @@ -827,201 +827,14 @@ void silc_sftp_realpath(SilcSFTP sftp, void silc_sftp_extended(SilcSFTP sftp, const char *request, const unsigned char *data, - uint32 data_len, + SilcUInt32 data_len, SilcSFTPExtendedCallback callback, void *context); /* SFTP Server Interface */ -/****s* silcsftp/SilcSFTPAPI/SilcSFTPFilesystem - * - * NAME - * - * typedef struct SilcSFTPFilesystemStruct { ... } *SilcSFTPFilesystem; - * - * DESCRIPTION - * - * This structure defines the generic filesystem access. When the - * filesystem is accessed these functions are called to do the requested - * filesystem operation. The level that implements the actual filesystem - * must fill this structure with the callback functions providing the - * access to the filesystem. The structure is will be given as - * argument to the silc_sftp_server_start function. - * - * SOURCE - */ -typedef struct SilcSFTPFilesystemStruct { - /* Find a file handle by the file handle data indicated by the `data'. - If the handle is not found this returns NULL. */ - SilcSFTPHandle (*sftp_get_handle)(void *context, SilcSFTP sftp, - const unsigned char *data, - uint32 data_len); - - /* Return encoded handle of `handle' or NULL on error. The caller - must free the returned buffer. */ - unsigned char *(*sftp_encode_handle)(void *context, SilcSFTP sftp, - SilcSFTPHandle handle, - uint32 *handle_len); - - /* Open a file indicated by the `filename' with flags indicated by the - `pflags', and with attributes indicated by the `attr'. Calls the - `callback' to return the opened file handle. */ - void (*sftp_open)(void *context, SilcSFTP sftp, - const char *filename, - SilcSFTPFileOperation pflags, - SilcSFTPAttributes attr, - SilcSFTPHandleCallback callback, - void *callback_context); - - /* Closes the file indicated by the file handle `handle'. Calls the - `callback' to indicate the status of the closing. */ - void (*sftp_close)(void *context, SilcSFTP sftp, - SilcSFTPHandle handle, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Reads data from the file indicated by the file handle `handle' starting - from the offset of `offset' at most `len' bytes. The `callback' is - called to return the read data. */ - void (*sftp_read)(void *context, SilcSFTP sftp, - SilcSFTPHandle handle, - uint64 offset, - uint32 len, - SilcSFTPDataCallback callback, - void *callback_context); - - /* Writes to a file indicated by the file handle `handle' starting from - offset of `offset' at most `data_len' bytes of `data'. The `callback' - is called to indicate the status of the writing. */ - void (*sftp_write)(void *context, SilcSFTP sftp, - SilcSFTPHandle handle, - uint64 offset, - const unsigned char *data, - uint32 data_len, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Removes a file indicated by the `filename'. Calls the `callback' - to indicate the status of the removing. */ - void (*sftp_remove)(void *context, SilcSFTP sftp, - const char *filename, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Renames a file indicated by the `oldname' to the name `newname'. The - `callback' is called to indicate the status of the renaming. */ - void (*sftp_rename)(void *context, SilcSFTP sftp, - const char *oldname, - const char *newname, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Creates a new directory indicated by the `path' with attributes indicated - by the `attrs'. The `callback' is called to indicate the status of the - creation. */ - void (*sftp_mkdir)(void *context, SilcSFTP sftp, - const char *path, - SilcSFTPAttributes attrs, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Removes a directory indicated by the `path' and calls the `callback' - to indicate the status of the removal. */ - void (*sftp_rmdir)(void *context, SilcSFTP sftp, - const char *path, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Opens a directory indicated by the `path'. The `callback' is called - to return the opened file handle. */ - void (*sftp_opendir)(void *context, SilcSFTP sftp, - const char *path, - SilcSFTPHandleCallback callback, - void *callback_context); - - /* Reads the contents of the directory indicated by the `handle' and - calls the `callback' to return the read file(s) from the directory. */ - void (*sftp_readdir)(void *context, SilcSFTP sftp, - SilcSFTPHandle handle, - SilcSFTPNameCallback callback, - void *callback_context); - - /* Gets the file attributes for a file indicated by the `path'. This - will follow symbolic links also. Calls the `callback' to return the - file attributes. */ - void (*sftp_stat)(void *context, SilcSFTP sftp, - const char *path, - SilcSFTPAttrCallback callback, - void *callback_context); - - /* Gets the file attributes for a file indicated by the `path'. This - will not follow symbolic links. Calls the `callback' to return the - file attributes. */ - void (*sftp_lstat)(void *context, SilcSFTP sftp, - const char *path, - SilcSFTPAttrCallback callback, - void *callback_context); - - /* Gets a file attributes for a opened file indicated by the `handle'. - Calls the `callback' to return the file attributes. */ - void (*sftp_fstat)(void *context, SilcSFTP sftp, - SilcSFTPHandle handle, - SilcSFTPAttrCallback callback, - void *callback_context); - - /* Sets a file attributes to a file indicated by the `path' with the - attributes indicated by the `attrs'. Calls the `callback' to indicate - the status of the setting. */ - void (*sftp_setstat)(void *context, SilcSFTP sftp, - const char *path, - SilcSFTPAttributes attrs, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Sets a file attributes to a opened file indicated by the `handle' with - the attributes indicated by the `attrs'. Calls the `callback' to - indicate the status of the setting. */ - void (*sftp_fsetstat)(void *context, SilcSFTP sftp, - SilcSFTPHandle handle, - SilcSFTPAttributes attrs, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Reads the target of a symbolic link indicated by the `path'. The - `callback' is called to return the target of the symbolic link. */ - void (*sftp_readlink)(void *context, SilcSFTP sftp, - const char *path, - SilcSFTPNameCallback callback, - void *callback_context); - - /* Creates a new symbolic link indicated by the `linkpath' to the target - indicated by the `targetpath'. The `callback' is called to indicate - the status of creation. */ - void (*sftp_symlink)(void *context, SilcSFTP sftp, - const char *linkpath, - const char *targetpath, - SilcSFTPStatusCallback callback, - void *callback_context); - - /* Canonicalizes the path indicated by the `path' to a absolute path. - The `callback' is called to return the absolute path. */ - void (*sftp_realpath)(void *context, SilcSFTP sftp, - const char *path, - SilcSFTPNameCallback callback, - void *callback_context); - - /* Performs an extended operation indicated by the `request' with - optional extended operation data indicated by the `data'. The callback - is called to return any data associated with the extended request. */ - void (*sftp_extended)(void *context, SilcSFTP sftp, - const char *request, - const unsigned char *data, - uint32 data_len, - SilcSFTPExtendedCallback callback, - void *callback_context); -} *SilcSFTPFilesystem; -/****/ +#include "silcsftp_fs.h" /****f* silcsftp/SilcSFTPAPI/silc_sftp_server_start * @@ -1029,9 +842,8 @@ typedef struct SilcSFTPFilesystemStruct { * * SilcSFTP silc_sftp_server_start(SilcSocketConnection sock, * SilcSFTPSendPacketCallback send_packet, - * void *send_context, SilcSFTP sftp, - * SilcSFTPFilesystem fs, - * void *fs_context); + * void *send_context, + * SilcSFTPFilesystem fs); * * DESCRIPTION * @@ -1039,14 +851,13 @@ typedef struct SilcSFTPFilesystemStruct { * created SFTP server context. This function returns the allocated * SFTP client context or NULL on error. The `send_packet' is called * by the library when it needs to send a packet. The `fs' is the - * structure containing filesystem access callbacks. + * filesystem context allocated by the application. * ***/ SilcSFTP silc_sftp_server_start(SilcSocketConnection sock, SilcSFTPSendPacketCallback send_packet, void *send_context, - SilcSFTPFilesystem fs, - void *fs_context); + SilcSFTPFilesystem fs); /****f* silcsftp/SilcSFTPAPI/silc_sftp_server_shutdown * @@ -1063,6 +874,112 @@ SilcSFTP silc_sftp_server_start(SilcSocketConnection sock, ***/ void silc_sftp_server_shutdown(SilcSFTP sftp); +/****d* silcsftp/SilcSFTPAPI/SilcSFTPMonitors + * + * NAME + * + * typedef enum { ... } SilcSFTPMonitors; + * + * DESCRIPTION + * + * SFTP server monitor types. These can be masked together to monitor + * various client requests. + * + * SOURCE + */ +typedef enum { + SILC_SFTP_MONITOR_INIT = 0x0001, + SILC_SFTP_MONITOR_OPEN = 0x0002, + SILC_SFTP_MONITOR_CLOSE = 0x0004, + SILC_SFTP_MONITOR_READ = 0x0008, + SILC_SFTP_MONITOR_WRITE = 0x0010, + SILC_SFTP_MONITOR_REMOVE = 0x0020, + SILC_SFTP_MONITOR_RENAME = 0x0040, + SILC_SFTP_MONITOR_MKDIR = 0x0080, + SILC_SFTP_MONITOR_RMDIR = 0x0100, + SILC_SFTP_MONITOR_OPENDIR = 0x0200, + SILC_SFTP_MONITOR_READDIR = 0x0400, + SILC_SFTP_MONITOR_STAT = 0x0800, + SILC_SFTP_MONITOR_LSTAT = 0x1000, + SILC_SFTP_MONITOR_FSTAT = 0x2000, + SILC_SFTP_MONITOR_SETSTAT = 0x4000, + SILC_SFTP_MONITOR_FSETSTAT = 0x8000, + SILC_SFTP_MONITOR_READLINK = 0x10000, + SILC_SFTP_MONITOR_SYMLINK = 0x20000, + SILC_SFTP_MONITOR_REALPATH = 0x40000, + SILC_SFTP_MONITOR_EXTENDED = 0x80000, +} SilcSFTPMonitors; +/***/ + +/****s* silcsftp/SilcSFTPAPI/SilcSFTPMonitorData + * + * NAME + * + * typedef struct { ... } *SilcSFTPMonitorData, SilcSFTPMonitorDataStruct; + * + * DESCRIPTION + * + * This structure includes the monitor type specific data. The + * application can check what the client has requested from this + * structure. + * + * SOURCE + */ +typedef struct { + SilcSFTPVersion version; /* _INIT */ + char *name; /* _OPEN, _REMOVE, _RENAME, _MKDIR, + _RMDIR, _OPENDIR, _STAT, _LSTAT, + _SETSTAT, _READLINK, _SYMLINK, _REALPATH */ + char *name2; /* _RENAME, _SYMLINK */ + SilcSFTPFileOperation pflags; /* _OPEN */ + SilcUInt64 offset; /* _READ, _WRITE */ + SilcUInt32 data_len; /* _READ, _WRITE */ + SilcSFTPName names; /* _READDIR, _READLINK, _REALPATH */ +} *SilcSFTPMonitorData, SilcSFTPMonitorDataStruct; +/***/ + +/****f* silcsftp/SilcSFTPAPI/SilcSFTPMonitor + * + * SYNOPSIS + * + * typedef void (*SilcSFTPMonitor)(SilcSFTP sftp + * SilcSFTPMonitors type, + * const SilcSFTPMonitorData data, + * void *context); + * + * DESCRIPTION + * + * Monitor callback that is called when an specified request is + * received from client. The `type' is the requested type that + * was being monitored. + * + ***/ +typedef void (*SilcSFTPMonitor)(SilcSFTP sftp, + SilcSFTPMonitors type, + const SilcSFTPMonitorData data, + void *context); + +/****f* silcsftp/SilcSFTPAPI/silc_sftp_server_set_monitor + * + * SYNOPSIS + * + * void silc_sftp_server_set_monitor(SilcSFTP sftp, + * SilcSFTPMonitors monitors, + * SilcSFTPMonitor monitor, + * void *context); + * + * DESCRIPTION + * + * Sets monitor callback to monitor various request sent by an client. + * When request that has been set in the `monitors' is received the + * monitor callback will be called to notify the caller. + * + ***/ +void silc_sftp_server_set_monitor(SilcSFTP sftp, + SilcSFTPMonitors monitors, + SilcSFTPMonitor monitor, + void *context); + /* Function that is called to process the incmoing SFTP packet. */ /* XXX Some day this will go away and we have automatic receive callbacks for SilcSocketConnection API or SilcPacketContext API. */