updates
authorPekka Riikonen <priikone@silcnet.org>
Thu, 2 May 2002 13:08:23 +0000 (13:08 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 2 May 2002 13:08:23 +0000 (13:08 +0000)
apps/irssi/src/silc/core/silc-servers.c
lib/silcclient/client_ftp.c
lib/silcclient/silcclient.h

index d258c4c7802eec282e83b1a2521e20cc470fd9ce..ba829c82c4f96e93d331440131f0369b0d47661a 100644 (file)
@@ -723,7 +723,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
       }
 
       ret = silc_client_file_receive(silc_client, conn, 
-                                    silc_client_file_monitor, server,
+                                    silc_client_file_monitor, server, NULL,
                                     server->current_session->session_id);
       if (ret != SILC_CLIENT_FILE_OK) {
        if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
@@ -744,7 +744,7 @@ static void command_file(const char *data, SILC_SERVER_REC *server,
       if (ftp->client_entry == client_entry && !ftp->filepath) {
        ret = silc_client_file_receive(silc_client, conn, 
                                       silc_client_file_monitor, server,
-                                      ftp->session_id);
+                                      NULL, ftp->session_id);
        if (ret != SILC_CLIENT_FILE_OK) {
          if (ret == SILC_CLIENT_FILE_ALREADY_STARTED)
            printformat_module("fe-common/silc", server, NULL,
index 87a1f4c9e51b05c0f74d78b0779d550976b23e88..24233fc8fc5a2f84056f3dcd05a69182abec5d6f 100644 (file)
@@ -49,6 +49,7 @@ struct SilcClientFtpSessionStruct {
   SilcClientFileMonitor monitor;
   void *monitor_context;
   char *filepath;
+  char *path;
 
   SilcSFTP sftp;
   SilcSFTPFilesystem fs;
@@ -291,6 +292,7 @@ static void silc_client_ftp_open_handle(SilcSFTP sftp,
                                        void *context)
 {
   SilcClientFtpSession session = (SilcClientFtpSession)context;
+  char path[512];
 
   SILC_LOG_DEBUG(("Start"));
 
@@ -310,8 +312,14 @@ static void silc_client_ftp_open_handle(SilcSFTP sftp,
   }
 
   /* Open the actual local file */
-  session->fd = silc_file_open(session->filepath, 
-                              O_RDWR | O_CREAT | O_EXCL);
+  memset(path, 0, sizeof(path));
+  if (session->path && strlen(session->path) < sizeof(path))
+    strncat(path, session->path, strlen(session->path));
+  if (strlen(session->filepath) > sizeof(path) - strlen(path))
+    strncat(path, session->filepath, sizeof(path) - strlen(path) - 1);
+  else
+    strncat(path, session->filepath, strlen(session->filepath));
+  session->fd = silc_file_open(path, O_RDWR | O_CREAT | O_EXCL);
   if (session->fd < 0) {
     /* Call monitor callback */
     session->client->internal->ops->say(session->client, session->conn, 
@@ -379,7 +387,7 @@ static void silc_client_ftp_readdir_name(SilcSFTP sftp,
   silc_sftp_open(sftp, name->filename[0], SILC_SFTP_FXF_READ, &attr,
                 silc_client_ftp_open_handle, session);
 
-  /* Save the important attributes */
+  /* Save the important attributes like filename and file size */
   session->filepath = strdup(name->filename[0]);
   session->filesize = name->attrs[0]->size;
 
@@ -891,6 +899,7 @@ silc_client_file_receive(SilcClient client,
                         SilcClientConnection conn,
                         SilcClientFileMonitor monitor,
                         void *monitor_context,
+                        const char *path,
                         SilcUInt32 session_id)
 {
   SilcClientFtpSession session;
@@ -920,6 +929,7 @@ silc_client_file_receive(SilcClient client,
   session->monitor = monitor;
   session->monitor_context = monitor_context;
   session->conn = conn;
+  session->path = path ? strdup(path) : NULL;
 
   /* If the hostname and port already exists then the remote client did
      provide the connection point to us and we won't create listener, but
index 7e0de3f350f9e83d12227896151280e4d7539309..b0ef27efcd4c026dc1025dc1796935481b9d14e2 100644 (file)
@@ -2128,6 +2128,7 @@ silc_client_file_send(SilcClient client,
  *                             SilcClientConnection conn,
  *                             SilcClientFileMonitor monitor,
  *                             void *monitor_context,
+ *                             const char *path,
  *                             SilcUInt32 session_id);
  *
  * DESCRIPTION
@@ -2137,7 +2138,9 @@ silc_client_file_send(SilcClient client,
  *    received in the `ftp' client operation function.  This will actually
  *    perform the key agreement protocol with the remote client before
  *    actually starting the file transmission.  The `monitor' callback
- *    will be called to monitor the transmission.
+ *    will be called to monitor the transmission.  If `path' is non NULL
+ *    the file will be saved into that directory.  If NULL the file is
+ *    saved in the current working directory.
  *
  *    If error will occur during the file transfer process the error
  *    status will be returned in the monitor callback.  In this case
@@ -2150,6 +2153,7 @@ silc_client_file_receive(SilcClient client,
                         SilcClientConnection conn,
                         SilcClientFileMonitor monitor,
                         void *monitor_context,
+                        const char *path,
                         SilcUInt32 session_id);
 
 /****f* silcclient/SilcClientAPI/silc_client_file_close