Ported SFTP library to new util library.
[silc.git] / lib / silcsftp / silcsftp.h
index b7017448e9a83ca537efb92f6009de672bab5c37..87ee70397ce1dc9a849a43bad1fe6855d0c215ae 100644 (file)
@@ -1,10 +1,10 @@
 /*
 
-  silcsftp.h 
+  silcsftp.h
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 Pekka Riikonen
+  Copyright (C) 2001 - 2007 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
  *
  * DESCRIPTION
  *
- *    SILC SFTP Interface is the implementation of the SSH 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
- *    interface is defined to represent filesystem access.
+ * SILC SFTP Interface is the implementation of the Secure File Transfer
+ * Protocol (or SSH 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, and when used in SILC the SFTP packets are
+ * encapsulated into SILC packets.  The SFTP server implementation is
+ * filesystem independent and generic interface is defined to represent
+ * filesystem access.
  *
- *    The SilcSFTP context is the actual SFTP client or SFTP server, and
- *    each SFTP session (associated to a socket connection) must create
- *    own SFTP context.
+ * The SilcSFTP context is the actual SFTP client or SFTP server, and each
+ * SFTP session should create its own SFTP context.
+ *
+ * The SILC SFTP library is a generic SFTP implementation and not directly
+ * related to either SILC or SSH.  It could be used for any general purpose
+ * SFTP application.
  *
  ***/
 
 /****s* silcsftp/SilcSFTPAPI/SilcSFTP
  *
  * NAME
- * 
+ *
  *    typedef struct SilcSFTPStruct *SilcSFTP;
  *
  * DESCRIPTION
@@ -47,7 +52,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,7 +61,7 @@ typedef struct SilcSFTPStruct *SilcSFTP;
 /****d* silcsftp/SilcSFTPAPI/SilcSFTPVersion
  *
  * NAME
- * 
+ *
  *    typedef SilcUInt32 SilcSFTPVersion;
  *
  * DESCRIPTION
@@ -74,7 +79,7 @@ typedef SilcUInt32 SilcSFTPVersion;
 /****d* silcsftp/SilcSFTPAPI/SilcSFTPStatus
  *
  * NAME
- * 
+ *
  *    typedef enum { ... } SilcSFTPStatus
  *
  * DESCRIPTION
@@ -92,16 +97,36 @@ typedef enum {
   SILC_SFTP_STATUS_PERMISSION_DENIED   = 3,  /* No sufficient permissions */
   SILC_SFTP_STATUS_FAILURE             = 4,  /* Operation failed */
   SILC_SFTP_STATUS_BAD_MESSAGE         = 5,  /* Bad message received */
-  SILC_SFTP_STATUS_NO_CONNECTION       = 6,  /* No connection to server */
+  SILC_SFTP_STATUS_NO_CONNECTION       = 6,  /* No connection to remote */
   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,13 +150,13 @@ 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.
  *
  ***/
@@ -152,7 +177,7 @@ typedef struct {
 /****s* silcsftp/SilcSFTPAPI/SilcSFTPName
  *
  * NAME
- * 
+ *
  *    typedef struct { ... } *SilcSFTPName, SilcSFTPNameStruct
  *
  * DESCRIPTION
@@ -173,7 +198,7 @@ typedef struct {
 /****s* silcsftp/SilcSFTPAPI/SilcSFTPHandle
  *
  * NAME
- * 
+ *
  *    typedef struct SilcSFTPHandleStruct *SilcSFTPHandle;
  *
  * DESCRIPTION
@@ -185,22 +210,6 @@ typedef struct {
  ***/
 typedef struct SilcSFTPHandleStruct *SilcSFTPHandle;
 
-/****f* silcsftp/SilcSFTPAPI/SilcSFTPSendPacketCallback
- *
- * SYNOPSIS
- *
- *    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 remote host.
- *
- ***/
-typedef void (*SilcSFTPSendPacketCallback)(SilcBuffer packet, void *context);
-
 /****f* silcsftp/SilcSFTPAPI/SilcSFTPVersionCallback
  *
  * SYNOPSIS
@@ -222,6 +231,25 @@ typedef void (*SilcSFTPVersionCallback)(SilcSFTP sftp,
                                        SilcSFTPVersion version,
                                        void *context);
 
+/****f* silcsftp/SilcSFTPAPI/SilcSFTPErrorCallback
+ *
+ * SYNOPSIS
+ *
+ *    typedef void (*SilcSFTPErrorCallback)(SilcSFTP sftp,
+ *                                          SilcSFTPStatus status,
+ *                                          void *context);
+ *
+ * DESCRIPTION
+ *
+ *    Error callback is called if a connection error occurs during SFTP
+ *    session.  If the connection or stream is closed this callback is
+ *    called.  Other errors are delivered in other callbacks.
+ *
+ ***/
+typedef void (*SilcSFTPErrorCallback)(SilcSFTP sftp,
+                                     SilcSFTPStatus status,
+                                     void *context);
+
 /****f* silcsftp/SilcSFTPAPI/SilcSFTPStatusCallback
  *
  * SYNOPSIS
@@ -366,9 +394,10 @@ typedef void (*SilcSFTPExtendedCallback)(SilcSFTP sftp,
  *
  * SYNOPSIS
  *
- *    SilcSFTP silc_sftp_client_start(SilcSFTPSendPacketCallback send_packet,
- *                                    void *send_context,
- *                                    SilcSFTPVersionCallback callback,
+ *    SilcSFTP silc_sftp_client_start(SilcStream stream,
+ *                                    SilcSchedule schedule,
+ *                                    SilcSFTPVersionCallback version_cb,
+ *                                    SilcSFTPErrorCallback error_cb,
  *                                    void *context);
  *
  * DESCRIPTION
@@ -377,13 +406,14 @@ typedef void (*SilcSFTPExtendedCallback)(SilcSFTP sftp,
  *    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.
+ *    allocated SFTP client context or NULL on error.  The `stream' will be
+ *    used to read and write the SFTP packets.
  *
  ***/
-SilcSFTP silc_sftp_client_start(SilcSFTPSendPacketCallback send_packet,
-                               void *send_context,
-                               SilcSFTPVersionCallback callback,
+SilcSFTP silc_sftp_client_start(SilcStream stream,
+                               SilcSchedule schedule,
+                               SilcSFTPVersionCallback version_cb,
+                               SilcSFTPErrorCallback error_cb,
                                void *context);
 
 /****f* silcsftp/SilcSFTPAPI/silc_sftp_client_shutdown
@@ -401,18 +431,11 @@ SilcSFTP silc_sftp_client_start(SilcSFTPSendPacketCallback send_packet,
  ***/
 void silc_sftp_client_shutdown(SilcSFTP sftp);
 
-/* 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. */
-void silc_sftp_client_receive_process(SilcSFTP sftp,
-                                     SilcSocketConnection sock,
-                                     SilcPacketContext *packet);
-
 /****f* silcsftp/SilcSFTPAPI/silc_sftp_open
  *
  * SYNOPSIS
  *
- *    void silc_sftp_open(SilcSFTP sftp, 
+ *    void silc_sftp_open(SilcSFTP sftp,
  *                        const char *filename,
  *                        SilcSFTPFileOperation pflags,
  *                        SilcSFTPAttributes attrs,
@@ -426,7 +449,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,
@@ -459,7 +482,7 @@ void silc_sftp_close(SilcSFTP sftp,
  *
  *    void silc_sftp_read(SilcSFTP sftp,
  *                        SilcSFTPHandle handle,
- *                        SilcUInt64 offset, 
+ *                        SilcUInt64 offset,
  *                        SilcUInt32 len,
  *                        SilcSFTPDataCallback callback,
  *                        void *context);
@@ -473,7 +496,7 @@ void silc_sftp_close(SilcSFTP sftp,
  ***/
 void silc_sftp_read(SilcSFTP sftp,
                    SilcSFTPHandle handle,
-                   SilcUInt64 offset, 
+                   SilcUInt64 offset,
                    SilcUInt32 len,
                    SilcSFTPDataCallback callback,
                    void *context);
@@ -493,7 +516,7 @@ void silc_sftp_read(SilcSFTP sftp,
  * 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.
  *
  ***/
@@ -814,7 +837,7 @@ void silc_sftp_realpath(SilcSFTP sftp,
  *
  * 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.
  *
@@ -835,21 +858,25 @@ void silc_sftp_extended(SilcSFTP sftp,
  *
  * SYNOPSIS
  *
- *    SilcSFTP silc_sftp_server_start(SilcSFTPSendPacketCallback send_packet,
- *                                    void *send_context, 
+ *    SilcSFTP silc_sftp_server_start(SilcStream stream,
+ *                                    SilcSchedule schedule,
+ *                                    SilcSFTPErrorCallback error_cb,
+ *                                    void *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'
+ *    the allocated SFTP server 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, 
+SilcSFTP silc_sftp_server_start(SilcStream stream,
+                               SilcSchedule schedule,
+                               SilcSFTPErrorCallback error_cb,
+                               void *context,
                                SilcSFTPFilesystem fs);
 
 /****f* silcsftp/SilcSFTPAPI/silc_sftp_server_shutdown
@@ -870,7 +897,7 @@ void silc_sftp_server_shutdown(SilcSFTP sftp);
 /****d* silcsftp/SilcSFTPAPI/SilcSFTPMonitors
  *
  * NAME
- * 
+ *
  *    typedef enum { ... } SilcSFTPMonitors;
  *
  * DESCRIPTION
@@ -907,7 +934,7 @@ typedef enum {
 /****s* silcsftp/SilcSFTPAPI/SilcSFTPMonitorData
  *
  * NAME
- * 
+ *
  *    typedef struct { ... } *SilcSFTPMonitorData, SilcSFTPMonitorDataStruct;
  *
  * DESCRIPTION
@@ -958,26 +985,19 @@ typedef void (*SilcSFTPMonitor)(SilcSFTP sftp,
  *
  *    void silc_sftp_server_set_monitor(SilcSFTP sftp,
  *                                      SilcSFTPMonitors monitors,
- *                                      SilcSFTPMonitor monitor, 
+ *                                      SilcSFTPMonitor monitor,
  *                                      void *context);
  *
  * DESCRIPTION
  *
- *    Sets monitor callback to monitor various request sent by an client.
+ *    Sets monitor callback to monitor various request sent by a 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, 
+                                 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. */
-void silc_sftp_server_receive_process(SilcSFTP sftp,
-                                     SilcSocketConnection sock,
-                                     SilcPacketContext *packet);
-
 #endif /* SILCSFTP_H */