Merged silc_1_0_branch to trunk.
[silc.git] / lib / silcsftp / silcsftp.h
index 4cda235ef261c769a87ab862dd20438f3c7cc71c..38b300b6277e4c807b68e8c7c284fadec5acd874 100644 (file)
@@ -1,10 +1,10 @@
 /*
 
-  silcsftp.h 
+  silcsftp.h
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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
 #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,241 +842,156 @@ 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
+#include "silcsftp_fs.h"
+
+/****f* silcsftp/SilcSFTPAPI/silc_sftp_server_start
+ *
+ * SYNOPSIS
+ *
+ *    SilcSFTP silc_sftp_server_start(SilcSFTPSendPacketCallback send_packet,
+ *                                    void *send_context,
+ *                                    SilcSFTPFilesystem fs);
+ *
+ * DESCRIPTION
+ *
+ *    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(SilcSFTPSendPacketCallback send_packet,
+                               void *send_context,
+                               SilcSFTPFilesystem fs);
+
+/****f* silcsftp/SilcSFTPAPI/silc_sftp_server_shutdown
+ *
+ * SYNOPSIS
+ *
+ *    void silc_sftp_server_shutdown(SilcSFTP sftp);
+ *
+ * DESCRIPTION
+ *
+ *    Shutdown's the SFTP server.  The caller is responsible of closing
+ *    the associated socket connection.  The SFTP context is freed and is
+ *    invalid after this function returns.
+ *
+ ***/
+void silc_sftp_server_shutdown(SilcSFTP sftp);
+
+/****d* silcsftp/SilcSFTPAPI/SilcSFTPMonitors
  *
  * NAME
- * 
- *    typedef struct SilcSFTPFilesystemStruct { ... } *SilcSFTPFilesystem;
+ *
+ *    typedef enum { ... } SilcSFTPMonitors;
  *
  * 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.
+ *    SFTP server monitor types. These can be masked together to monitor
+ *    various client requests.
  *
  * 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);
+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;
+/***/
 
-  /* 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;
-/****/
+/****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/silc_sftp_server_start
+/****f* silcsftp/SilcSFTPAPI/SilcSFTPMonitor
  *
  * SYNOPSIS
  *
- *    SilcSFTP silc_sftp_server_start(SilcSocketConnection sock,
- *                                    SilcSFTPSendPacketCallback send_packet,
- *                                    void *send_context, SilcSFTP sftp,
- *                                    SilcSFTPFilesystem fs,
- *                                    void *fs_context);
+ *    typedef void (*SilcSFTPMonitor)(SilcSFTP sftp
+ *                                    SilcSFTPMonitors type,
+ *                                    const SilcSFTPMonitorData data,
+ *                                    void *context);
  *
  * 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
- *    structure containing filesystem access callbacks.
+ *    Monitor callback that is called when an specified request is
+ *    received from client.  The `type' is the requested type that
+ *    was being monitored.
  *
  ***/
-SilcSFTP silc_sftp_server_start(SilcSocketConnection sock,
-                               SilcSFTPSendPacketCallback send_packet,
-                               void *send_context, 
-                               SilcSFTPFilesystem fs,
-                               void *fs_context);
+typedef void (*SilcSFTPMonitor)(SilcSFTP sftp,
+                               SilcSFTPMonitors type,
+                               const SilcSFTPMonitorData data,
+                               void *context);
 
-/****f* silcsftp/SilcSFTPAPI/silc_sftp_server_shutdown
+/****f* silcsftp/SilcSFTPAPI/silc_sftp_server_set_monitor
  *
  * SYNOPSIS
  *
- *    void silc_sftp_server_shutdown(SilcSFTP sftp);
+ *    void silc_sftp_server_set_monitor(SilcSFTP sftp,
+ *                                      SilcSFTPMonitors monitors,
+ *                                      SilcSFTPMonitor monitor,
+ *                                      void *context);
  *
  * DESCRIPTION
  *
- *    Shutdown's the SFTP server.  The caller is responsible of closing
- *    the associated socket connection.  The SFTP context is freed and is
- *    invalid after this function returns.
+ *    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_shutdown(SilcSFTP sftp);
+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