Mercurial > gftp.yaz
diff lib/local.c @ 58:c01d91c10f6c
2002-11-20 Brian Masney <masneyb@gftp.org>
* lib/protocols.c lib/gftp.h - added gftp_get_line(), gftp_read(),
gftp_write(), gftp_writefmt(), and gftp_set_sockblocking() functions.
Added struct_gftp_getline_buffer for gftp_get_line function()
* lib/cache.c lib/gftp.h lib/local.c lib/misc.c lib/protocols.c
lib/rfc2068.c lib/rfc959.c lib/ssh.c lib/sshv2.c - *_get_file() returns
off_t instead of long. *_{get,put}_next_file_chunk returns ssize_t
instead of size_t. Added *_set_config_options function to gftp_request
structure and protocol files. Use the new network functions
documented above. Convert usage of ANSI C IO (FILE *) to standard BSD
sockets so that I can use timeouts properly with select
* lib/misc.c (ssh_start_login_sequence) - use gftp_set_sockblock(),
gftp_read() and gftp_write() functions
* lib/protocols.c - move some protocol specific code to the protocol
specific files
* lib/local.c - log succesful messages to gftp_logging_misc instead
of gftp_logging_error
* lib/cache.c - log some more error conditions to the user
* lib/rfc959.c - added rfc959_getcwd(). In,
rfc959_accept_active_connection(), set set socket to blocking mode
before calling accept()
* src/text/gftk-text.c - If we get no files in gftp_text_ls(),
return instead of segfaulting
* src/gtk/gftp-gtk.c - expand the port field in the toolbar to be 45
pixels wide
* src/text/gftp-text.c src/gtk/misc-gtk.c src/gtk/transfer.c
src/gtk/view_dialog.c - changes for conversion of request->{sock,data}
from ANSI C IO (FILE *) to standard BSD sockets
author | masneyb |
---|---|
date | Thu, 21 Nov 2002 00:33:51 +0000 |
parents | e5f6054590b5 |
children | 1af41fb08509 |
line wrap: on
line diff
--- a/lib/local.c Tue Nov 12 00:04:44 2002 +0000 +++ b/lib/local.c Thu Nov 21 00:33:51 2002 +0000 @@ -59,9 +59,6 @@ g_return_val_if_fail (request != NULL, -2); g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2); - /* Just to simulate that we are actually connected */ - request->sockfd = (void *) 1; - if (request->directory) { if (chdir (request->directory) != 0) @@ -95,81 +92,62 @@ g_return_if_fail (request != NULL); g_return_if_fail (request->protonum == GFTP_LOCAL_NUM); - if (request->datafd != NULL) + if (request->datafd != -1) { - if (fclose (request->datafd) < 0) + if (close (request->datafd) < 0) request->logging_function (gftp_logging_error, request->user_data, _("Error closing file descriptor: %s\n"), g_strerror (errno)); - request->datafd = NULL; + request->datafd = -1; } - request->sockfd = NULL; } -static long -local_get_file (gftp_request * request, const char *filename, FILE * fd, +static off_t +local_get_file (gftp_request * request, const char *filename, int fd, off_t startsize) { - size_t size; - int sock, flags; + off_t size; + int flags; g_return_val_if_fail (request != NULL, -2); g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2); g_return_val_if_fail (filename != NULL, -2); - if (fd == NULL) + if (fd > 0) { flags = O_RDONLY; #if defined (_LARGEFILE_SOURCE) flags |= O_LARGEFILE; #endif - if ((sock = open (filename, flags)) < 0) + if ((request->datafd = open (filename, flags)) < 0) { request->logging_function (gftp_logging_error, request->user_data, _("Error: Cannot open local file %s: %s\n"), filename, g_strerror (errno)); return (-2); } - - if ((request->datafd = fdopen (sock, "rb")) == NULL) - { - request->logging_function (gftp_logging_error, request->user_data, - _("Cannot fdopen() socket for %s: %s\n"), - filename, g_strerror (errno)); - close (sock); - return (-2); - } } else request->datafd = fd; - if (lseek (fileno (request->datafd), 0, SEEK_END) == -1) + if ((size = lseek (request->datafd, 0, SEEK_END)) == -1) { request->logging_function (gftp_logging_error, request->user_data, _("Error: Cannot seek on file %s: %s\n"), filename, g_strerror (errno)); - fclose (request->datafd); - request->datafd = NULL; + gftp_disconnect (request); + return (-1); } - if ((size = ftell (request->datafd)) == -1) + if (lseek (request->datafd, startsize, SEEK_SET) == -1) { request->logging_function (gftp_logging_error, request->user_data, _("Error: Cannot seek on file %s: %s\n"), filename, g_strerror (errno)); - fclose (request->datafd); - request->datafd = NULL; - } - - if (lseek (fileno (request->datafd), startsize, SEEK_SET) == -1) - { - request->logging_function (gftp_logging_error, request->user_data, - _("Error: Cannot seek on file %s: %s\n"), - filename, g_strerror (errno)); - fclose (request->datafd); - request->datafd = NULL; + gftp_disconnect (request); + return (-1); } return (size); @@ -177,16 +155,16 @@ static int -local_put_file (gftp_request * request, const char *filename, FILE * fd, +local_put_file (gftp_request * request, const char *filename, int fd, off_t startsize, off_t totalsize) { - int sock, flags; + int flags; g_return_val_if_fail (request != NULL, -2); g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2); g_return_val_if_fail (filename != NULL, -2); - if (fd == NULL) + if (fd > 0) { flags = O_WRONLY | O_CREAT; if (startsize > 0) @@ -195,43 +173,32 @@ flags |= O_LARGEFILE; #endif - if ((sock = open (filename, flags, S_IRUSR | S_IWUSR)) < 0) + if ((request->datafd = open (filename, flags, S_IRUSR | S_IWUSR)) < 0) { request->logging_function (gftp_logging_error, request->user_data, _("Error: Cannot open local file %s: %s\n"), filename, g_strerror (errno)); return (-2); } - - if ((request->datafd = fdopen (sock, "ab")) == NULL) - { - request->logging_function (gftp_logging_error, request->user_data, - _("Cannot fdopen() socket for %s: %s\n"), - filename, g_strerror (errno)); - close (sock); - return (-2); - } } else request->datafd = fd; - if (ftruncate (fileno (request->datafd), startsize) == -1) + if (ftruncate (request->datafd, startsize) == -1) { request->logging_function (gftp_logging_error, request->user_data, _("Error: Cannot truncate local file %s: %s\n"), filename, g_strerror (errno)); - fclose (request->datafd); - request->datafd = NULL; - return (-2); + gftp_disconnect (request); + return (-1); } - if (fseek (request->datafd, startsize, SEEK_SET) == -1) + if (lseek (request->datafd, startsize, SEEK_SET) == -1) { request->logging_function (gftp_logging_error, request->user_data, _("Error: Cannot seek on file %s: %s\n"), filename, g_strerror (errno)); - fclose (request->datafd); - request->datafd = NULL; + gftp_disconnect (request); return (-2); } return (0); @@ -250,14 +217,14 @@ lpd->dir = NULL; } - if (request->datafd != NULL) + if (request->datafd > 0) { - if (fclose (request->datafd) < 0) + if (close (request->datafd) < 0) request->logging_function (gftp_logging_error, request->user_data, _("Error closing file descriptor: %s\n"), g_strerror (errno)); - request->datafd = NULL; + request->datafd = -1; } return (0); @@ -351,7 +318,7 @@ static int -local_get_next_file (gftp_request * request, gftp_file * fle, FILE * fd) +local_get_next_file (gftp_request * request, gftp_file * fle, int fd) { local_protocol_data * lpd; struct dirent *dirp; @@ -503,7 +470,7 @@ if (chdir (directory) == 0) { - request->logging_function (gftp_logging_error, request->user_data, + request->logging_function (gftp_logging_misc, request->user_data, _("Successfully changed local directory to %s\n"), directory); if (request->directory != directory) @@ -538,7 +505,7 @@ if (rmdir (directory) == 0) { - request->logging_function (gftp_logging_error, request->user_data, + request->logging_function (gftp_logging_misc, request->user_data, _("Successfully removed %s\n"), directory); return (0); } @@ -561,7 +528,7 @@ if (unlink (file) == 0) { - request->logging_function (gftp_logging_error, request->user_data, + request->logging_function (gftp_logging_misc, request->user_data, _("Successfully removed %s\n"), file); return (0); } @@ -584,7 +551,7 @@ if (mkdir (directory, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0) { - request->logging_function (gftp_logging_error, request->user_data, + request->logging_function (gftp_logging_misc, request->user_data, _("Successfully made directory %s\n"), directory); return (0); @@ -610,7 +577,7 @@ if (rename (oldname, newname) == 0) { - request->logging_function (gftp_logging_error, request->user_data, + request->logging_function (gftp_logging_misc, request->user_data, _("Successfully renamed %s to %s\n"), oldname, newname); return (0); @@ -640,7 +607,7 @@ if (chmod (file, newmode) == 0) { - request->logging_function (gftp_logging_error, request->user_data, + request->logging_function (gftp_logging_misc, request->user_data, _("Successfully changed mode of %s to %d\n"), file, mode); return (0); @@ -716,6 +683,7 @@ request->set_file_time = local_set_file_time; request->site = NULL; request->parse_url = NULL; + request->set_config_options = NULL; request->url_prefix = "file"; request->protocol_name = "Local"; request->need_hostport = 0;