X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcsftp%2Fsilcsftp.h;h=38b300b6277e4c807b68e8c7c284fadec5acd874;hb=c257b555225193e54d85daf541d29578b3c93882;hp=fb81b595a9561573aa401f749647b043c30abd7b;hpb=6f25b5bdcdbcb21dbfb1c86fd79bfd5b71b027db;p=silc.git diff --git a/lib/silcsftp/silcsftp.h b/lib/silcsftp/silcsftp.h index fb81b595..38b300b6 100644 --- a/lib/silcsftp/silcsftp.h +++ b/lib/silcsftp/silcsftp.h @@ -1,10 +1,10 @@ /* - silcsftp.h + silcsftp.h Author: Pekka Riikonen - Copyright (C) 2001 Pekka Riikonen + Copyright (C) 2001 - 2005 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,11 +20,11 @@ #ifndef SILCSFTP_H #define SILCSFTP_H -/****h* silcsftp/SilcSFTPAPI +/****h* silcsftp/SILC SFTP Interface * * DESCRIPTION * - * SILC SFTP Interface is the implementation of the SSH File Transfer + * SILC SFTP Interface is the implementation of the Secure File Transfer * Protocol. The interface defines the SFTP client and the SFTP server. * The SFTP is the mandatory file transfer protocol in the SILC protocol. * The SFTP server implementation is filesystem independent and generic @@ -39,7 +39,7 @@ /****s* silcsftp/SilcSFTPAPI/SilcSFTP * * NAME - * + * * typedef struct SilcSFTPStruct *SilcSFTP; * * DESCRIPTION @@ -47,7 +47,7 @@ * This context is the actual SFTP client and SFTP server, and is * allocated by silc_sftp_client_start or silc_sftp_server_start and * given as argument usually to all silc_sftp_* functions. It is freed - * by the silc_sftp_client_shutdown or silc_sftp_server_shutdown + * by the silc_sftp_client_shutdown or silc_sftp_server_shutdown * functions. * ***/ @@ -56,8 +56,8 @@ typedef struct SilcSFTPStruct *SilcSFTP; /****d* silcsftp/SilcSFTPAPI/SilcSFTPVersion * * 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 */ @@ -74,7 +74,7 @@ typedef uint32 SilcSFTPVersion; /****d* silcsftp/SilcSFTPAPI/SilcSFTPStatus * * NAME - * + * * typedef enum { ... } SilcSFTPStatus * * DESCRIPTION @@ -95,13 +95,33 @@ typedef enum { SILC_SFTP_STATUS_NO_CONNECTION = 6, /* No connection to server */ SILC_SFTP_STATUS_CONNECTION_LOST = 7, /* Connection lost to server */ SILC_SFTP_STATUS_OP_UNSUPPORTED = 8, /* Operation unsupported */ + SILC_SFTP_STATUS_INVALID_HANDLE = 9, /* Invalid file handle */ + SILC_SFTP_STATUS_NO_SUCH_PATH = 10, /* Path does not exist */ + SILC_SFTP_STATUS_FILE_ALREADY_EXIST = 11, /* File already exists */ + SILC_SFTP_STATUS_WRITE_PROTECT = 12, /* Read-only or protected */ + SILC_SFTP_STATUS_NO_MEDIA = 13, /* No media available */ + SILC_SFTP_STATUS_NO_SPACE_ON_DEVICE = 14, /* No space on device */ + SILC_SFTP_STATUS_QUOTA_EXCEEDED = 15, /* Quota limit reached */ + SILC_SFTP_STATUS_UNKNOWN_PRINCIBLE = 16, /* Unknown princible */ + SILC_SFTP_STATUS_LOCK_CONFLICT = 17, /* File already locked */ + SILC_SFTP_STATUS_NOT_EMPTY = 18, /* Directory not empty */ + SILC_SFTP_STATUS_NOT_A_DIRECTORY = 19, /* Not a directory */ + SILC_SFTP_STATUS_INVALID_FILENAME = 20, /* Invalid filename */ + SILC_SFTP_STATUS_LINK_LOOP = 21, /* Too many symlinks */ + SILC_SFTP_STATUS_CANNOT_DELETE = 22, /* Could not delete file */ + SILC_SFTP_STATUS_INVALID_PARAMETER = 23, /* Invalid parameter */ + SILC_SFTP_STATUS_FILE_IS_A_DIRECTORY = 24, /* File is a directory file */ + SILC_SFTP_STATUS_BR_LOCK_CONFLICT = 25, /* Byte range lock conflict */ + SILC_SFTP_STATUS_BR_LOCK_REFUSED = 26, /* Byte range lock refused */ + SILC_SFTP_STATUS_DELETE_PENDING = 27, /* File is being deleted */ + SILC_SFTP_STATUS_FILE_CORRUPT = 28, /* File is corrupted */ } SilcSFTPStatus; /***/ /****d* silcsftp/SilcSFTPAPI/SilcSFTPFileOperation * * NAME - * + * * typedef enum { ... } SilcSFTPFileOperation * * DESCRIPTION @@ -125,26 +145,26 @@ typedef enum { /****s* silcsftp/SilcSFTPAPI/SilcSFTPAttributes * * NAME - * + * * typedef struct { ... } *SilcSFTPAttributes, SilcSFTPAttributesStruct; * * DESCRIPTION * * SFTP File attributes structure represents the attributes for a file. - * This structure can be used by the client to send attributes to the + * This structure can be used by the client to send attributes to the * server, and by server to return file attributes to the client. * ***/ 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; @@ -152,7 +172,7 @@ typedef struct { /****s* silcsftp/SilcSFTPAPI/SilcSFTPName * * NAME - * + * * typedef struct { ... } *SilcSFTPName, SilcSFTPNameStruct * * DESCRIPTION @@ -163,17 +183,17 @@ typedef struct { * example when reading the contents of a directory. * ***/ -typedef struct { +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 * * NAME - * + * * typedef struct SilcSFTPHandleStruct *SilcSFTPHandle; * * DESCRIPTION @@ -189,20 +209,17 @@ typedef struct SilcSFTPHandleStruct *SilcSFTPHandle; * * SYNOPSIS * - * typedef void (*SilcSFTPSendPacketCallback)(SilcSocketConnection sock, - * SilcBuffer packet, + * typedef void (*SilcSFTPSendPacketCallback)(SilcBuffer packet, * void *context); * * DESCRIPTION * * Packet sending callback. The caller of this interface will provide this * function for the library. The libary will call this function everytime - * it needs to send a packet to the socket connection indicated by the - * `sock'. + * it needs to send a packet to the remote host. * ***/ -typedef void (*SilcSFTPSendPacketCallback)(SilcSocketConnection sock, - SilcBuffer packet, void *context); +typedef void (*SilcSFTPSendPacketCallback)(SilcBuffer packet, void *context); /****f* silcsftp/SilcSFTPAPI/SilcSFTPVersionCallback * @@ -280,7 +297,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 +310,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 +363,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 +376,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); @@ -369,24 +386,22 @@ typedef void (*SilcSFTPExtendedCallback)(SilcSFTP sftp, * * SYNOPSIS * - * SilcSFTP silc_sftp_client_start(SilcSocketConnection sock, - * SilcSFTPSendPacketCallback send_packet, + * SilcSFTP silc_sftp_client_start(SilcSFTPSendPacketCallback send_packet, * void *send_context, * SilcSFTPVersionCallback callback, * void *context); * * DESCRIPTION * - * Starts SFTP client by associating the socket connection `sock' to the - * created SFTP client context. The version callback indicated by the - * `callback' will be called after the SFTP session has been started - * and server has returned the version of the protocol. The SFTP client - * context is returned in the callback too. This returns the allocated - * SFTP client context or NULL on error. + * Starts SFTP client and returns context to it. The version callback + * indicated by the `callback' will be called after the SFTP session has + * been started and server has returned the version of the protocol. The + * SFTP client context is returned in the callback too. This returns the + * allocated SFTP client context or NULL on error. Each socket connection + * should allocate their own SFTP client by calling this function. * ***/ -SilcSFTP silc_sftp_client_start(SilcSocketConnection sock, - SilcSFTPSendPacketCallback send_packet, +SilcSFTP silc_sftp_client_start(SilcSFTPSendPacketCallback send_packet, void *send_context, SilcSFTPVersionCallback callback, void *context); @@ -417,7 +432,7 @@ void silc_sftp_client_receive_process(SilcSFTP sftp, * * SYNOPSIS * - * void silc_sftp_open(SilcSFTP sftp, + * void silc_sftp_open(SilcSFTP sftp, * const char *filename, * SilcSFTPFileOperation pflags, * SilcSFTPAttributes attrs, @@ -431,7 +446,7 @@ void silc_sftp_client_receive_process(SilcSFTP sftp, * `callback' to return the opened file handle. * ***/ -void silc_sftp_open(SilcSFTP sftp, +void silc_sftp_open(SilcSFTP sftp, const char *filename, SilcSFTPFileOperation pflags, SilcSFTPAttributes attrs, @@ -464,8 +479,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 +493,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,24 +504,24 @@ 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); * * DESCRIPTION * * Writes to a file indicated by the file handle `handle' starting from - * offset of `offset' at most `data_len' bytes of `data'. The `callback' + * offset of `offset' at most `data_len' bytes of `data'. The `callback' * is called to indicate the status of the writing. * ***/ 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,13 +828,13 @@ 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); * * DESCRIPTION * - * Performs an extended operation indicated by the `request' with + * 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. * @@ -827,7 +842,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); @@ -840,23 +855,21 @@ void silc_sftp_extended(SilcSFTP sftp, * * SYNOPSIS * - * SilcSFTP silc_sftp_server_start(SilcSocketConnection sock, - * SilcSFTPSendPacketCallback send_packet, - * void *send_context, SilcSFTP sftp, + * SilcSFTP silc_sftp_server_start(SilcSFTPSendPacketCallback send_packet, + * void *send_context, * SilcSFTPFilesystem fs); * * DESCRIPTION * - * Starts SFTP server by associating the socket connection `sock' to the - * 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 - * filesystem context allocated by the application. + * Starts SFTP server and returns a context to it. 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 + * filesystem context allocated by the application. Each socket connection + * should start its own server by calling this function. * ***/ -SilcSFTP silc_sftp_server_start(SilcSocketConnection sock, - SilcSFTPSendPacketCallback send_packet, - void *send_context, +SilcSFTP silc_sftp_server_start(SilcSFTPSendPacketCallback send_packet, + void *send_context, SilcSFTPFilesystem fs); /****f* silcsftp/SilcSFTPAPI/silc_sftp_server_shutdown @@ -874,6 +887,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. */