Mercurial > gftp.yaz
changeset 893:331d6ad73a75
2007-3-15 Brian Masney <masneyb@gftp.org>
* lib/rfc959.c - added new function rfc959_setup_file_transfer(). It
elimnates some duplicate code that was found by CPD.
author | masneyb |
---|---|
date | Fri, 16 Mar 2007 01:23:46 +0000 |
parents | ecd9a397c441 |
children | 14476a8a4d2b |
files | ChangeLog lib/rfc959.c |
diffstat | 2 files changed, 35 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Mar 16 00:52:59 2007 +0000 +++ b/ChangeLog Fri Mar 16 01:23:46 2007 +0000 @@ -1,7 +1,10 @@ 2007-3-15 Brian Masney <masneyb@gftp.org> + * lib/rfc959.c - added new function rfc959_setup_file_transfer(). It + elimnates some duplicate code that was found by CPD. + * lib/sshv2.c - added new function sshv2_send_command_and_check_response(). It eliminates some duplicate - code that was found by PMD. + code that was found by CPD. * docs/gftp-faq.sgml - updated FAQ entry about how to check the latest code out of SVN.
--- a/lib/rfc959.c Fri Mar 16 00:52:59 2007 +0000 +++ b/lib/rfc959.c Fri Mar 16 01:23:46 2007 +0000 @@ -1163,22 +1163,16 @@ } -static off_t -rfc959_get_file (gftp_request * request, const char *filename, int fd, - off_t startsize) +static int +rfc959_setup_file_transfer (gftp_request * request, const char *filename, + off_t startsize, char *transfer_command) { - char *command, *tempstr; intptr_t passive_transfer; rfc959_parms * parms; + char *command; int ret; - g_return_val_if_fail (request != NULL, GFTP_EFATAL); - g_return_val_if_fail (filename != NULL, GFTP_EFATAL); - g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL); - parms = request->protocol_data; - if (fd > 0) - parms->data_connection = fd; if ((ret = rfc959_set_data_type (request, filename)) < 0) return (ret); @@ -1206,7 +1200,8 @@ } } - ret = rfc959_generate_and_send_command (request, "RETR", filename, 1, 0); + ret = rfc959_generate_and_send_command (request, transfer_command, filename, + 1, 0); if (ret < 0) return (ret); else if (ret != '1') @@ -1224,6 +1219,30 @@ (ret = rfc959_accept_active_connection (request)) < 0) return (ret); + return (0); +} + + +static off_t +rfc959_get_file (gftp_request * request, const char *filename, int fd, + off_t startsize) +{ + rfc959_parms * parms; + char *tempstr; + int ret; + + g_return_val_if_fail (request != NULL, GFTP_EFATAL); + g_return_val_if_fail (filename != NULL, GFTP_EFATAL); + g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL); + + parms = request->protocol_data; + if (fd > 0) + parms->data_connection = fd; + + ret = rfc959_setup_file_transfer (request, filename, startsize, "RETR"); + if (ret < 0) + return (ret); + if ((tempstr = strrchr (request->last_ftp_response, '(')) == NULL) { tempstr = request->last_ftp_response + 4; @@ -1241,8 +1260,6 @@ rfc959_put_file (gftp_request * request, const char *filename, int fd, off_t startsize, off_t totalsize) { - intptr_t passive_transfer; - char *command; rfc959_parms * parms; int ret; @@ -1261,43 +1278,7 @@ (ret = rfc959_data_connection_new (request, 0)) < 0) return (ret); - if ((ret = gftp_fd_set_sockblocking (request, parms->data_connection, 1)) < 0) - return (ret); - - if (startsize > 0) - { - command = g_strdup_printf ("REST " GFTP_OFF_T_PRINTF_MOD "\r\n", - startsize); - ret = rfc959_send_command (request, command, -1, 1, 0); - g_free (command); - if (ret < 0) - return (ret); - else if (ret != '3') - { - rfc959_close_data_connection (request); - return (GFTP_ERETRYABLE); - } - } - - ret = rfc959_generate_and_send_command (request, "STOR", filename, 1, 0); - if (ret < 0) - return (ret); - else if (ret != '1') - { - rfc959_close_data_connection (request); - - if (ret == '5') - return (GFTP_EFATAL); - else - return (GFTP_ERETRYABLE); - } - - gftp_lookup_request_option (request, "passive_transfer", &passive_transfer); - if (!passive_transfer && - (ret = rfc959_accept_active_connection (request)) < 0) - return (ret); - - return (0); + return (rfc959_setup_file_transfer (request, filename, startsize, "STOR")); }