📄 download.c
字号:
int server_pos, cur_path_pos; server_pos = ftpsearch_get_server_position(download->ftps_info, download->pconnections[i]->u. host); cur_path_pos = ftpsearch_get_path_position(download->ftps_info, download->pconnections[i]->u.host, download->pconnections[i]->u.dir); assert(cur_path_pos != -1); proz_debug("Server pos = %d, cur_path_pos=%d", server_pos, cur_path_pos); /*mark path as not valid */ download->ftps_info->mirrors[server_pos].paths[cur_path_pos]. valid = FALSE; /*See if more paths are avail */ ; if (cur_path_pos < (download->ftps_info->mirrors[server_pos].num_paths - 1)) { char *url_buf; /* Make sure this thread has terminated */ pthread_join(download->threads[i], NULL); /*additional paths avail to try */ download_show_message(download, _ ("Trying additional paths available on this server")); proz_debug("Trying path %s", download->ftps_info->mirrors[server_pos]. paths[cur_path_pos + 1]); url_buf = malloc(strlen (download->ftps_info->mirrors[server_pos]. server_name) + strlen(download->ftps_info->mirrors[server_pos]. paths[cur_path_pos + 1].path) + strlen(download->pconnections[i]->u.file) + 11 + 1); sprintf(url_buf, "ftp://%s/%s/%s", download->ftps_info->mirrors[server_pos].server_name, download->ftps_info->mirrors[server_pos]. paths[cur_path_pos + 1].path, download->pconnections[i]->u.file); proz_debug("Target url for relaunching is %s", url_buf); /*FIXME */ proz_parse_url(url_buf, &download->pconnections[i]->u, 0); free(url_buf); /*Relaunch thread */ if (pthread_create (&download->threads[i], NULL, (void *) &ftp_loop, (void *) (download->pconnections[i])) != 0) proz_die(_("Error: Not enough system resources")); } else { int j, usable_server; /*download_show_message(download, _ ("No additional paths on this server available, so will try to switch to another server")); */ /*Find any server that is downloading or completed and use it */ usable_server = -1; pthread_mutex_lock(&download->status_change_mutex); for (j = 0; j < download->num_connections; j++) { if (download->pconnections[j]->status == DOWNLOADING || download->pconnections[j]->status == COMPLETED) { usable_server = j; } } pthread_mutex_unlock(&download->status_change_mutex); if (usable_server != -1) { /*We have a server which is DLING */ download_show_message(download, _ ("No additional paths on this server available, so will switch to another server")); /* Make sure this thread has terminated */ pthread_join(download->threads[i], NULL); /*copy url and relaunch */ proz_free_url(&download->pconnections[i]->u, 0); memcpy(&download->pconnections[i]->u, proz_copy_url(&download-> pconnections[usable_server]->u), sizeof(urlinfo)); proz_debug ("Found server %s which is downloading will relaunch based on it", download->pconnections[usable_server]->u.host); /*Relaunch thread */ if (pthread_create (&download->threads[i], NULL, (void *) &ftp_loop, (void *) (download->pconnections[i])) != 0) proz_die(_("Error: Not enough system resources")); } else { /*Shit! no servers are downloading so what shall we do? we shall do nothing and wait for one connectection at least to start downloading */ } } } } else /*Handle the file not being found on the server */ if (connection_err == FTPCWDFAIL) { if (proz_download_all_dls_ftpcwdfail(download) == TRUE) { download_show_message(download, _ ("Failed to change to the working directory on all the connections!")); /*Terminate the connections */ proz_download_stop_downloads(download); return DLREMOTEFATAL; } else { /*Now we have to be careful */ int server_pos, cur_path_pos; server_pos = ftpsearch_get_server_position(download->ftps_info, download->pconnections[i]->u. host); assert(server_pos != -1); cur_path_pos = ftpsearch_get_path_position(download->ftps_info, download->pconnections[i]->u.host, download->pconnections[i]->u.dir); assert(cur_path_pos != -1); proz_debug("Server pos = %d, cur_path_pos=%d", server_pos, cur_path_pos); /*mark path as not valid */ download->ftps_info->mirrors[server_pos].paths[cur_path_pos]. valid = FALSE; /*See if more paths are avail */ ; if (cur_path_pos < (download->ftps_info->mirrors[server_pos].num_paths - 1)) { char *url_buf; /* Make sure this thread has terminated */ pthread_join(download->threads[i], NULL); /*additional paths avail to try */ download_show_message(download, _ ("Trying additional paths available on this server")); proz_debug("Trying path %s", download->ftps_info->mirrors[server_pos]. paths[cur_path_pos + 1]); url_buf = malloc(strlen (download->ftps_info->mirrors[server_pos]. server_name) + strlen(download->ftps_info->mirrors[server_pos]. paths[cur_path_pos + 1].path) + strlen(download->pconnections[i]->u.file) + 11 + 1); sprintf(url_buf, "ftp://%s/%s/%s", download->ftps_info->mirrors[server_pos].server_name, download->ftps_info->mirrors[server_pos]. paths[cur_path_pos + 1].path, download->pconnections[i]->u.file); proz_debug("Target url for relaunching is %s", url_buf); /*FIXME */ proz_parse_url(url_buf, &download->pconnections[i]->u, 0); free(url_buf); /*Relaunch thread */ if (pthread_create (&download->threads[i], NULL, (void *) &ftp_loop, (void *) (download->pconnections[i])) != 0) proz_die(_("Error: Not enough system resources")); } else { int j, usable_server; /* download_show_message(download, _("No additional paths on this server available, so will try to switch to another server")); */ proz_debug ("No additional paths on this server available, so will try to switch to another server"); /*Find any server that is downloading or completed and use it */ usable_server = -1; pthread_mutex_lock(&download->status_change_mutex); for (j = 0; j < download->num_connections; j++) { if (download->pconnections[j]->status == DOWNLOADING || download->pconnections[j]->status == COMPLETED) { usable_server = j; } } pthread_mutex_unlock(&download->status_change_mutex); if (usable_server != -1) { /*We have a server which is DLING */ download_show_message(download, _ ("No additional paths on this server available, so will switch to another server")); /* Make sure this thread has terminated */ pthread_join(download->threads[i], NULL); /*copy url and relaunch */ proz_free_url(&download->pconnections[i]->u, 0); memcpy(&download->pconnections[i]->u, proz_copy_url(&download-> pconnections[usable_server]->u), sizeof(urlinfo)); proz_debug ("Found server %s which is downloading will relaunch based on it", download->pconnections[usable_server]->u.host); /*Relaunch thread */ if (pthread_create (&download->threads[i], NULL, (void *) &ftp_loop, (void *) (download->pconnections[i])) != 0) proz_die(_("Error: Not enough system resources")); } else { /*Shit! no servers are downloading so what shall we do? we shall do nothing and wait for one connectection at least to start downloading */ } } } } else if (connection_err == FTPRESTFAIL) { /*Handle the server not supporting REST */ if (proz_download_all_dls_err(download, FTPRESTFAIL) == TRUE) { download_show_message(download, _ ("The server(s) do not support REST on all the connections!")); /*Terminate the connections */ proz_download_stop_downloads(download); return DLREMOTEFATAL; } else { /*Now we have to be careful */ int server_pos; server_pos = ftpsearch_get_server_position(download->ftps_info, download->pconnections[i]->u. host); proz_debug("Server pos = %d", server_pos); /*mark server as not supporting resume */ download->ftps_info->mirrors[server_pos].resume_supported = FALSE; { int j, usable_server; /*Find any server that is downloading or completed and use it instead */ usable_server = -1; pthread_mutex_lock(&download->status_change_mutex); for (j = 0; j < download->num_connections; j++) { if (download->pconnections[j]->status == DOWNLOADING || download->pconnections[j]->status == COMPLETED) { usable_server = j; } } pthread_mutex_unlock(&download->status_change_mutex); if (usable_server != -1) { /*We have a server which is DLING */ download_show_message(download, _ ("This server does not support resuming downloads, so will switch to another server")); /* Make sure this thread has terminated */ pthread_join(download->threads[i], NULL); /*copy url and relaunch */ proz_free_url(&download->pconnections[i]->u, 0); memcpy(&download->pconnections[i]->u, proz_copy_url(&download-> pconnections[usable_server]->u), sizeof(urlinfo)); proz_debug ("Found server %s which is downloading will relaunch based on it", download->pconnections[usable_server]->u.host); /*Relaunch thread */ if (pthread_create (&download->threads[i], NULL, (void *) &ftp_loop, (void *) (download->pconnections[i])) != 0) proz_die(_("Error: Not enough system resources")); } else { /*Shit! no servers are downloading so what shall we do? we shall do nothing and wait for one connectection at least to start downloading */ } } } } break; case LOCALFATAL: proz_download_stop_downloads(download); download_show_message(download, _ ("Connection %d, had a local fatal error: %s .Aborting download. "), i, proz_strerror(download->pconnections[i]->err)); return DLLOCALFATAL; break; case LOGINFAIL: /* * First check if the ftp server did not allow any thread * to login at all, then retry the curent thread */ if (proz_download_all_dls_status(download, LOGINFAIL) == TRUE) { download_show_message(download, _ ("All logins rejected! Retrying connection")); /* Make sure this thread has terminated */ pthread_join(download->threads[i], NULL); if (pthread_create (&download->threads[i], NULL, (void *) &ftp_loop, (void *) (download->pconnections[i])) != 0) proz_die(_("Error: Not enough system resources")); break; } else { int j, usable_server; /*Find any server that is downloading or completed and use it instead */ usable_server = -1; pthread_mutex_lock(&download->status_change_mutex); for (j = 0; j < download->num_connections; j++) { if ((download->pconnections[j]->status == DOWNLOADING || download->pconnections[j]->status == COMPLETED) && j!=i) { usable_server = j; } } pthread_mutex_unlock(&download->status_change_mutex); if (usable_server != -1) { /*We have a server which is DLING */ download_show_message(download, _ ("This server has rejected the login attempt, so will switch to another server")); /* Make sure this thread has terminated */ pthread_join(download->threads[i], NULL); /*copy url and relaunch */ proz_free_url(&download->pconnections[i]->u, 0); memcpy(&download->pconnections[i]->u, proz_copy_url(&download-> pconnections[usable_server]->u), sizeof(urlinfo)); proz_debug ("Found server %s which is downloading will relaunch based on it", download->pconnections[usable_server]->u.host); /*Relaunch thread */ if (pthread_create (&download->threads[i], NULL, (void *) &ftp_loop, (void *) (download->pconnections[i])) != 0) proz_die(_("Error: Not enough system resources")); } else { /* * Ok so at least there is one download whos login has not been rejected, * so lets see if it has completed, if so we can relaunch this connection, * as the commonest reason for a ftp login being rejected is because, the * ftp server has a limit on the number of logins permitted from the same * IP address. */ /* * Query the number of threads that are downloading * if it is zero then relaunch this connection */ int server_pos; int dling_conns_count = download_query_conns_status_count(download, DOWNLOADING, download-> pconnections[i]->u.host); server_pos = ftpsearch_get_server_position(download->ftps_info, download->pconnections[i]->u.host); if (dling_conns_count > download->ftps_info->mirrors[server_pos].max_simul_connections) { download->ftps_info->mirrors[server_pos].max_simul_connections = dling_conns_count; break; } if (dling_conns_count == 0 && (download_query_conns_status_count (download, CONNECTING, download->pconnections[i]->u.host) == 0) && (download_query_conns_status_count (download, LOGGININ, download->pconnections[i]->u.host) == 0)) { /* Make sure this thread has terminated */ pthread_join(download->threads[i], NULL); pthread_mutex_lock(&download->status_change_mutex);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -