changeset 40:66c064fd05bc

2002-10-17 Brian Masney <masneyb@gftp.org> * lib/protocols.c - add gftp_abort_transfer function. Also, in gftp_transfer_file, when we do a gftp_put_file, if that fails, try to abort the transfer. * lib/rfc959.c - add rfc959_abort_transfer function * lib/rfc2068.c, lib/local.c - point abort_transfer pointer to rfc2068_end_transfer and local_end_transfer respectively * lib/ssh.c, lib/sshv2.c - add FIXME to implement abort function * src/gtk/transfer.c - when we stop a transfer, try to abort it first. If that fails, disconnect from the site completely
author masneyb
date Fri, 18 Oct 2002 02:53:52 +0000
parents 474d562c7268
children 4bcfaf6307b5
files ChangeLog TODO lib/gftp.h lib/local.c lib/protocols.c lib/rfc2068.c lib/rfc959.c lib/ssh.c lib/sshv2.c src/gtk/transfer.c
diffstat 10 files changed, 109 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Oct 16 02:11:09 2002 +0000
+++ b/ChangeLog	Fri Oct 18 02:53:52 2002 +0000
@@ -1,3 +1,18 @@
+2002-10-17 Brian Masney <masneyb@gftp.org>
+	* lib/protocols.c - add gftp_abort_transfer function. Also, in 
+	gftp_transfer_file, when we do a gftp_put_file, if that fails,
+	try to abort the transfer.
+
+	* lib/rfc959.c - add rfc959_abort_transfer function
+
+	* lib/rfc2068.c, lib/local.c - point abort_transfer pointer to 
+	rfc2068_end_transfer and local_end_transfer respectively
+
+	* lib/ssh.c, lib/sshv2.c - add FIXME to implement abort function
+
+	* src/gtk/transfer.c - when we stop a transfer, try to abort it 
+	first. If that fails, disconnect from the site completely
+
 2002-10-15 Brian Masney <masneyb@gftp.org>
 	* lib/config_file.c - enable combo in GTK port for Proxy server type
 
@@ -64,7 +79,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.18 2002/10/16 02:11:06 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.19 2002/10/18 02:53:50 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/TODO	Wed Oct 16 02:11:09 2002 +0000
+++ b/TODO	Fri Oct 18 02:53:52 2002 +0000
@@ -16,7 +16,6 @@
 * Full Gnome compatibility.
 * Add registered file extensions to options dialog
 * VMS directory listings
-* FTP: Send ABOR command when the users wants to stop the download
 * HTTP: Support CONNECT method in Squid proxy
 * FTP: Support rfc1639
 * Add support for SRP protocol (http://srp.stanford.edu/srp)
--- a/lib/gftp.h	Wed Oct 16 02:11:09 2002 +0000
+++ b/lib/gftp.h	Fri Oct 18 02:53:52 2002 +0000
@@ -246,6 +246,7 @@
 					  char *buf, 
 					  size_t size );
   int (*end_transfer) 			( gftp_request * request );
+  int (*abort_transfer) 		( gftp_request * request );
   int (*list_files) 			( gftp_request * request );
   int (*get_next_file)			( gftp_request * request, 
 					  gftp_file *fle, 
@@ -676,6 +677,8 @@
 
 int gftp_end_transfer 			( gftp_request * request );
 
+int gftp_abort_transfer 		( gftp_request * request );
+
 int gftp_read_response 			( gftp_request * request );
 
 int gftp_set_data_type 			( gftp_request * request, 
--- a/lib/local.c	Wed Oct 16 02:11:09 2002 +0000
+++ b/lib/local.c	Fri Oct 18 02:53:52 2002 +0000
@@ -90,6 +90,7 @@
   request->get_next_file_chunk = NULL;
   request->put_next_file_chunk = NULL;
   request->end_transfer = local_end_transfer;
+  request->abort_transfer = local_end_transfer; /* NOTE: uses end_transfer */
   request->list_files = local_list_files;
   request->get_next_file = local_get_next_file;
   request->set_data_type = NULL;
--- a/lib/protocols.c	Wed Oct 16 02:11:09 2002 +0000
+++ b/lib/protocols.c	Fri Oct 18 02:53:52 2002 +0000
@@ -225,7 +225,9 @@
 
   if (gftp_put_file (toreq, tofile, tofd, tosize, size) != 0)
     {
-      gftp_end_transfer (fromreq);
+      if (gftp_abort_transfer (fromreq) != 0)
+        gftp_end_transfer (fromreq);
+
       return (-2);
     }
 
@@ -329,19 +331,18 @@
 
   g_return_val_if_fail (request != NULL, -2);
 
-  if (request->end_transfer == NULL)
-    return (-2);
+  if (!request->cached && 
+      request->end_transfer != NULL)
+    ret = request->end_transfer (request);
+  else
+    ret = 0;
 
-  ret = 0;
   if (request->cachefd != NULL)
     {
       fclose (request->cachefd);
       request->cachefd = NULL;
     }
 
-  if (!request->cached)
-    ret = request->end_transfer (request);
-
   if (request->last_dir_entry)
     {
       g_free (request->last_dir_entry);
@@ -354,6 +355,18 @@
 
 
 int
+gftp_abort_transfer (gftp_request * request)
+{
+  g_return_val_if_fail (request != NULL, -2);
+
+  if (request->abort_transfer == NULL)
+    return (-2);
+
+  return (request->abort_transfer (request));
+}
+
+
+int
 gftp_list_files (gftp_request * request)
 {
   FILE * fd;
--- a/lib/rfc2068.c	Wed Oct 16 02:11:09 2002 +0000
+++ b/lib/rfc2068.c	Fri Oct 18 02:53:52 2002 +0000
@@ -69,6 +69,7 @@
   request->get_next_file_chunk = rfc2068_get_next_file_chunk;
   request->put_next_file_chunk = NULL;
   request->end_transfer = rfc2068_end_transfer;
+  request->abort_transfer = rfc2068_end_transfer; /* NOTE: uses end_transfer */
   request->list_files = rfc2068_list_files;
   request->get_next_file = rfc2068_get_next_file;
   request->set_data_type = NULL;
--- a/lib/rfc959.c	Wed Oct 16 02:11:09 2002 +0000
+++ b/lib/rfc959.c	Fri Oct 18 02:53:52 2002 +0000
@@ -38,6 +38,7 @@
 						  const char *tofile, 
 						  off_t tosize );
 static int rfc959_end_transfer 			( gftp_request * request );
+static int rfc959_abort_transfer 		( gftp_request * request );
 static int rfc959_list_files 			( gftp_request * request );
 static int rfc959_set_data_type 		( gftp_request * request, 
 						  int data_type );
@@ -84,6 +85,7 @@
   request->get_next_file_chunk = NULL;
   request->put_next_file_chunk = NULL;
   request->end_transfer = rfc959_end_transfer;
+  request->abort_transfer = rfc959_abort_transfer;
   request->list_files = rfc959_list_files;
   request->get_next_file = rfc959_get_next_file;
   request->set_data_type = rfc959_set_data_type;
@@ -336,14 +338,7 @@
   g_free (tempstr);
 
   if (ret != '1')
-    {
-      if (request->datafd != NULL)
-        {
-          fclose (request->datafd);
-          request->datafd = NULL;
-        }
-      return (-2);
-    }
+    return (-2);
 
   if (request->transfer_type == gftp_transfer_active &&
       (ret = rfc959_accept_active_connection (request)) < 0)
@@ -410,14 +405,7 @@
   ret = rfc959_send_command (request, tempstr);
   g_free (tempstr);
   if (ret != '1')
-    {
-      if (request->datafd != NULL)
-        {
-          fclose (request->datafd);
-          request->datafd = NULL;
-        }
-      return (-2);
-    }
+    return (-2);
 
   if (request->transfer_type == gftp_transfer_active && 
       (ret = rfc959_accept_active_connection (request)) < 0)
@@ -509,6 +497,37 @@
 
 
 static int
+rfc959_abort_transfer (gftp_request * request)
+{
+  int ret;
+
+  g_return_val_if_fail (request != NULL, -2);
+  g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, -2);
+  g_return_val_if_fail (request->sockfd != NULL, -2);
+
+  if (request->datafd)
+    {
+      fclose (request->datafd);
+      request->datafd = NULL;
+    }
+
+  /* We need to read two lines of output. The first one is acknowleging
+     the transfer and the second line acknowleges the ABOR command */
+  rfc959_send_command (request, "ABOR\r\n");
+
+  if (request->sockfd != NULL)
+    {
+      ret = rfc959_read_response (request);
+
+      if (ret != '2')
+        gftp_disconnect (request);
+    }
+  
+  return (0);
+}
+
+
+static int
 rfc959_list_files (gftp_request * request)
 {
   char *tempstr, parms[3];
@@ -828,10 +847,7 @@
     }
 
   if (write_to_socket (request, command) < 0)
-    {
-      gftp_disconnect (request);
-      return (-1);
-    }
+    return (-1);
 
   return (rfc959_read_response (request));
 }
@@ -929,7 +945,8 @@
   request->last_ftp_response = g_malloc (strlen (tempstr) + 1);
   strcpy (request->last_ftp_response, tempstr);
 
-  if (*request->last_ftp_response == '4')
+  if (request->last_ftp_response[0] == '4' &&
+      request->last_ftp_response[1] == '2')
     gftp_disconnect (request);
 
   return (*request->last_ftp_response);
--- a/lib/ssh.c	Wed Oct 16 02:11:09 2002 +0000
+++ b/lib/ssh.c	Fri Oct 18 02:53:52 2002 +0000
@@ -139,6 +139,7 @@
   request->get_next_file_chunk = ssh_get_next_file_chunk;
   request->put_next_file_chunk = ssh_put_next_file_chunk;
   request->end_transfer = ssh_end_transfer;
+  request->abort_transfer = NULL; /* FIXME */
   request->list_files = ssh_list_files;
   request->get_next_file = ssh_get_next_file;
   request->set_data_type = NULL;
--- a/lib/sshv2.c	Wed Oct 16 02:11:09 2002 +0000
+++ b/lib/sshv2.c	Fri Oct 18 02:53:52 2002 +0000
@@ -193,6 +193,7 @@
   request->get_next_file_chunk = sshv2_get_next_file_chunk;
   request->put_next_file_chunk = sshv2_put_next_file_chunk;
   request->end_transfer = sshv2_end_transfer;
+  request->abort_transfer = NULL; /* FIXME */
   request->list_files = sshv2_list_files;
   request->get_next_file = sshv2_get_next_file;
   request->set_data_type = NULL;
--- a/src/gtk/transfer.c	Wed Oct 16 02:11:09 2002 +0000
+++ b/src/gtk/transfer.c	Fri Oct 18 02:53:52 2002 +0000
@@ -709,7 +709,15 @@
             }
         }
 
-      if (num_read < 0 || transfer->cancel)
+      if (transfer->cancel)
+        {
+          if (gftp_abort_transfer (transfer->fromreq) != 0)
+            gftp_disconnect (transfer->fromreq);
+
+          if (gftp_abort_transfer (transfer->toreq) != 0)
+            gftp_disconnect (transfer->toreq);
+        }
+      else if (num_read < 0)
         {
           transfer->fromreq->logging_function (gftp_logging_misc, 
                                         transfer->fromreq->user_data, 
@@ -718,15 +726,14 @@
                                         transfer->fromreq->hostname);
 
           if (get_status (transfer, num_read) == 1)
-            {
-              transfer->cancel = 0;
-              continue;
-            }
+            continue;
+
           break;
         }
       else
         {
-          /* FIXME - this needs cleaned up. NOTE: view/edit file will be broken if the file hsa to be resumed */
+          /* FIXME - this needs cleaned up. NOTE: view/edit file will be 
+             broken if the file has to be resumed */
           if (curfle->is_fd)
             {
               if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD)
@@ -738,10 +745,8 @@
           if (gftp_end_transfer (transfer->fromreq) != 0)
             {
               if (get_status (transfer, -1) == 1)
-                {
-                  transfer->cancel = 0;
-                  continue;
-                }
+                continue;
+
               break;
             }
           gftp_end_transfer (transfer->toreq);
@@ -1066,9 +1071,10 @@
 
   tdata->fromreq->stopable = 0;
   tdata->toreq->stopable = 0;
+  pthread_mutex_unlock (tdata->structmutex);
+
   ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer of %s\n"),
 	   ((gftp_file *) tdata->curfle->data)->file);
-  pthread_mutex_unlock (tdata->structmutex);
 }
 
 
@@ -1365,9 +1371,10 @@
     }
   else
     transdata->transfer->done = 1;
+  pthread_mutex_unlock (transdata->transfer->structmutex);
+
   ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"),
 	   transdata->transfer->fromreq->hostname);
-  pthread_mutex_unlock (transdata->transfer->structmutex);
 }
 
 
@@ -1377,6 +1384,7 @@
   gftp_curtrans_data * transdata;
   GtkCTreeNode * node;
   gftp_file * curfle;
+  char *file;
 
   if (GTK_CLIST (dlwdw)->selection == NULL)
     {
@@ -1398,10 +1406,14 @@
         }
 
       curfle->transfer_action = GFTP_TRANS_ACTION_SKIP;
-      ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), 
-               curfle->file, transdata->transfer->fromreq->hostname);
+      file = curfle->file;
     }
+  else
+    file = NULL;
   pthread_mutex_unlock (transdata->transfer->structmutex);
+
+  ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), 
+           file, transdata->transfer->fromreq->hostname);
 }
 
 
@@ -1449,10 +1461,10 @@
       transdata->transfer->total_bytes -= curfle->size;
     }
 
+  pthread_mutex_unlock (transdata->transfer->structmutex);
+
   ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"),
            curfle->file, transdata->transfer->fromreq->hostname);
-
-  pthread_mutex_unlock (transdata->transfer->structmutex);
 }