changeset 390:0444232dc494

2003-2-3 Brian Masney <masneyb@gftp.org> * lib/ftpcommon.h lib/ftps.c lib/rfc959.c - added pointers to read/write functions to the rfc959_params structure for the data connection. For now, this is always set to the plaintext version.
author masneyb
date Wed, 04 Feb 2004 02:20:33 +0000
parents b39a312323ec
children 901b826c057d
files ChangeLog lib/ftpcommon.h lib/ftps.c lib/rfc959.c
diffstat 4 files changed, 37 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Feb 04 01:53:06 2004 +0000
+++ b/ChangeLog	Wed Feb 04 02:20:33 2004 +0000
@@ -1,4 +1,8 @@
 2003-2-3 Brian Masney <masneyb@gftp.org>
+	* lib/ftpcommon.h lib/ftps.c lib/rfc959.c - added pointers to
+	read/write functions to the rfc959_params structure for the data
+	connection. For now, this is always set to the plaintext version. 
+
 	* lib/Makefile.am lib/gftp.h lib/options.h lib/rfc959.c lib/ftpcommon.h
 	lib/ftps.c - added support for the FTPS protocol. This currently is only
 	for the control connection. (draft-murray-auth-ftp-ssl-09.txt)
@@ -2153,7 +2157,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.216 2004/02/04 01:53:02 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.217 2004/02/04 02:20:29 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/ftpcommon.h	Wed Feb 04 01:53:06 2004 +0000
+++ b/lib/ftpcommon.h	Wed Feb 04 02:20:33 2004 +0000
@@ -27,8 +27,13 @@
                       * dataconn_rbuf;
   int data_connection;
   unsigned int is_ascii_transfer : 1,
-               sent_retr : 1; 
+               sent_retr : 1,
+               encrypted_connection : 1;
   int (*auth_tls_start) (gftp_request * request);
+  ssize_t (*data_conn_read) (gftp_request * request, void *ptr, size_t size,
+                             int fd);
+  ssize_t (*data_conn_write) (gftp_request * request, const char *ptr,
+                              size_t size, int fd);
 };
 
 typedef struct rfc959_params_tag rfc959_parms;
--- a/lib/ftps.c	Wed Feb 04 01:53:06 2004 +0000
+++ b/lib/ftps.c	Wed Feb 04 02:20:33 2004 +0000
@@ -55,9 +55,26 @@
   if (ret < 0)
     return (ret);
 
-  ret = rfc959_send_command (request, "PROT C\r\n", 1);
+  ret = '5'; /* FIXME */
+  /* ret = rfc959_send_command (request, "PROT P\r\n", 1); */
   if (ret < 0)
     return (ret);
+  else if (ret == '2')
+    {
+      params->data_conn_read = gftp_ssl_read;
+      params->data_conn_write = gftp_ssl_write;
+      params->encrypted_connection = 1;
+    }
+  else
+    {
+      ret = rfc959_send_command (request, "PROT C\r\n", 1);
+      if (ret < 0)
+        return (ret);
+
+      params->data_conn_read = gftp_fd_read;
+      params->data_conn_write = gftp_fd_write;
+      params->encrypted_connection = 0;
+    }
 
   return (0);
 }
--- a/lib/rfc959.c	Wed Feb 04 01:53:06 2004 +0000
+++ b/lib/rfc959.c	Wed Feb 04 02:20:33 2004 +0000
@@ -1226,8 +1226,7 @@
   g_free (tempstr);
 
   tempstr = g_strconcat ("RETR ", fromfile, "\r\n", NULL);
-  if ((ret = gftp_fd_write (fromreq, tempstr, strlen (tempstr), /* FIXME */
-                         fromreq->datafd)) < 0)
+  if ((ret = rfc959_send_command (fromreq, tempstr, 0)) < 0)
     {
       g_free (tempstr);
       return (ret);
@@ -1235,8 +1234,7 @@
   g_free (tempstr);
 
   tempstr = g_strconcat ("STOR ", tofile, "\r\n", NULL);
-  if ((ret = gftp_fd_write (toreq, tempstr, strlen (tempstr),  /* FIXME */
-                            toreq->datafd)) < 0)
+  if ((ret = rfc959_send_command (toreq, tempstr, 0)) < 0)
     {
       g_free (tempstr);
       return (ret);
@@ -1361,7 +1359,7 @@
 
   parms = request->protocol_data;
 
-  num_read = gftp_fd_read (request, buf, size, parms->data_connection);
+  num_read = parms->data_conn_read (request, buf, size, parms->data_connection);
   if (num_read < 0)
     return (num_read);
 
@@ -1425,7 +1423,8 @@
       tempstr = buf;
     }
 
-  num_wrote = gftp_fd_write (request, tempstr, rsize, parms->data_connection);
+  num_wrote = parms->data_conn_write (request, tempstr, rsize,
+                                      parms->data_connection);
 
   if (tempstr != buf)
     g_free (tempstr);
@@ -1462,7 +1461,7 @@
   do
     {
       oldread_func = request->read_function;
-      request->read_function = gftp_fd_read;
+      request->read_function = parms->data_conn_read;
       len = gftp_get_line (request, &parms->dataconn_rbuf, tempstr,
                            sizeof (tempstr), fd);
       request->read_function = oldread_func;
@@ -1792,6 +1791,8 @@
   parms = request->protocol_data;
   parms->data_connection = -1; 
   parms->auth_tls_start = NULL;
+  parms->data_conn_read = gftp_fd_read;
+  parms->data_conn_write = gftp_fd_write;
 
   return (gftp_set_config_options (request));
 }