Mercurial > gftp.yaz
changeset 125:b875de05c22d
2003-4-8 Brian Masney <masneyb@gftp.org>
* src/text/gftp-text.c lib/misc.c - moved r_gethostbyname() and
r_getservbyname() to lib/misc.c. Now uses GMutex functions
* lib/config_file.c lib/gftp.h lib/options.h - added config
variable type textcombo. default_protocol uses this
* lib/config_file.c (gftp_read_config_file) - when reading in the
list of supported protocols, add the protocol names to the list
associated with default_protocol. Also, don't try to have
default_protocol fall back to FTP. The code that uses this will fall
back properly
* lib/gftp.h (struct gftp_transfer) - renamed node to user_data
* lib/misc.c lib/gftp.h - moved parse_attribs() from
src/gtk/transfer.c to misc.c. Renamed to gftp_parse_attribs()
* lib/protocols.c lib/gftp.h - moved get_status() from
src/gtk/transfer.c to protocols.c. Renamed to
gftp_get_transfer_status(). Uses GMutex functions
author | masneyb |
---|---|
date | Tue, 08 Apr 2003 22:28:17 +0000 |
parents | 65048c959029 |
children | 1e65871fdfa1 |
files | ChangeLog lib/config_file.c lib/gftp.h lib/misc.c lib/options.h lib/protocols.c src/text/gftp-text.c |
diffstat | 7 files changed, 315 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Apr 08 01:43:33 2003 +0000 +++ b/ChangeLog Tue Apr 08 22:28:17 2003 +0000 @@ -1,3 +1,46 @@ +2003-4-8 Brian Masney <masneyb@gftp.org> + * src/text/gftp-text.c lib/misc.c - moved r_gethostbyname() and + r_getservbyname() to lib/misc.c. Now uses GMutex functions + + * lib/config_file.c lib/gftp.h lib/options.h - added config + variable type textcombo. default_protocol uses this + + * lib/config_file.c (gftp_read_config_file) - when reading in the + list of supported protocols, add the protocol names to the list + associated with default_protocol. Also, don't try to have + default_protocol fall back to FTP. The code that uses this will fall + back properly + + * lib/gftp.h (struct gftp_transfer) - renamed node to user_data + + * lib/misc.c lib/gftp.h - moved parse_attribs() from + src/gtk/transfer.c to misc.c. Renamed to gftp_parse_attribs() + + * lib/protocols.c lib/gftp.h - moved get_status() from + src/gtk/transfer.c to protocols.c. Renamed to + gftp_get_transfer_status(). Uses GMutex functions + + +2003-4-7 Brian Masney <masneyb@gftp.org> + * src/gtk/bookmarks.c - renamed struct gftp_bookmarks to + gftp_bookmarks_var. In run_bookmark(), use gftp_parse_bookmark() + + * src/gtk/bookmarks.c src/gtk/dnd.c src/gtk/menu-items.c + src/gtk/transfer.c - use g_strdup() instead of g_malloc()/strcpy() + + * src/gtk/dnd.c src/gtk/menu-items.c - don't use depreciated macros + to access the request structure + + * src/gtk/*.c - use new gftp_lookup_global_option() and + gftp_lookup_request_option() functions + + * src/gtk/gftp-gtk.h src/gtk/gftp-gtk.c - moved viewedit_processes and + viewedit_process_done variables from lib/gftp.h and lib/options.h + + * src/gtk/transfer.c - removed gftp_gtk_calc_kbs(). This is now in + lib/protocols.c. Removed Binary/Ascii conversion. This is all done in + lib/rfc959.c + 2003-4-6 Brian Masney <masneyb@gftp.org> * lib/config_file.c src/text/gftp-text.c - changed arguments of gftp_read_config_file() and gftp_read_bookmarks() to take an argument @@ -597,7 +640,7 @@ * cvsclean - added this script - * *.[ch] - added $Id: ChangeLog,v 1.66 2003/04/08 01:43:31 masneyb Exp $ tags + * *.[ch] - added $Id: ChangeLog,v 1.67 2003/04/08 22:28:16 masneyb Exp $ tags * debian/* - updated files from Debian maintainer
--- a/lib/config_file.c Tue Apr 08 01:43:33 2003 +0000 +++ b/lib/config_file.c Tue Apr 08 22:28:17 2003 +0000 @@ -452,6 +452,7 @@ char *tempstr, *temp1str, *curpos, buf[255]; gftp_config_list_vars * tmplistvar; gftp_config_vars * tmpconfigvar; + char **protocol_list; FILE *conffile; int line, i; size_t len; @@ -461,12 +462,24 @@ gftp_register_config_vars (gftp_global_config_vars); + protocol_list = NULL; for (i=0; gftp_protocols[i].register_options != NULL; i++) { + if (gftp_protocols[i].shown) + { + protocol_list = g_realloc (protocol_list, sizeof (char *) * (i + 2)); + protocol_list[i] = gftp_protocols[i].name; + protocol_list[i + 1] = NULL; + } + if (gftp_protocols[i].register_options != NULL) gftp_protocols[i].register_options (); } + if ((tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable, + "default_protocol")) != NULL) + tmpconfigvar->listdata = protocol_list; + gftp_config_list_htable = g_hash_table_new (string_hash_function, string_hash_compare); @@ -560,26 +573,6 @@ } } -/* FIXME - gftp_lookup_global_option ("default_protocol", &tempstr); - if (tempstr == NULL || *tempstr == '\0') - { - tempstr = "FTP"; - gftp_set_global_option ("default_protocol", tempstr); - } - - for (i = 0; gftp_protocols[i].name; i++) - { - if (strcmp (gftp_protocols[i].name, tempstr) == 0) - break; - } - - if (gftp_protocols[i].name == NULL) - { - printf (_("gFTP Error: Default protocol %s is not a valid protocol\n"), tempstr); - exit (1); - } -*/ if ((tempstr = expand_path (LOG_FILE)) == NULL) { printf (_("gFTP Error: Bad log file name %s\n"), LOG_FILE); @@ -962,7 +955,7 @@ clist = cv->listdata; for (i=0; clist[i] != NULL; i++) { - if (strcasecmp (_(clist[i]), str) == 0) + if (strcasecmp (clist[i], str) == 0) { cv->value = GINT_TO_POINTER(i); break; @@ -981,7 +974,7 @@ clist = cv->listdata; if (clist != NULL) - fprintf (fd, "%s", _(clist[GPOINTER_TO_INT(cv->value)])); + fprintf (fd, "%s", clist[GPOINTER_TO_INT(cv->value)]); else fprintf (fd, _("<unknown>")); @@ -989,7 +982,31 @@ } -/* *Note, the index numbers of this array must match up to the numbers in +static int +gftp_config_file_read_textcombo (char *str, gftp_config_vars * cv, int line) +{ + char **clist; + int i; + + cv->value = NULL; + if (cv->listdata != NULL) + { + clist = cv->listdata; + for (i=0; clist[i] != NULL; i++) + { + if (strcasecmp (clist[i], str) == 0) + { + cv->value = clist[i]; + break; + } + } + } + + return (0); +} + + +/* Note, the index numbers of this array must match up to the numbers in gftp_option_type_enum in gftp.h */ gftp_option_type_var gftp_option_types[] = { {gftp_config_file_read_text, gftp_config_file_write_text, NULL, NULL}, @@ -1004,7 +1021,7 @@ {gftp_config_file_read_text, gftp_config_file_write_text, NULL, NULL}, {NULL, NULL, NULL, NULL}, {gftp_config_file_read_intcombo, gftp_config_file_write_intcombo, NULL, NULL}, - {NULL, NULL, NULL, NULL}, + {gftp_config_file_read_textcombo, gftp_config_file_write_text, NULL, NULL}, {NULL, NULL, NULL, NULL} };
--- a/lib/gftp.h Tue Apr 08 01:43:33 2003 +0000 +++ b/lib/gftp.h Tue Apr 08 22:28:17 2003 +0000 @@ -352,7 +352,7 @@ GStaticMutex statmutex, structmutex; - void *node; + void *user_data; void *clist; }; @@ -437,7 +437,7 @@ gftp_option_type_textbox = 9, gftp_option_type_subtree = 10, gftp_option_type_intcombo = 11, - gftp_option_type_charcombo = 12, + gftp_option_type_textcombo = 12, gftp_option_type_table = 13 } gftp_option_type_enum; @@ -616,6 +616,8 @@ int column, int asds ); +mode_t gftp_parse_attribs ( char *attribs ); + /* protocols.c */ #define GFTP_FTP_NUM 0 #define GFTP_HTTP_NUM 1 @@ -820,5 +822,8 @@ void gftp_calc_kbs ( gftp_transfer * tdata, ssize_t num_read ); +int gftp_get_transfer_status ( gftp_transfer * tdata, + ssize_t num_read ); + #endif
--- a/lib/misc.c Tue Apr 08 01:43:33 2003 +0000 +++ b/lib/misc.c Tue Apr 08 22:28:17 2003 +0000 @@ -933,3 +933,100 @@ return (filelist); } + +mode_t +gftp_parse_attribs (char *attribs) +{ + mode_t mode; + int cur; + + cur = 0; + if (attribs[1] == 'r') + cur += 4; + if (attribs[2] == 'w') + cur += 2; + if (attribs[3] == 'x' || + attribs[3] == 's') + cur += 1; + mode = cur; + + cur = 0; + if (attribs[4] == 'r') + cur += 4; + if (attribs[5] == 'w') + cur += 2; + if (attribs[6] == 'x' || + attribs[6] == 's') + cur += 1; + mode = (mode * 10) + cur; + + cur = 0; + if (attribs[7] == 'r') + cur += 4; + if (attribs[8] == 'w') + cur += 2; + if (attribs[9] == 'x' || + attribs[9] == 's') + cur += 1; + mode = (mode * 10) + cur; + + return (mode); +} + + +#if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR) + +struct hostent * +r_gethostbyname (const char *name, struct hostent *result_buf, int *h_errnop) +{ + static GStaticMutex hostfunclock = G_STATIC_MUTEX_INIT; + struct hostent *hent; + + if (g_thread_supported ()) + g_static_mutex_lock (&hostfunclock); + + if ((hent = gethostbyname (name)) == NULL) + { + if (h_errnop) + *h_errnop = h_errno; + } + else + { + *result_buf = *hent; + hent = result_buf; + } + + if (g_thread_supported ()) + g_static_mutex_unlock (&hostfunclock); + + return (hent); +} + +#endif /* !HAVE_GETADDRINFO */ + +struct servent * +r_getservbyname (const char *name, const char *proto, + struct servent *result_buf, int *h_errnop) +{ + static GStaticMutex servfunclock = G_STATIC_MUTEX_INIT; + struct servent *sent; + + if (g_thread_supported ()) + g_static_mutex_lock (&servfunclock); + + if ((sent = getservbyname (name, proto)) == NULL) + { + if (h_errnop) + *h_errnop = h_errno; + } + else + { + *result_buf = *sent; + sent = result_buf; + } + + if (g_thread_supported ()) + g_static_mutex_unlock (&servfunclock); + return (sent); +} +
--- a/lib/options.h Tue Apr 08 01:43:33 2003 +0000 +++ b/lib/options.h Tue Apr 08 22:28:17 2003 +0000 @@ -98,12 +98,11 @@ gftp_option_type_float, &gftp_maxkbs, NULL, 0, N_("The maximum KB/s a file transfer can get. (Set to 0 to disable)"), GFTP_PORT_ALL, NULL}, -/* FIXME - {"", N_("Default Protocol"), (void *) 0x1, CONFIG_COMBO, "DP", NULL, GFTP_PORT_GTK}, - {"default_protocol", N_("Default Protocol"), &default_protocol, - CONFIG_CHARTEXT, N_("This specifies the default protocol to use"), NULL, 0}, -*/ + {"default_protocol", N_("Default Protocol"), + gftp_option_type_textcombo, "FTP", NULL, 0, + N_("This specifies the default protocol to use"), GFTP_PORT_ALL, NULL}, + {"list_dblclk_action", "", gftp_option_type_int, GINT_TO_POINTER(0), NULL, 0, N_("This defines what will happen when you double click a file in the file listboxes. 0=View file 1=Edit file 2=Transfer file"), 0, NULL},
--- a/lib/protocols.c Tue Apr 08 01:43:33 2003 +0000 +++ b/lib/protocols.c Tue Apr 08 22:28:17 2003 +0000 @@ -433,7 +433,7 @@ gftp_lookup_request_option (request, "default_protocol", &default_protocol); - if (*default_protocol != '\0') + if (default_protocol != NULL && *default_protocol != '\0') { for (i = 0; gftp_protocols[i].url_prefix; i++) { @@ -489,7 +489,7 @@ gftp_lookup_request_option (request, "default_protocol", &default_protocol); - if (*default_protocol != '\0') + if (default_protocol != NULL && *default_protocol != '\0') { for (i = 0; gftp_protocols[i].url_prefix; i++) { @@ -2179,3 +2179,123 @@ g_static_mutex_unlock (&tdata->statmutex); } + +int +gftp_get_transfer_status (gftp_transfer * tdata, ssize_t num_read) +{ + int ret1, ret2, retries, sleep_time; + gftp_file * tempfle; + struct timeval tv; + + ret1 = ret2 = 0; + gftp_lookup_request_option (tdata->fromreq, "retries", &retries); + gftp_lookup_request_option (tdata->fromreq, "sleep_time", &sleep_time); + + if (g_thread_supported ()) + g_static_mutex_lock (&tdata->structmutex); + + if (tdata->curfle == NULL) + { + if (g_thread_supported ()) + g_static_mutex_unlock (&tdata->structmutex); + + return (GFTP_EFATAL); + } + + tempfle = tdata->curfle->data; + + if (g_thread_supported ()) + g_static_mutex_unlock (&tdata->structmutex); + + gftp_disconnect (tdata->fromreq); + gftp_disconnect (tdata->toreq); + + if (num_read < 0 || tdata->skip_file) + { + if (num_read == GFTP_EFATAL) + return (GFTP_EFATAL); + else if (retries != 0 && + tdata->current_file_retries >= retries) + { + tdata->fromreq->logging_function (gftp_logging_error, + tdata->fromreq->user_data, + _("Error: Remote site %s disconnected. Max retries reached...giving up\n"), + tdata->fromreq->hostname != NULL ? + tdata->fromreq->hostname : tdata->toreq->hostname); + return (GFTP_EFATAL); + } + else + { + tdata->fromreq->logging_function (gftp_logging_error, + tdata->fromreq->user_data, + _("Error: Remote site %s disconnected. Will reconnect in %d seconds\n"), + tdata->fromreq->hostname != NULL ? + tdata->fromreq->hostname : tdata->toreq->hostname, + sleep_time); + } + + while (retries == 0 || + tdata->current_file_retries <= retries) + { + if (!tdata->skip_file) + { + tv.tv_sec = sleep_time; + tv.tv_usec = 0; + select (0, NULL, NULL, NULL, &tv); + } + + if ((ret1 = gftp_connect (tdata->fromreq)) == 0 && + (ret2 = gftp_connect (tdata->toreq)) == 0) + { + if (g_thread_supported ()) + g_static_mutex_lock (&tdata->structmutex); + + tdata->resumed_bytes = tdata->resumed_bytes + tdata->trans_bytes - tdata->curresumed - tdata->curtrans; + tdata->trans_bytes = 0; + if (tdata->skip_file) + { + tdata->total_bytes -= tempfle->size; + tdata->curtrans = 0; + + tdata->curfle = tdata->curfle->next; + tdata->next_file = 1; + tdata->skip_file = 0; + tdata->cancel = 0; + tdata->fromreq->cancel = 0; + tdata->toreq->cancel = 0; + } + else + { + tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; + tempfle->startsize = tdata->curtrans + tdata->curresumed; + /* We decrement this here because it will be incremented in + the loop again */ + tdata->curresumed = 0; + tdata->current_file_number--; /* Decrement this because it + will be incremented when we + continue in the loop */ + } + + gettimeofday (&tdata->starttime, NULL); + + if (g_thread_supported ()) + g_static_mutex_unlock (&tdata->structmutex); + + return (GFTP_ERETRYABLE); + } + else if (ret1 == GFTP_EFATAL || ret2 == GFTP_EFATAL) + { + gftp_disconnect (tdata->fromreq); + gftp_disconnect (tdata->toreq); + return (GFTP_EFATAL); + } + else + tdata->current_file_retries++; + } + } + else if (tdata->cancel) + return (GFTP_EFATAL); + + return (0); +} +
--- a/src/text/gftp-text.c Tue Apr 08 01:43:33 2003 +0000 +++ b/src/text/gftp-text.c Tue Apr 08 22:28:17 2003 +0000 @@ -1202,46 +1202,3 @@ return (0); } - -#if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR) - -struct hostent * -r_gethostbyname (const char *name, struct hostent *result_buf, int *h_errnop) -{ - struct hostent *hent; - - if ((hent = gethostbyname (name)) == NULL) - { - if (h_errnop) - *h_errnop = h_errno; - } - else - { - *result_buf = *hent; - hent = result_buf; - } - return (hent); -} - -#endif /* HAVE_GETADDRINFO */ - - -struct servent * -r_getservbyname (const char *name, const char *proto, - struct servent *result_buf, int *h_errnop) -{ - struct servent *sent; - - if ((sent = getservbyname (name, proto)) == NULL) - { - if (h_errnop) - *h_errnop = h_errno; - } - else - { - *result_buf = *sent; - sent = result_buf; - } - return (sent); -} -