⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 linux下的网络下载工具prozilla的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
		       "Please type proz --help for help\n");		exit(EXIT_FAILURE);	    }	    if (rt.max_ping_wait == 0)	    {		printf		    ("Hey! Does waiting for a server response for Zero(0)"		     " seconds make and sense to you!?\n"		     "Please type proz --help for help\n");		exit(EXIT_FAILURE);	    }	    break;	case 137:	    /* --pao option */	    if (setargval(optarg, &rt.max_simul_pings) != 1)	    {		/*		 * The call failed  due to a invalid arg		 */		printf("Error: Invalid arguments for the --pao option\n"		       "Please type proz --help for help\n");		exit(EXIT_FAILURE);	    }	    if (rt.max_simul_pings == 0)	    {		printf("Hey you! Will pinging Zero(0) servers at once"		       " achive anything for me!?\n"		       "Please type proz --help for help\n");		exit(EXIT_FAILURE);	    }	    break;	case 138:	    /* --max-ftp-servers option */	    if (setargval(optarg, &rt.ftps_mirror_req_n) != 1)	    {		/*		 * The call failed  due to a invalid arg		 */		printf("Error: Invalid arguments for the --pao option\n"		       "Please type proz --help for help\n");		exit(EXIT_FAILURE);	    }	    if (rt.ftps_mirror_req_n == 0)	    {		printf("Hey! Will requesting Zero(0) servers at once"		       "from ftpsearch.lycos.com achive anything!?\n"		       "Please type proz --help for help\n");		exit(EXIT_FAILURE);	    }	    break;	case 139:	    /* --max-bps */	    if (setargval(optarg, &rt.max_bps) != 1)	    {		/*		 * The call failed  due to a invalid arg		 */		printf		    ("Error: Invalid arguments for the --max-bps option\n"		     "Please type proz --help for help\n");		exit(EXIT_FAILURE);	    }	    break;	default:	    printf("Error: Invalid option\n");	    exit(EXIT_FAILURE);	}    }    if (optind == argc)    {	printf("Error: You haven't specified a URL\n"	       "Please type proz --help for help\n");	exit(EXIT_FAILURE);    }    /*     * Parse the netrc file if needed      */    if (rt.use_netrc == TRUE)    {	char *home = home_dir();	const char netrc[] = ".netrc";	if (home != NULL)	{	    char *netrc_file = malloc(strlen(home) + strlen(netrc) + 2);	    sprintf(netrc_file, "%s/%s", home, netrc);	    rt.netrc_list = parse_netrc(netrc_file);	    kfree(home);	}    }    /*     * Ok.. so we have a URL      * Setup curses      */    initscr();    keypad(stdscr, TRUE);    start_color();    noecho();    nodelay(stdscr, TRUE);    init_pair(HIGHLIGHT_PAIR, COLOR_GREEN, COLOR_BLACK);    init_pair(MSG_PAIR, COLOR_YELLOW, COLOR_BLUE);    init_pair(WARN_PAIR, COLOR_RED, COLOR_BLACK);    init_pair(PROMPT_PAIR, COLOR_RED, COLOR_BLACK);    init_pair(SELECTED_PAIR, COLOR_WHITE, COLOR_BLUE);    memset(&url_data, 0, sizeof(url_data));    err = parseurl(argv[optind], &url_data, 0);    if (err != URLOK)    {	die("The URL is syntactically wrong!\n");    }    if (!*url_data.file)    {	die("Error: You haven't specified a file name.");    }    if (url_data.proto == URLHTTP)    {	err = get_http_info(&url_data, &hs);	if (err == NEWLOCATION)	{	  char * referer = 0;	    /*	     * loop for max_redirections searching for a valid file 	     */	    for (i = 0; i < rt.max_redirections; ++i)	    {	          char *constructed_newloc;		/*DONE : handle relative urls too */		  constructed_newloc =		    uri_merge(url_data.url, hs.newloc);		  debug_prz("Redirected to %s, merged URL = %s",			  hs.newloc, constructed_newloc);		  err =		    parseurl(constructed_newloc, &url_data, 0);		  if (err != URLOK)		    {		      die("The server returned location is syntatically wrong: %s!", constructed_newloc);		    }		  referer= url_data.host;		url_data.referer=strdup(referer);		/*If we have been directed to a FTP site lets continue 		   from the FTP routine 		 */		if (url_data.proto != URLHTTP)		    break;		err = get_http_info(&url_data, &hs);		if (err == HOK)		{		    break;		} else if (err == NEWLOCATION)		{		    if (i == rt.max_redirections)		    {			/*			 * redirected too many times 			 */			die("Error: Too many redirections:%d\n",			    rt.max_redirections);		    }		} else		{		    switch (err)		    {		    case HOSTERR:			die("Unable to resolve %s", url_data.host);			break;		    case CONREFUSED:			die("%s rejected the connection attempt",			    url_data.host);			break;		    case CONERROR:			if (errno == ETIMEDOUT)			{			    die("The connection attempt to %s timed out",				url_data.host);			} else			    die("Error while attempting to connect to %s",				url_data.host);			break;		    case HAUTHREQ:			die("%s needs authentication to access that resource: privileged resource!", url_data.host);			break;		    case HAUTHFAIL:			die("Authentication with %s failed!",			    url_data.host);			break;		    default:			die("An error occured while trying to get info from the server\n");			break;		    }		}	    }	} else if (err != HOK)	{	    if (hs.statcode == HTTP_NOT_FOUND)	    {		die("Error: The file was not found on the server!\n");	    } else	    {		switch (err)		{		case HOSTERR:		    die("Unable to resolve %s", url_data.host);		    break;		case CONREFUSED:		    die("%s rejected the connection attempt",			url_data.host);		    break;		case CONERROR:		    if (errno == ETIMEDOUT)		    {			die("The connection attempt to %s timed out",			    url_data.host);		    } else			die("Error while attempting to connect to %s",			    url_data.host);		    break;		case HAUTHREQ:		    die("%s needs authentication to access that resource: privileged resource!", url_data.host);		    break;		case HAUTHFAIL:		    die("Authentication with %s failed!", url_data.host);		    break;		default:		    die("An error occured while trying to get info from the server\n");		    break;		}	    }	}    }    if (url_data.proto == URLFTP)    {	err = ftp_get_info(&url_data, &fs);	if (err == FTPOK)	{	    if (fs.fp.flagtryretr == 0 && fs.fp.flagtrycwd == 1)		die("Error:  %s is a directory, not a file",		    url_data.file);	} else	{	    switch (err)	    {	    case HOSTERR:		die("Unable to resolve %s", url_data.host);		break;	    case CONREFUSED:		die("%s rejected the connection attempt", url_data.host);		break;	    case CONERROR:		if (errno == ETIMEDOUT)		{		    die("The connection attempt to %s timed out",			url_data.host);		} else		    die("Error while attempting to connect to %s",			url_data.host);		break;	    case FTPCONREFUSED:		die("%s rejected the connection attempt", url_data.host);		break;	    case FTPLOGREFUSED:		die("The FTP server has rejected the login attempt.");		break;	    case FTPNSFOD:		die("Error: A file called %s was not found on the server",		    url_data.file);		break;	    default:		die("An error occured while trying to get info from the server\n");		break;	    }	}    }    if ((url_data.proto != URLHTTP) && (url_data.proto != URLFTP))    {	die("Error: Unsupported Protocol was specified\n");    }    /* now we got the info lets do our ftpsearch here... */    message("File size=%Ld", (long long) url_data.file_size);    if (url_data.file_size == -1)    {	message	    ("Unable to get file size; will download from original server\n");	rt.ftp_search = FALSE;    }    if (rt.ftp_search == TRUE)    {	err =	    get_complete_mirror_list(&url_data, &ftp_mirrors,				     &num_servers);	if (err != MIRINFOK)	{	    message		("Unable to get mirror info; will download from original server\n");	    same_url = TRUE;	    delay_ms(2000);	} else	{	    if (num_servers == 0)	    {		message		    ("No mirrors were found; will download from original server\n");		same_url = TRUE;		delay_ms(2000);	    } else	    {		int user_sel_server;		interface_ret i_ret;		/*Ok we got the mirrors..lets ping them */		/*Clear any other keys in the key buffer */		flushinp();		i_ret =		    curses_ftpsearch_interface(ftp_mirrors, num_servers,					       &user_sel_server);		/*Clear any other keys in the key buffer */		flushinp();		/* ok we exited */		/* We got some mirrors, now lets select the fastest one */		use_server = -1;		if (i_ret == AUTO || i_ret == USER_ABORTED)		{		    qsort(ftp_mirrors, num_servers,			  sizeof(struct ftp_mirror), compare_two_servers);		    use_server = 0;		    debug_prz("dumping sorted list\n");		    for (i = 0; i < num_servers; i++)		    {			debug_prz("%s\n", ftp_mirrors[i].server_name);		    }		    /* is the "fastest" server one which has not been tested? 		       If so download from the original server instead 		     */		    if (ftp_mirrors[use_server].status != RESPONSEOK)		    {			message			    ("None of the servers appear to be fast enough, therefore will use original server \n");			same_url = TRUE;			/*fixme */			use_server = -1;			delay_ms(2000);		    }		} else if (i_ret == USER_SELECTED)		{		  /*get the name */		    char *sel_loc= ftp_mirrors[user_sel_server].full_name;		    debug_prz("selloc %s", sel_loc);		    /*now sort the list according to  speed */		    qsort(ftp_mirrors, num_servers,			  sizeof(struct ftp_mirror), compare_two_servers);		    /* now get the new localtion of the user selected server */		    use_server =			get_mirror_list_pos(sel_loc, ftp_mirrors,					    num_servers);		}		if (use_server != -1)		{		    message("Will get from %s\n",			    ftp_mirrors[use_server].server_name);		    delay_ms(1000);		    message("Location is %s\n",			    ftp_mirrors[use_server].full_name);		    delay_ms(2000);		    debug_prz("getting from %s\n",			      ftp_mirrors[use_server].server_name);		    debug_prz("gettinglocation is %s\n",			      ftp_mirrors[use_server].full_name);		    /*now copy that servers pathname  to url_data */		    memset(&ftps_url_data, 0, sizeof(ftps_url_data));		    debug_prz("mem setted");		    err =			parseurl(ftp_mirrors[use_server].full_name,				 &ftps_url_data, 0);		    debug_prz("ftpsearch returned URL parsed");		    if (err != URLOK)		    {			die("The ftp search returned URL is syntatically wrong!\n");		    }		}	    }	}    }    /* Did the ftpsearch return the same location as the original url as the fastest server? */    if (rt.ftp_search == TRUE && same_url == FALSE)    {	if (strcmp(ftps_url_data.path, url_data.path) == 0)	{	    same_url = TRUE;	    freeurl(&ftps_url_data, 0);	} else	{	    freeurl(&url_data, 0);	    memcpy(&url_data, &ftps_url_data, sizeof(urlinfo));	    same_url = FALSE;	}    } else	same_url = TRUE;    /* Now lets switch based on the protocol */    switch (url_data.proto)    {    case URLHTTP:	fetch_http_portions(&url_data, &hs, same_url, ftp_mirrors,			    num_servers);	break;    case URLFTP:	fetch_ftp_portions(&url_data, &fs, same_url, ftp_mirrors,			   num_servers);	break;    default:	die("Error: Unsupported Protocol was specified\n");    }    message("File Successfully Retreived, Now joining the sections");    join_downloads(url_data.file, connections, rt.num_connections);    message("Deleting the unwanted files");    if (delete_downloads(connections, rt.num_connections) != 1)	die("Unable to cleanup the downloaded file parts");    if (log_delete_logfile(&url_data) != 0)    {	die("Error while deleting the log file: %s", strerror(errno));	ok = 0;    }    if (ok)      quit("All Done: Download Successful!");    /*     *  just to keep gcc quiet      */    return ok ? EXIT_SUCCESS : EXIT_FAILURE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -