Merge commit 'origin/silc.1.1.branch'
[silc.git] / lib / silcsftp / silcsftp.h
index b7036a95fe47cf9875c734c8599a422a2500232f..d2364146c79f39c5f0254ce317efb6930748471f 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 - 2005 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 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
- *    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.
  *
  ***/
 
@@ -63,10 +68,8 @@ typedef struct SilcSFTPStruct *SilcSFTP;
  *
  *    SFTP Version type.
  *
- * SOURCE
- */
+ ***/
 typedef SilcUInt32 SilcSFTPVersion;
-/***/
 
 /* SFTP protocol version */
 #define SILC_SFTP_PROTOCOL_VERSION       3
@@ -92,7 +95,7 @@ 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 */
@@ -155,7 +158,7 @@ typedef enum {
  *    server, and by server to return file attributes to the client.
  *
  ***/
-typedef struct {
+typedef struct SilcSFTPAttributesObject {
   SilcUInt32 flags;            /* Flags to indicate present attributes */
   SilcUInt64 size;             /* Sife of the file in bytes */
   SilcUInt32 uid;                      /* Unix user ID */
@@ -183,7 +186,7 @@ typedef struct {
  *    example when reading the contents of a directory.
  *
  ***/
-typedef struct {
+typedef struct SilcSFTPNameObject {
   char **filename;
   char **long_filename;
   SilcSFTPAttributes *attrs;
@@ -205,22 +208,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
@@ -242,6 +229,27 @@ 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.  Only the
+ *    SILC_SFTP_STATUS_EOF or SILC_SFTP_STATUS_NO_CONNECTION is delivered
+ *    in this callback.
+ *
+ ***/
+typedef void (*SilcSFTPErrorCallback)(SilcSFTP sftp,
+                                     SilcSFTPStatus status,
+                                     void *context);
+
 /****f* silcsftp/SilcSFTPAPI/SilcSFTPStatusCallback
  *
  * SYNOPSIS
@@ -387,21 +395,29 @@ typedef void (*SilcSFTPExtendedCallback)(SilcSFTP sftp,
  * SYNOPSIS
  *
  *    SilcSFTP silc_sftp_client_start(SilcStream stream,
- *                                    SilcSFTPVersionCallback callback,
+ *                                    SilcSchedule schedule,
+ *                                    SilcSFTPVersionCallback version_cb,
+ *                                    SilcSFTPErrorCallback error_cb,
  *                                    void *context);
  *
  * DESCRIPTION
  *
  *    Starts SFTP client and returns context to it.  The version callback
- *    indicated by the `callback' will be called after the SFTP session has
+ *    indicated by the `version_cb' 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.  The `stream' will be
- *    used to read from and write to the SFTP packets.
+ *    used to read and write the SFTP packets.  The `error_cb' will be called
+ *    in case a stream error occurs, such as end of stream.
+ *
+ *    If `schedule' is NULL this will call silc_schedule_get_global to try to
+ *    get global scheduler.
  *
  ***/
 SilcSFTP silc_sftp_client_start(SilcStream stream,
-                               SilcSFTPVersionCallback callback,
+                               SilcSchedule schedule,
+                               SilcSFTPVersionCallback version_cb,
+                               SilcSFTPErrorCallback error_cb,
                                void *context);
 
 /****f* silcsftp/SilcSFTPAPI/silc_sftp_client_shutdown
@@ -413,8 +429,8 @@ SilcSFTP silc_sftp_client_start(SilcStream stream,
  * DESCRIPTION
  *
  *    Shutdown's the SFTP client.  The caller is responsible of closing
- *    the associated socket connection.  The SFTP context is freed and is
- *    invalid after this function returns.
+ *    the associated stream.  The SFTP context is freed and is invalid after
+ *    this function returns.
  *
  ***/
 void silc_sftp_client_shutdown(SilcSFTP sftp);
@@ -846,21 +862,29 @@ 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 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.
+ *    the allocated SFTP server context or NULL on error.  The `stream' is
+ *    the stream (connection) to the client.  The `error_cb' will be called
+ *    when the `stream' is ended (SILC_SFTP_STATUS_EOF).  The caller is
+ *    responsible of closing and destroying the `stream'.  The `fs' is the
+ *    filesystem context allocated by the application.
+ *
+ *    If `schedule' is NULL this will call silc_schedule_get_global to try to
+ *    get global scheduler.
  *
  ***/
-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
@@ -871,9 +895,9 @@ SilcSFTP silc_sftp_server_start(SilcSFTPSendPacketCallback send_packet,
  *
  * 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.
+ *    Shutdown the SFTP server.  The caller is responsible of closing the
+ *    associated stream.  The SFTP context is freed and is invalid after
+ *    this function returns.
  *
  ***/
 void silc_sftp_server_shutdown(SilcSFTP sftp);
@@ -925,11 +949,12 @@ typedef enum {
  *
  *    This structure includes the monitor type specific data.  The
  *    application can check what the client has requested from this
- *    structure.
+ *    structure.  See the comments below what data is available for what
+ *    monitor type.
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcSFTPMonitorDataObject {
   SilcSFTPVersion version;     /* _INIT */
   char *name;                  /* _OPEN, _REMOVE, _RENAME, _MKDIR,
                                   _RMDIR, _OPENDIR, _STAT, _LSTAT,