uncrustify sources

This commit is contained in:
Mario Fetka 2010-09-01 10:52:02 +02:00
parent ef090ed65d
commit 8fe8503cbd
49 changed files with 7937 additions and 7834 deletions

View File

@ -19,7 +19,7 @@
/* Common #includes and #defines. */
/* $Id: common.h,v 1.7 2001/10/27 23:20:24 kalum Exp $ */
/* $Id$ */
#ifndef COMMON_H

View File

@ -98,7 +98,8 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
if (errno == EINPROGRESS)
errno = ETIMEDOUT;
} else if (status == 0)
}
else if (status == 0)
errno = ETIMEDOUT, status = -1;
}
@ -110,12 +111,14 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
{
freeaddrinfo(res);
return CONREFUSED;
} else
}
else
{
freeaddrinfo(res);
return CONERROR;
}
} else
}
else
{
flags = fcntl(*sock, F_GETFL, 0);
@ -209,8 +212,7 @@ int krecv(int sock, char *buffer, int size, int flags,
do
{
ret = select_fd(sock, timeout, 0);
}
while ((ret == -1) && (errno == EINTR));
} while ((ret == -1) && (errno == EINTR));
if (ret <= 0)
@ -226,8 +228,7 @@ int krecv(int sock, char *buffer, int size, int flags,
}
ret = recv(sock, buffer, size, flags);
}
while ((ret == -1) && (errno == EINTR));
} while ((ret == -1) && (errno == EINTR));
return ret;
}
@ -254,8 +255,7 @@ int ksend(int sock, char *buffer, int size, int flags,
do
{
ret = select_fd(sock, timeout, 1);
}
while ((ret == -1) && (errno == EINTR));
} while ((ret == -1) && (errno == EINTR));
if (ret <= 0)
{
@ -266,8 +266,7 @@ int ksend(int sock, char *buffer, int size, int flags,
}
}
ret = send(sock, buffer, size, flags);
}
while ((ret == -1) && (errno == EINTR));
} while ((ret == -1) && (errno == EINTR));
if (ret <= 0)
break;

View File

@ -19,7 +19,7 @@
/* Connection routines. */
/* $Id: connect.h,v 1.17 2001/05/09 22:58:00 kalum Exp $ */
/* $Id$ */
#ifndef CONNECT_H

View File

@ -19,7 +19,7 @@
/* Several connection-related routines. */
/* $Id: connection.c,v 1.48 2005/09/19 16:18:02 kalum Exp $ */
/* $Id$ */
#include "common.h"
@ -59,8 +59,7 @@ void done_with_response(connection_t * connection)
p = p1;
p1 = p->next;
kfree(p);
}
while (p1 != 0);
} while (p1 != 0);
connection->serv_ret_lines = 0;
}
@ -71,8 +70,8 @@ void done_with_response(connection_t * connection)
connection_t * proz_connection_init(urlinfo *url, pthread_mutex_t * mutex)
{
connection_t * connection = kmalloc(sizeof(connection_t));
memset(connection, 0, sizeof(connection_t));
/* memcpy(&connection->u, url, sizeof(urlinfo));*/
@ -191,8 +190,7 @@ uerr_t connection_retr_fsize_not_known(connection_t * connection,
connection_calc_ratebps(connection);
connection_throttle_bps(connection);
}
}
while (bytes_read > 0);
} while (bytes_read > 0);
if (bytes_read == -1)
{
@ -267,10 +265,8 @@ uerr_t connection_retr_fsize_known(connection_t * connection,
if (bytes_read > 0)
{
if (write_data_with_lock(connection, read_buffer, sizeof(char), bytes_read) < bytes_read)
{
proz_debug(_("write failed"));
connection_show_message(connection,
_
@ -307,9 +303,6 @@ uerr_t connection_retr_fsize_known(connection_t * connection,
int connection_load_resume_info(connection_t * connection)
{
if (connection->remote_startpos - connection->orig_remote_startpos != connection->remote_bytes_received)
{
proz_debug("connection->remote start pos before loading %ld", connection->remote_startpos);
@ -324,6 +317,7 @@ int connection_load_resume_info(connection_t * connection)
dl_status proz_connection_get_status(connection_t * connection)
{
dl_status status;
pthread_mutex_lock(connection->status_change_mutex);
status = connection->status;
pthread_mutex_unlock(connection->status_change_mutex);
@ -335,13 +329,13 @@ dl_status proz_connection_get_status(connection_t * connection)
char *proz_connection_get_status_string(connection_t * connection)
{
dl_status status;
pthread_mutex_lock(connection->status_change_mutex);
status = connection->status;
pthread_mutex_unlock(connection->status_change_mutex);
switch (connection->status)
{
case IDLE:
return(_("Idle"));
@ -354,6 +348,7 @@ char *proz_connection_get_status_string(connection_t * connection)
case DOWNLOADING:
return(_("Downloading"));
break;
case COMPLETED:
return(_("Completed"));
@ -371,6 +366,7 @@ char *proz_connection_get_status_string(connection_t * connection)
case TIMEDOUT:
return(_("Timed Out"));
case MAXTRYS:
return(_("Max attempts reached"));
@ -412,7 +408,6 @@ off_t proz_connection_get_total_bytes_got(connection_t * connection)
pthread_mutex_unlock(&connection->access_mutex);
return ret;
}
/*****************************************************************************
@ -422,6 +417,7 @@ by this connection.
off_t proz_connection_get_total_remote_bytes_got(connection_t * connection)
{
off_t ret;
pthread_mutex_lock(&connection->access_mutex);
ret = (connection->remote_bytes_received
- (connection->remote_startpos - connection->orig_remote_startpos));
@ -447,7 +443,6 @@ handling conditions like redirection from http to ftp etc
*************************************************************************/
void get_url_info_loop(connection_t * connection)
{
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
/*TODO Should we try to make it broadcast a condition to the other threads? */
@ -462,9 +457,11 @@ void get_url_info_loop(connection_t * connection)
case URLHTTP:
connection->err = http_get_url_info_loop(connection);
break;
case URLFTP:
connection->err = ftp_get_url_info_loop(connection);
break;
default:
proz_die(_("Error: unsupported protocol"));
}
@ -498,16 +495,15 @@ void get_url_info_loop(connection_t * connection)
kfree(constructed_newloc);
connection->err = HERR;
return;
} else
}
else
connection_show_message(connection, _("Redirected to => %s"),
constructed_newloc);
connection->u.referer = referer;
kfree(constructed_newloc);
connection->err = NEWLOCATION;
}
}
while (connection->err == NEWLOCATION);
} while (connection->err == NEWLOCATION);
return;
}
@ -536,11 +532,11 @@ void connection_calc_ratebps(connection_t * connection)
if (connection->time_begin.tv_sec == 0
&& connection->time_begin.tv_usec == 0)
{
connection->rate_bps = 0;
pthread_mutex_unlock(&connection->access_mutex);
return;
} else
}
else
{
gettimeofday(&tv_cur, NULL);
proz_timeval_subtract(&tv_diff, &tv_cur, &(connection->time_begin));
@ -575,7 +571,6 @@ void connection_calc_ratebps(connection_t * connection)
void connection_throttle_bps(connection_t * connection)
{
struct timeval tv_cur;
struct timeval tv_diff;
float diff_us;
@ -651,7 +646,8 @@ void connection_throttle_bps(connection_t * connection)
("Cant throttle fully : Connection would timeout if done so, please try increasing the timeout value"); */
proz_debug("delaymaxlimit %ld sec\n", tv_delay.tv_usec);
} else
}
else
{
tv_delay.tv_usec = (wtime - diff_us);
//#warning "comment out the following line before releasing the code base"
@ -665,7 +661,6 @@ void connection_throttle_bps(connection_t * connection)
{
proz_debug("Unable to throttle Bandwith\n");
}
}
}
@ -673,6 +668,7 @@ void connection_throttle_bps(connection_t * connection)
boolean proz_connection_running(connection_t * connection)
{
boolean running;
pthread_mutex_lock(&connection->access_mutex);
running = connection->running;
pthread_mutex_unlock(&connection->access_mutex);
@ -719,6 +715,7 @@ void proz_connection_free_connection(connection_t * connection,
size_t write_data_with_lock(connection_t * connection, const void *ptr, size_t size, size_t nmemb)
{
size_t ret;
flockfile(connection->fp);
/*Seek appropriately......*/

View File

@ -19,7 +19,7 @@
/* Several connection-related routines. */
/* $Id: connection.h,v 1.34 2005/01/11 01:49:11 sean Exp $ */
/* $Id$ */
#ifndef CONNECTION_H

View File

@ -19,7 +19,7 @@
/* Debugging routines. */
/* $Id: debug.c,v 1.20 2001/08/17 21:53:39 kalum Exp $ */
/* $Id$ */
#include "common.h"
@ -43,8 +43,8 @@ void debug_init()
void proz_debug_delete_log()
{
char logfile_name[PATH_MAX];
snprintf(logfile_name, PATH_MAX, "%s/debug.log", libprozrtinfo.log_dir);
@ -73,6 +73,7 @@ void proz_debug(const char *format, ...)
char message[MAX_MSG_SIZE + 1 + 1];
char logfile_name[PATH_MAX];
snprintf(logfile_name, PATH_MAX, "%s/debug.log", libprozrtinfo.log_dir);

View File

@ -19,7 +19,7 @@
/* Debugging routines. */
/* $Id: debug.h,v 1.14 2001/07/11 23:19:41 kalum Exp $ */
/* $Id$ */
#ifndef DEBUG_H

View File

@ -19,7 +19,7 @@
/* Download routines. */
/* $Id: download.c,v 1.42 2005/09/19 16:18:02 kalum Exp $ */
/* $Id$ */
#include "common.h"
@ -36,7 +36,6 @@
******************************************************************************/
download_t *proz_download_init(urlinfo * u)
{
/* pthread_mutexattr_t attr; */
download_t *download = kmalloc(sizeof(download_t));
@ -90,8 +89,8 @@ int proz_download_setup_connections_no_ftpsearch(download_t * download,
num_connections = 1;
bytes_per_connection = -1;
bytes_left = -1;
} else
}
else
{
if (connection->resume_support == FALSE)
num_connections = 1;
@ -137,7 +136,6 @@ int proz_download_setup_connections_no_ftpsearch(download_t * download,
return -1;
}
proz_debug("created file");
}
else
{
@ -161,14 +159,12 @@ int proz_download_setup_connections_no_ftpsearch(download_t * download,
out_file, strerror(errno));
return -1;
}
}
//TRY setting the offset;
if (download->main_file_size != -1)
{
if (fseeko(fp, download->main_file_size, SEEK_SET) != 0)
{
proz_debug("fseek failed");
@ -208,7 +204,8 @@ int proz_download_setup_connections_no_ftpsearch(download_t * download,
download->pconnections[i]->local_startpos = 0;
} else
}
else
{
download->pconnections[i]->main_file_size = connection->main_file_size;
download->pconnections[i]->orig_remote_startpos = download->pconnections[i]->remote_startpos = i * bytes_per_connection;
@ -248,16 +245,15 @@ int proz_download_load_resume_info(download_t * download)
int i;
int ret = 1;
logfile lf;
if (proz_log_read_logfile(&lf, download, TRUE) == 1)
proz_debug("sucessfully loaded resume info");
for (i = 0; i < download->num_connections; i++)
{
if (download->pconnections[i]->remote_endpos - download->pconnections[i]->remote_startpos == download->pconnections[i]->remote_bytes_received)
{
connection_change_status(download->pconnections[i], COMPLETED);
//This should fix the error we received when resuming when the
//average rate was too high.
@ -266,8 +262,6 @@ int proz_download_load_resume_info(download_t * download)
}
download->pconnections[i]->remote_startpos += download->pconnections[i]->remote_bytes_received;
}
download->resume_mode = TRUE;
@ -281,7 +275,6 @@ int proz_download_load_resume_info(download_t * download)
void proz_download_start_downloads(download_t * download,
boolean resume_mode)
{
int i;
if (resume_mode)
@ -320,6 +313,7 @@ else
proz_die(_("Error: Not enough system resources"));
break;
case URLFTP:
/* ftp_loop(&download->connections[i]); */
@ -331,6 +325,7 @@ else
proz_die(_("Error: Not enough system resources"));
break;
default:
proz_die(_("Error: Unsupported Protocol was specified"));
}
@ -342,6 +337,7 @@ else
void proz_download_stop_downloads(download_t * download)
{
int i;
/*Stop the threads */
for (i = 0; i < download->num_connections; i++)
@ -354,8 +350,6 @@ void proz_download_stop_downloads(download_t * download)
/* returns one of DLINPROGRESS, DLERR, DLDONE, DLREMOTEFATAL, DLLOCALFATAL*/
uerr_t proz_download_handle_threads(download_t * download)
{
//Create logfile everytime this is callaed
log_create_logfile(download->num_connections, download->main_file_size, download->u.url, download);
@ -449,7 +443,8 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
proz_download_stop_downloads(download);
/*FIXME Do we delete any downloaded portions here ? */
return CANTRESUME;
} else /*Handle the file not being found on the server */
}
else /*Handle the file not being found on the server */
if (connection_err == FTPNSFOD || connection_err == HTTPNSFOD)
{
if (proz_download_all_dls_filensfod(download) == TRUE)
@ -460,7 +455,8 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
/*Terminate the connections */
proz_download_stop_downloads(download);
return DLREMOTEFATAL;
} else
}
else
{
download_show_message(download, _("Relaunching download"));
/* Make sure this thread has terminated */
@ -475,7 +471,8 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
}
} else /*Handle the file not being found on the server */
}
else /*Handle the file not being found on the server */
if (connection_err == FTPCWDFAIL)
{
if (proz_download_all_dls_ftpcwdfail(download) == TRUE)
@ -486,7 +483,8 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
/*Terminate the connections */
proz_download_stop_downloads(download);
return DLREMOTEFATAL;
} else
}
else
{
download_show_message(download, _("Relaunching download"));
/* Make sure this thread has terminated */
@ -536,9 +534,9 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
break;
} else
}
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,
@ -568,28 +566,6 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
&& (download_query_conns_status_count(download, LOGGININ, NULL)
== 0))
{
/* Make sure this thread has terminated */
pthread_join(download->threads[i], NULL);
pthread_mutex_lock(&download->status_change_mutex);
download_show_message(download, _("Relaunching download"));
if (pthread_create(&download->threads[i], NULL,
(void *) &ftp_loop,
(void *) (download->pconnections[i])) != 0)
proz_die(_("Error: Not enough system resources"));
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
} else
if (dling_conns_count < download->max_simul_connections
&&
(download_query_conns_status_count
(download, CONNECTING, NULL) == 0)
&&
(download_query_conns_status_count
(download, LOGGININ, NULL) == 0))
{
/* Make sure this thread has terminated */
pthread_join(download->threads[i], NULL);
pthread_mutex_lock(&download->status_change_mutex);
@ -602,7 +578,27 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
}
else
if (dling_conns_count < download->max_simul_connections
&&
(download_query_conns_status_count
(download, CONNECTING, NULL) == 0)
&&
(download_query_conns_status_count
(download, LOGGININ, NULL) == 0))
{
/* Make sure this thread has terminated */
pthread_join(download->threads[i], NULL);
pthread_mutex_lock(&download->status_change_mutex);
download_show_message(download, _("Relaunching download"));
if (pthread_create(&download->threads[i], NULL,
(void *)&ftp_loop,
(void *)(download->pconnections[i])) != 0)
proz_die(_("Error: Not enough system resources"));
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
}
}
break;
@ -629,7 +625,8 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
break;
} else
}
else
{
/*
* Ok so at least there is one download whos connections attempt has not been rejected,
@ -660,28 +657,6 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
&& (download_query_conns_status_count(download, LOGGININ, NULL)
== 0))
{
/* Make sure this thread has terminated */
pthread_join(download->threads[i], NULL);
pthread_mutex_lock(&download->status_change_mutex);
download_show_message(download, _("Relaunching download"));
if (pthread_create(&download->threads[i], NULL,
(void *) &ftp_loop,
(void *) (download->pconnections[i])) != 0)
proz_die(_("Error: Not enough system resources"));
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
} else
if (dling_conns_count < download->max_simul_connections
&&
(download_query_conns_status_count
(download, CONNECTING, NULL) == 0)
&&
(download_query_conns_status_count
(download, LOGGININ, NULL) == 0))
{
/* Make sure this thread has terminated */
pthread_join(download->threads[i], NULL);
pthread_mutex_lock(&download->status_change_mutex);
@ -694,7 +669,27 @@ uerr_t download_handle_threads_no_ftpsearch(download_t * download)
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
}
else
if (dling_conns_count < download->max_simul_connections
&&
(download_query_conns_status_count
(download, CONNECTING, NULL) == 0)
&&
(download_query_conns_status_count
(download, LOGGININ, NULL) == 0))
{
/* Make sure this thread has terminated */
pthread_join(download->threads[i], NULL);
pthread_mutex_lock(&download->status_change_mutex);
download_show_message(download, _("Relaunching download"));
if (pthread_create(&download->threads[i], NULL,
(void *)&ftp_loop,
(void *)(download->pconnections[i])) != 0)
proz_die(_("Error: Not enough system resources"));
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
}
}
break;
@ -737,7 +732,6 @@ connection_t *proz_download_get_connection(download_t * download,
{
assert(number >= 0 && number < download->num_connections);
return(download->pconnections[number]);
}
@ -790,13 +784,14 @@ float proz_download_get_average_speed(download_t * download)
speed = (float)total_remote_bytes_got / ((float)diff_time.tv_sec +
((float)diff_time.
tv_usec / 10e5));
} else
}
else
speed = 0;
} else
}
else
speed = 0; /*The DL hasnt started yet */
return speed;
}
@ -806,6 +801,7 @@ float proz_download_get_average_speed(download_t * download)
int proz_download_delete_dl_file(download_t * download)
{
char *out_file;
out_file = kmalloc(PATH_MAX);
snprintf(out_file, PATH_MAX, "%s/%s.prozilla",
download->dl_dir, download->u.file);
@ -838,6 +834,7 @@ int proz_download_delete_dl_file(download_t * download)
void proz_download_wait_till_all_end(download_t * download)
{
int i;
/*Wait till the end of all the threads */
for (i = 0; i < download->num_connections; i++)
@ -868,7 +865,6 @@ void download_join_downloads(download_t * download)
/*This function will join the downloaded files*/
void join_downloads(download_t * download)
{
pthread_mutex_lock(&download->access_mutex);
download->building = 0;
pthread_mutex_unlock(&download->access_mutex);
@ -883,7 +879,6 @@ by the all the connections managed by this download
******************************************************************************/
off_t proz_download_get_total_remote_bytes_got(download_t * download)
{
off_t total_bytes_recv = 0;
int i;
@ -903,6 +898,7 @@ off_t proz_download_get_total_remote_bytes_got(download_t * download)
int proz_download_all_dls_status(download_t * download, dl_status status)
{
int i;
pthread_mutex_lock(&download->status_change_mutex);
for (i = 0; i < download->num_connections; i++)
{
@ -924,6 +920,7 @@ boolean proz_download_all_dls_filensfod(download_t * download)
{
int i;
uerr_t err;
/*Lock mutex */
for (i = 0; i < download->num_connections; i++)
@ -946,6 +943,7 @@ boolean proz_download_all_dls_ftpcwdfail(download_t * download)
{
int i;
uerr_t err;
/*Lock mutex */
for (i = 0; i < download->num_connections; i++)
@ -970,6 +968,7 @@ boolean proz_download_all_dls_err(download_t * download, uerr_t in_err)
{
int i;
uerr_t err;
/*Lock mutex */
for (i = 0; i < download->num_connections; i++)
@ -993,6 +992,7 @@ int download_query_conns_status_count(download_t * download,
{
int i;
int count = 0;
pthread_mutex_lock(&download->status_change_mutex);
for (i = 0; i < download->num_connections; i++)
@ -1027,7 +1027,6 @@ if it cannot be calculated say if the file size of not known, it returns -1
*/
off_t proz_download_get_est_time_left(download_t * download)
{
long secs_left;
float average_speed;
off_t total_bytes_got;
@ -1044,13 +1043,11 @@ off_t proz_download_get_est_time_left(download_t * download)
return secs_left =
(off_t)((download->main_file_size -
total_bytes_got) / average_speed);
}
void proz_download_free_download(download_t * download, boolean complete)
{
assert(download);
/*TODO free the URL */
@ -1177,7 +1174,6 @@ Returns,
int proz_download_target_exist(download_t * download)
{
char out_file_name[PATH_MAX];
struct stat st_buf;
int ret;
@ -1196,7 +1192,6 @@ int proz_download_target_exist(download_t * download)
/*File was statable so it exists */
return 1;
}
@ -1209,7 +1204,6 @@ Returns,
int proz_download_delete_target(download_t * download)
{
char out_file_name[PATH_MAX];
int ret;
@ -1227,7 +1221,6 @@ int proz_download_delete_target(download_t * download)
/*File was statable so it exists */
return 1;
}
/*Tries to switch to another server which is downloading or has completed, returns 1 on sucesss, or -1 on failure
@ -1277,13 +1270,12 @@ int download_switch_server_ftpsearch(download_t *download, int bad_connection)
pthread_cond_wait(&download->pconnections[bad_connection]->connecting_cond, &download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
return 1;
} else
}
else
{
/*Shit! no servers are downloading or completed so what shall we do? we shall do nothing and wait for one connectection at least to start downloading */
return -1;
}
}
/* returns one of DLINPROGRESS, DLERR, DLDONE, DLREMOTEFATAL, DLLOCALFATAL*/
@ -1368,7 +1360,8 @@ uerr_t download_handle_threads_ftpsearch(download_t * download)
proz_download_stop_downloads(download);
/*FIXME Do we delete any downloaded portions here ? */
return CANTRESUME;
} else /*Handle the file not being found on the server */
}
else /*Handle the file not being found on the server */
if (connection_err == FTPNSFOD || connection_err == HTTPNSFOD)
{
if (proz_download_all_dls_filensfod(download) == TRUE)
@ -1379,9 +1372,9 @@ uerr_t download_handle_threads_ftpsearch(download_t * download)
/*Terminate the connections */
proz_download_stop_downloads(download);
return DLREMOTEFATAL;
} else
}
else
{
/*Now we have to be careful */
int server_pos, cur_path_pos;
@ -1449,9 +1442,9 @@ uerr_t download_handle_threads_ftpsearch(download_t * download)
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
} else
}
else
{
/*download_show_message(download,
_
("No additional paths on this server available, so will try to switch to another server")); */
@ -1459,7 +1452,8 @@ uerr_t download_handle_threads_ftpsearch(download_t * download)
download_switch_server_ftpsearch(download, i);
}
}
} else /*Handle the file not being found on the server */
}
else /*Handle the file not being found on the server */
if (connection_err == FTPCWDFAIL)
{
if (proz_download_all_dls_ftpcwdfail(download) == TRUE)
@ -1470,9 +1464,9 @@ download_switch_server_ftpsearch(download, i);
/*Terminate the connections */
proz_download_stop_downloads(download);
return DLREMOTEFATAL;
} else
}
else
{
/*Now we have to be careful */
int server_pos, cur_path_pos;
@ -1534,9 +1528,9 @@ download_switch_server_ftpsearch(download, i);
(&download->threads[i], NULL, (void *)&ftp_loop,
(void *)(download->pconnections[i])) != 0)
proz_die(_("Error: Not enough system resources"));
} else
}
else
{
/* download_show_message(download, _("No additional paths on this server available, so will try to switch to another server")); */
@ -1546,7 +1540,8 @@ download_switch_server_ftpsearch(download, i);
download_switch_server_ftpsearch(download, i);
}
}
} else if (connection_err == FTPRESTFAIL)
}
else if (connection_err == FTPRESTFAIL)
{
/*Handle the server not supporting REST */
if (proz_download_all_dls_err(download, FTPRESTFAIL) == TRUE)
@ -1557,9 +1552,9 @@ download_switch_server_ftpsearch(download, i);
/*Terminate the connections */
proz_download_stop_downloads(download);
return DLREMOTEFATAL;
} else
}
else
{
/*Now we have to be careful */
int server_pos;
@ -1578,7 +1573,6 @@ download_switch_server_ftpsearch(download, i);
_
("This server does not support resuming downloads, so will switch to another server"));
download_switch_server_ftpsearch(download, i);
}
}
}
@ -1617,9 +1611,9 @@ download_switch_server_ftpsearch(download, i);
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
break;
} else
}
else
{
int j, usable_server;
/*Find any server that is downloading or completed and use it instead */
@ -1669,9 +1663,9 @@ download_switch_server_ftpsearch(download, i);
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
} else
}
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,
@ -1711,7 +1705,6 @@ download_switch_server_ftpsearch(download, i);
(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);
@ -1723,7 +1716,8 @@ download_switch_server_ftpsearch(download, i);
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
} else
}
else
if (dling_conns_count <
download->ftps_info->mirrors[server_pos].
max_simul_connections
@ -1736,7 +1730,6 @@ download_switch_server_ftpsearch(download, i);
(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);
@ -1775,9 +1768,9 @@ download_switch_server_ftpsearch(download, i);
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
break;
} else
}
else
{
int j, usable_server;
/*Find any server that is downloading or completed and use it instead */
@ -1825,8 +1818,8 @@ download_switch_server_ftpsearch(download, i);
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
} else
}
else
{
/*
* Ok so at least there is one download whos connections attempt has not been rejected,
@ -1867,7 +1860,6 @@ download_switch_server_ftpsearch(download, i);
(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);
@ -1879,7 +1871,8 @@ download_switch_server_ftpsearch(download, i);
pthread_cond_wait(&download->pconnections[i]->connecting_cond,
&download->status_change_mutex);
pthread_mutex_unlock(&download->status_change_mutex);
} else
}
else
if (dling_conns_count <
download->ftps_info->mirrors[server_pos].
max_simul_connections
@ -1892,7 +1885,6 @@ download_switch_server_ftpsearch(download, i);
(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);
@ -1935,6 +1927,7 @@ int proz_download_setup_connections_ftpsearch(download_t * download,
FILE *fp;
char *out_file;
struct stat stat_buf;
/*TODO Check for log file and use same number of threads */
proz_debug("proz_download_setup_connections_ftpsearch");
@ -1993,8 +1986,8 @@ int proz_download_setup_connections_ftpsearch(download_t * download,
download->pconnections[i] = proz_connection_init(url,
&download->status_change_mutex);
} else
}
else
{
int extra_mirror = 0;
/*FIXME improve allocation algorithm in this part */
@ -2051,7 +2044,6 @@ int proz_download_setup_connections_ftpsearch(download_t * download,
out_file, strerror(errno));
return -1;
}
}
else
return -1;
@ -2069,14 +2061,12 @@ int proz_download_setup_connections_ftpsearch(download_t * download,
out_file, strerror(errno));
return -1;
}
}
//TRY setting the offset;
if (download->main_file_size != -1)
{
if (fseeko(fp, download->main_file_size, SEEK_SET) != 0)
return -1;
}
@ -2109,7 +2099,8 @@ int proz_download_setup_connections_ftpsearch(download_t * download,
/* Add the remaining bytes to the last connection */
download->pconnections[--i]->remote_endpos += bytes_left;
} else
}
else
{
proz_debug("No mirrors, which were up are found");
download->using_ftpsearch = FALSE;
@ -2125,8 +2116,8 @@ int proz_download_setup_connections_ftpsearch(download_t * download,
uerr_t proz_download_get_join_status(download_t *download)
{
int building_status;
pthread_mutex_lock(&download->access_mutex);
building_status = download->building;
pthread_mutex_unlock(&download->access_mutex);
@ -2135,10 +2126,13 @@ uerr_t proz_download_get_join_status(download_t *download)
{
case 1:
return JOININPROGRESS;
case 0:
return JOINDONE;
case -1:
return JOINERR;
default:
proz_die("Bad building falg in download structure");
}
@ -2149,8 +2143,8 @@ uerr_t proz_download_get_join_status(download_t *download)
float proz_download_get_file_build_percentage(download_t *download)
{
float percent_done;
pthread_mutex_lock(&download->access_mutex);
percent_done = 100;
pthread_mutex_unlock(&download->access_mutex);

View File

@ -19,7 +19,7 @@
/* Download routines. */
/* $Id: download.h,v 1.25 2001/09/30 23:13:50 kalum Exp $ */
/* $Id$ */
#ifndef DOWNLOAD_H

View File

@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
/* $Id: ftp-retr.c,v 1.18 2005/01/11 01:49:11 sean Exp $ */
/* $Id$ */
#include "common.h"
@ -85,7 +85,8 @@ uerr_t proz_ftp_get_file(connection_t * connection)
err = ftp_connect_to_server(connection,
connection->ftp_proxy->proxy_url.host,
connection->ftp_proxy->proxy_url.port);
} else
}
else
{
err = ftp_connect_to_server(connection, connection->u.host,
connection->u.port);
@ -133,7 +134,8 @@ uerr_t proz_ftp_get_file(connection_t * connection)
if (err == FTPLOGREFUSED)
{
connection_change_status(connection, LOGINFAIL);
} else
}
else
{
connection_change_status(connection, REMOTEFATAL);
}
@ -166,12 +168,14 @@ uerr_t proz_ftp_get_file(connection_t * connection)
connection->u.dir);
close_sock(&connection->ctrl_sock);
return err;
} else
}
else
{
proz_debug(_("CWD ok."));
done_with_response(connection);
}
} else
}
else
proz_debug(_("CWD not needed."));
err = ftp_setup_data_sock_1(connection, &passive_mode);
@ -252,7 +256,6 @@ uerr_t ftp_loop(connection_t * connection)
{
if (connection->attempts > 0)
{
if (retrying_from_loop == TRUE)
{
connection_show_message(connection,
@ -270,7 +273,8 @@ uerr_t ftp_loop(connection_t * connection)
_
("Error while attemting to process download file "));
}
} else
}
else
{
/*If we cant resume then reset the connections bytesreceived to 0 */
connection->remote_bytes_received = 0;
@ -309,8 +313,7 @@ uerr_t ftp_loop(connection_t * connection)
break;
}
retrying_from_loop = TRUE;
}
while ((connection->attempts < connection->max_attempts)
} while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0);
@ -326,7 +329,6 @@ or false if it should be passed upwards so that the main download thread can
restart it when necessary after processing other threads status too */
boolean ftp_loop_handle_error(uerr_t err)
{
proz_debug("Error encountered in ftp_loop is %d", err);
if (err == FTPNSFOD || err == FTPLOGREFUSED || err == FTPCONREFUSED
|| err == FWRITEERR || err == FOPENERR || err == FTPCWDFAIL
@ -334,5 +336,4 @@ boolean ftp_loop_handle_error(uerr_t err)
return FALSE;
else
return TRUE;
}

View File

@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
/* $Id: ftp-retr.h,v 1.6 2001/06/25 12:30:55 kalum Exp $ */
/* $Id$ */
#ifndef FTP_RETR_H
#define FTP_RETR_H

View File

@ -19,7 +19,7 @@
/* FTP support. */
/* $Id: ftp.c,v 1.55 2005/09/04 00:06:50 kalum Exp $ */
/* $Id$ */
#include "common.h"
@ -44,6 +44,7 @@
static int ftp_get_return(const char *ftp_buffer)
{
char code[4];
strncpy(code, ftp_buffer, 3);
code[3] = '\0';
return atoi(code);
@ -362,7 +363,8 @@ uerr_t ftp_pasv(connection_t * connection, unsigned char *addr)
/* Parse it. */
p = (unsigned char *)connection->serv_ret_lines->line;
for (p += 4; *p && !isdigit(*p); p++);
for (p += 4; *p && !isdigit(*p); p++)
;
if (!*p)
return FTPINVPASV;
@ -469,7 +471,8 @@ uerr_t ftp_pwd(connection_t * connection, char *dir)
strcpy(dir, l);
*r = '"';
}
} else
}
else
{
if ((r = strchr(connection->serv_ret_lines->line, ' ')) != NULL)
{
@ -504,9 +507,9 @@ uerr_t ftp_size(connection_t * connection, const char *file, off_t *size)
{
sscanf(connection->serv_ret_lines->line + 3, "%lld", size);
return FTPOK;
} else if (connection->serv_ret_lines->line[0] == '5') /* An error occured. */
}
else if (connection->serv_ret_lines->line[0] == '5') /* An error occured. */
{
if (ftp_get_return(connection->serv_ret_lines->line) == 550)
{
return FTPNSFOD;
@ -624,7 +627,8 @@ uerr_t ftp_login(connection_t * connection, const char *username,
{
/* No proxy just direct connection. */
err = ftp_send_msg(connection, "USER %s\r\n", username);
} else
}
else
{
switch (connection->ftp_proxy->type)
{
@ -632,21 +636,25 @@ uerr_t ftp_login(connection_t * connection, const char *username,
err = ftp_send_msg(connection, "USER %s@%s:%d\r\n", username,
connection->u.host, connection->u.port);
break;
case USERatPROXYUSERatSITE:
err = ftp_send_msg(connection, "USER %s@%s@%s:%d\r\n", username,
connection->ftp_proxy->username,
connection->u.host, connection->u.port);
break;
case USERatSITE_PROXYUSER:
err = ftp_send_msg(connection, "USER %s:%d@%s %s\r\n", username,
connection->u.host, connection->u.port,
connection->ftp_proxy->username);
break;
case PROXYUSERatSITE:
err = ftp_send_msg(connection, "USER %s@%s:%d\r\n",
connection->ftp_proxy->username,
connection->u.host, connection->u.port);
break;
default:
/* Something else, just send PROXY USER. */
err = ftp_send_msg(connection, "USER %s\r\n",
@ -680,19 +688,23 @@ uerr_t ftp_login(connection_t * connection, const char *username,
err = ftp_send_msg(connection, "USER %s@%s:%d\r\n", username,
connection->u.host, connection->u.port);
break;
case OPENSITE:
err =
ftp_send_msg(connection, "OPEN %s:%d\r\n", connection->u.host,
connection->u.port);
break;
case SITESITE:
err =
ftp_send_msg(connection, "SITE %s:%d\r\n", connection->u.host,
connection->u.port);
break;
case PROXYUSERatSITE:
err = ftp_send_msg(connection, "USER %s\r\n", username);
break;
default:
/* TODO What is the default here? */
return FTPOK;
@ -721,24 +733,29 @@ uerr_t ftp_login(connection_t * connection, const char *username,
{
/* No proxy just direct connection. */
err = ftp_send_msg(connection, "PASS %s\r\n", passwd);
} else
}
else
{
switch (connection->ftp_proxy->type)
{
case USERatSITE:
err = ftp_send_msg(connection, "PASS %s\r\n", passwd);
break;
case USERatPROXYUSERatSITE:
err = ftp_send_msg(connection, "PASS %s@%s\r\n", passwd,
connection->ftp_proxy->passwd);
break;
case USERatSITE_PROXYUSER:
err = ftp_send_msg(connection, "PASS %s\r\n", passwd);
break;
case PROXYUSERatSITE:
err = ftp_send_msg(connection, "PASS %s\r\n",
connection->ftp_proxy->passwd);
break;
default:
/* Something else we dont know about. */
err = ftp_send_msg(connection, "PASS %s\r\n",
@ -809,6 +826,7 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
longstring buffer;
boolean size_ok;
struct ftpparse fp;
/* if we have to use a HTTP proxy call the routine which is defined in http.c
and just return.
*/
@ -842,7 +860,8 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
connection_show_message(connection, _("Connected to %s"),
connection->ftp_proxy->proxy_url.host);
} else
}
else
{
connection_show_message(connection, _("Connecting to %s"),
connection->u.host);
@ -932,11 +951,13 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
connection->u.dir);
close_sock(&connection->ctrl_sock);
return err;
} else
}
else
{
done_with_response(connection);
}
} else
}
else
connection_show_message(connection, _("CWD not needed"));
init_response(connection);
@ -946,7 +967,8 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
connection->resume_support = FALSE;
connection_show_message(connection, _("REST failed"));
/* NOTE: removed return err; */
} else
}
else
{
connection->resume_support = TRUE;
connection_show_message(connection, _("REST ok"));
@ -961,9 +983,9 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
/* So connection->u.file is a directory and not a file. */
connection->file_type = DIRECTORY;
return FTPOK;
} else
}
else
{
/* FIXME: The statement below is strictly not true, it could be a symlink
but for the moment lets leave this as it is, later we will perform a
LIST command and detect whether it is a symlink. */
@ -995,9 +1017,11 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
case FTPOK:
size_ok = TRUE;
break;
case FTPSIZEFAIL:
size_ok = FALSE;
break;
default:
size_ok = FALSE;
}
@ -1080,7 +1104,8 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
while ((tmp = strrchr(buffer, '\n')) || (tmp = strrchr(buffer, '\r')))
{
*tmp = 0;
};
}
;
close_sock(&connection->data_sock);
close_sock(&connection->ctrl_sock);
@ -1128,7 +1153,8 @@ uerr_t ftp_setup_data_sock_1(connection_t * connection,
{
proz_debug(_("Server doesn't seem to support PASV"));
*passive_mode = FALSE;
} else if (err == FTPOK) /* Server supports PASV. */
}
else if (err == FTPOK) /* Server supports PASV. */
{
char dhost[256];
unsigned short dport;
@ -1146,11 +1172,13 @@ uerr_t ftp_setup_data_sock_1(connection_t * connection,
/* Everything seems to be ok. */
*passive_mode = TRUE;
} else
}
else
return err;
done_with_response(connection);
} else
}
else
*passive_mode = FALSE; /* Ok... Since PASV is not to be used. */
if (*passive_mode == FALSE)
@ -1200,13 +1228,11 @@ uerr_t ftp_get_url_info_loop(connection_t * connection)
{
if (connection->attempts > 0 && connection->err != NEWLOCATION)
{
connection_show_message(connection,
_("Retrying attempt %d in %d seconds"),
connection->attempts,
connection->retry_delay.tv_sec);
delay_ms(connection->retry_delay.tv_sec * 1000);
}
/*Push the handler which will cleanup any sockets that are left open */
@ -1240,9 +1266,7 @@ uerr_t ftp_get_url_info_loop(connection_t * connection)
connection_show_message(connection, proz_strerror(connection->err));
break;
}
}
while ((connection->attempts < connection->max_attempts)
} while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0);

View File

@ -19,7 +19,7 @@
/* FTP support. */
/* $Id: ftp.h,v 1.35 2005/09/04 00:06:50 kalum Exp $ */
/* $Id$ */
#ifndef FTP_H

View File

@ -44,6 +44,7 @@
long getlong(char *buf, int len)
{
long u = 0;
while (len-- > 0)
u = u * 10 + (*buf++ - '0');
return u;
@ -71,37 +72,56 @@ char * get_nextfield (char ** pstr)
char * p = *pstr;
char * start = NULL;
if (!pstr || !*pstr) return NULL;
while (1) {
if (!pstr || !*pstr)
return NULL;
while (1)
{
/* Strip white space and other delimiters */
while (*p && (isspace((int) *p) || *p==',' || *p==';' || *p=='=')) p++;
if (!*p) {
while (*p && (isspace((int)*p) || *p == ',' || *p == ';' || *p == '='))
p++;
if (!*p)
{
*pstr = p;
return NULL; /* No field */
}
if (*p == '"') { /* quoted field */
if (*p == '"') /* quoted field */
{
start = ++p;
for (; *p && *p != '"'; p++)
if (*p == '\\' && *(p+1)) p++; /* Skip escaped chars */
if (*p == '\\' && *(p + 1))
p++;
/* Skip escaped chars */
break; /* kr95-10-9: needs to stop here */
} else if (*p == '<') { /* quoted field */
}
else if (*p == '<') /* quoted field */
{
start = ++p;
for (; *p && *p != '>'; p++)
if (*p == '\\' && *(p+1)) p++; /* Skip escaped chars */
break; /* kr95-10-9: needs to stop here */
} else if (*p == '(') { /* Comment */
for(;*p && *p!=')'; p++)
if (*p == '\\' && *(p+1)) p++; /* Skip escaped chars */
if (*p == '\\' && *(p + 1))
p++;
} else { /* Spool field */
/* Skip escaped chars */
break; /* kr95-10-9: needs to stop here */
}
else if (*p == '(') /* Comment */
{
for (; *p && *p != ')'; p++)
if (*p == '\\' && *(p + 1))
p++;
/* Skip escaped chars */
p++;
}
else /* Spool field */
{
start = p;
while (*p && !isspace((int)*p) && *p != ',' && *p != ';' && *p != '=')
p++;
break; /* Got it */
}
}
if (*p) *p++ = '\0';
if (*p)
*p++ = '\0';
*pstr = p;
return start;
}
@ -110,12 +130,12 @@ char * get_nextfield (char ** pstr)
uerr_t ftp_parse(ftpparse *fp, char *buf, int len)
{
char *cp;
char *token;
char *ptr;
char *date;
int i;
fp->filename = 0;
fp->namelen = 0;
// fp->flagtrycwd = 0;
@ -134,7 +154,8 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
if (len < 2) /* an empty name in EPLF, with no info, could be 2 chars */
return FTPPARSENOTEXIST;
switch(*buf) {
switch (*buf)
{
case 'b':
case 'c':
case 'd':
@ -160,9 +181,12 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
/* "drwxrwxr-x folder 2 May 10 1996 network"
*/
if (*buf == 'd') fp->filetype = DIRECTORY;
if (*buf == '-') fp->filetype = DIRECTORY;
if (*buf == 'l') fp->filetype = SYMBOLIC_LINK;
if (*buf == 'd')
fp->filetype = DIRECTORY;
if (*buf == '-')
fp->filetype = DIRECTORY;
if (*buf == 'l')
fp->filetype = SYMBOLIC_LINK;
ptr = cp = strdup(buf);
for (i = 0; i < 4; i++)
@ -176,17 +200,21 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
** This field can either be group or size. We find out by looking at the
** next field. If this is a non-digit then this field is the size.
*/
while (*cp && isspace((int) *cp)) cp++;
if (isdigit((int) *cp)) {
while (*cp && isspace((int)*cp))
cp++;
if (isdigit((int)*cp))
{
token = get_nextfield(&cp);
while (*cp && isspace((int) *cp)) cp++;
while (*cp && isspace((int)*cp))
cp++;
}
//if it is a filename
fp->filesize = strtol(token, NULL, 10);
proz_debug("FTP file size is %ld", fp->filesize);
while (*cp && isspace((int) *cp)) cp++;
while (*cp && isspace((int)*cp))
cp++;
assert(cp + 12 < ptr + len);
date = cp;
cp += 12;
@ -196,11 +224,10 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
proz_debug("LIST date is %s", fp->date_str);
return FTPPARSEOK;
default:
return FTPPARSEFAIL;
}
}
@ -208,18 +235,16 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
time_t parse_time(const char * str)
{
char * p;
struct tm tm;
time_t t;
if (!str) return 0;
if (!str)
return 0;
if ((p = strchr(str, ',')))
{
}
return 0;
}

View File

@ -19,7 +19,7 @@
/* FTP LIST command parsing code. */
/* $Id: ftpparse.h,v 1.15 2005/08/06 17:07:35 kalum Exp $ */
/* $Id$ */
#ifndef FTPPARSE_H

View File

@ -82,6 +82,7 @@ ftps_request_t * proz_ftps_request_init(
break;
case FILESEARCH_RU:
url = prepare_filesearching_url(request, ftps_loc, num_req_mirrors);
if (url == 0)
@ -90,6 +91,7 @@ ftps_request_t * proz_ftps_request_init(
/*NOTE pasing zero as the status change mutes as we dont need it here */
request->connection = proz_connection_init(url, 0);
break;
default:
proz_debug("Unsupported FTP search server type");
proz_die("Unsupported FTP search server type");
@ -181,15 +183,16 @@ urlinfo *prepare_filesearching_url(ftps_request_t * request, char *ftps_loc,
uerr_t parse_html_mirror_list(ftps_request_t * request, char *p)
{
switch (request->server_type)
{
case LYCOS:
return parse_lycos_html_mirror_list(request, p);
break;
case FILESEARCH_RU:
return parse_filesearching_html_mirror_list(request, p);
break;
default:
proz_debug("Unsupported FTP search server type");
proz_die("Unsupported FTP search server type");
@ -199,7 +202,6 @@ uerr_t parse_html_mirror_list(ftps_request_t * request, char *p)
uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
{
struct ftp_mirror **pmirrors = &request->mirrors;
int *num_servers = &request->num_mirrors;
char *p1, *p2, *i = 0, *j;
@ -226,7 +228,6 @@ uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
if (num_pre == 1)
{
if ((i = strstr(p, "<PRE>")) == NULL)
{
proz_debug("nomatches found");
@ -240,7 +241,8 @@ uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
proz_debug("nomatches found");
return MIRPARSEFAIL;
}
} else
}
else
{
/*search for the reported hits text */
char *rep_hits;
@ -358,7 +360,6 @@ uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
for (k = 0; k < *num_servers; k++)
{
ftp_mirrors[k].full_name =
(char *)kmalloc(strlen(ftp_mirrors[k].server_name) +
strlen(ftp_mirrors[k].paths[0].path) +
@ -379,7 +380,6 @@ uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
uerr_t parse_filesearching_html_mirror_list(ftps_request_t * request, char *p)
{
struct ftp_mirror **pmirrors = &request->mirrors;
int *num_servers = &request->num_mirrors;
char *p1, *p2, *i = 0, *j;
@ -406,7 +406,6 @@ uerr_t parse_filesearching_html_mirror_list(ftps_request_t * request, char *p)
if (num_pre == 1)
{
if ((i = strstr(p, "<pre class=list>")) == NULL)
{
proz_debug("nomatches found");
@ -420,7 +419,8 @@ uerr_t parse_filesearching_html_mirror_list(ftps_request_t * request, char *p)
proz_debug("nomatches found");
return MIRPARSEFAIL;
}
} else
}
else
{
/*search for the reported hits text */
char *rep_hits;
@ -543,7 +543,6 @@ uerr_t parse_filesearching_html_mirror_list(ftps_request_t * request, char *p)
for (k = 0; k < *num_servers; k++)
{
ftp_mirrors[k].full_name =
(char *)kmalloc(strlen(ftp_mirrors[k].server_name) +
strlen(ftp_mirrors[k].paths[0].path) +
@ -603,7 +602,8 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
connection_change_status(connection, REMOTEFATAL);
return err;
}
} else
}
else
{
connection_show_message(connection, _("Connecting to %s"),
connection->u.host);
@ -642,7 +642,8 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth);
} else
}
else
www_auth = 0;
if (http_use_proxy(connection))
@ -659,7 +660,8 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
{
remote_port = NULL;
remote_port_len = 0;
} else
}
else
{
remote_port = (char *)alloca(64);
remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
@ -676,7 +678,8 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
{
location = (char *)alloca(strlen(connection->u.url) + 1);
strcpy(location, connection->u.url);
} else
}
else
{
location = (char *)alloca(strlen(connection->u.path) + 1);
strcpy(location, connection->u.path);
@ -739,7 +742,6 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
do
{
ret =
krecv(connection->data_sock, buffer, sizeof(buffer), 0,
&connection->xfer_timeout);
@ -751,8 +753,7 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
p = p2;
}
total += ret;
}
while (ret > 0);
} while (ret > 0);
if (ret == -1)
{
@ -777,7 +778,6 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
char *find_ahref(char *buf)
{
return(strcasestr(buf, "<A HREF="));
}
@ -835,7 +835,8 @@ char *grow_buffer(char *buf_start, char *cur_pos, int *buf_len,
p = krealloc(buf_start, *buf_len + INIT_SIZE);
*buf_len += INIT_SIZE;
return p;
} else
}
else
{
return buf_start;
}
@ -852,9 +853,6 @@ void proz_get_complete_mirror_list(ftps_request_t * request)
(void *)&get_complete_mirror_list,
(void *)request) != 0)
proz_die(_("Error: Not enough system resources"));
}
@ -911,7 +909,8 @@ uerr_t get_complete_mirror_list(ftps_request_t * request)
request->info_running = FALSE;
pthread_mutex_unlock(&request->access_mutex);
return(request->err = HERR);
} else
}
else
connection_show_message(request->connection,
_("Redirected to => %s"),
constructed_newloc);
@ -919,8 +918,7 @@ uerr_t get_complete_mirror_list(ftps_request_t * request)
kfree(constructed_newloc);
request->err = NEWLOCATION;
}
}
while (request->err == NEWLOCATION);
} while (request->err == NEWLOCATION);
/*TODO handle and process the redirection here */
if (request->err != HOK)
@ -937,13 +935,13 @@ uerr_t get_complete_mirror_list(ftps_request_t * request)
request->info_running = FALSE;
pthread_mutex_unlock(&request->access_mutex);
return request->err;
}
boolean proz_request_info_running(ftps_request_t * request)
{
boolean ret;
pthread_mutex_lock(&request->access_mutex);
ret = request->info_running;
pthread_mutex_unlock(&request->access_mutex);
@ -953,6 +951,7 @@ boolean proz_request_info_running(ftps_request_t * request)
boolean proz_request_mass_ping_running(ftps_request_t * request)
{
boolean ret;
pthread_mutex_lock(&request->access_mutex);
ret = request->mass_ping_running;
pthread_mutex_unlock(&request->access_mutex);
@ -964,7 +963,6 @@ boolean proz_request_mass_ping_running(ftps_request_t * request)
ftp_mirror_t *reprocess_mirror_list(ftp_mirror_t * mirrors,
int *num_servers)
{
ftp_mirror_t *ftp_mirrors;
int i, j;
int num_new_servers = 0;
@ -1067,6 +1065,7 @@ int compare_two_servers(const void *a, const void *b)
void proz_sort_mirror_list(ftp_mirror_t * mirrors, int num_servers)
{
int i;
qsort(mirrors, num_servers, sizeof(ftp_mirror_t), compare_two_servers);
for (i = 0; i < num_servers; i++)
proz_debug("Mirror = %s, time =%d", mirrors[i].server_name,
@ -1079,9 +1078,9 @@ void proz_sort_mirror_list(ftp_mirror_t * mirrors, int num_servers)
int ftpsearch_get_server_position(ftps_request_t * request, char *server)
{
int i;
for (i = 0; i < request->num_mirrors; i++)
{
if (strcmp(request->mirrors[i].server_name, server) == 0)
return i;
}
@ -1105,8 +1104,6 @@ int ftpsearch_get_path_position(ftps_request_t * request, char *server,
proz_debug("path to check is %s", path);
if (strcmp(request->mirrors[pos].paths[i].path, path) == 0)
return i;
}
return -1;
}

View File

@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
/* $Id: http-retr.c,v 1.20 2005/03/31 20:10:57 sean Exp $ */
/* $Id$ */
#include "common.h"
#include "prozilla.h"
@ -79,7 +79,8 @@ uerr_t proz_http_get_file(connection_t * connection)
connection_change_status(connection, REMOTEFATAL);
return err;
}
} else
}
else
{
connection_show_message(connection, _("Connecting to %s"),
connection->u.host);
@ -118,7 +119,8 @@ uerr_t proz_http_get_file(connection_t * connection)
www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth);
} else
}
else
www_auth = 0;
if (http_use_proxy(connection))
@ -135,7 +137,8 @@ uerr_t proz_http_get_file(connection_t * connection)
{
remote_port = NULL;
remote_port_len = 0;
} else
}
else
{
remote_port = (char *)alloca(64);
remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
@ -159,7 +162,8 @@ uerr_t proz_http_get_file(connection_t * connection)
{
location = (char *)alloca(strlen(connection->u.url) + 1);
strcpy(location, connection->u.url);
} else
}
else
{
location = (char *)alloca(strlen(connection->u.path) + 1);
strcpy(location, connection->u.path);
@ -260,6 +264,7 @@ of maximum tries for the connection is realised
uerr_t http_loop(connection_t * connection)
{
boolean retrying_from_loop = FALSE;
assert(connection->max_attempts >= 0);
assert(connection->attempts >= 0);
@ -269,7 +274,6 @@ uerr_t http_loop(connection_t * connection)
{
if (connection->attempts > 0)
{
if (retrying_from_loop == TRUE)
{
connection_show_message(connection,
@ -287,7 +291,8 @@ uerr_t http_loop(connection_t * connection)
_
("Error while attemting to process download file "));
}
} else
}
else
{
/*If we cant resume then reset the connections bytesreceived to 0 */
connection->remote_bytes_received = 0;
@ -324,9 +329,7 @@ uerr_t http_loop(connection_t * connection)
}
retrying_from_loop = TRUE;
}
while ((connection->attempts < connection->max_attempts)
} while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0);
@ -336,7 +339,6 @@ uerr_t http_loop(connection_t * connection)
connection->attempts);
return connection->err;
}
@ -361,7 +363,6 @@ boolean http_loop_handle_error(uerr_t err)
*/
uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
{
uerr_t err;
int remote_port_len;
char *user, *passwd, *www_auth = NULL, *proxy_auth = NULL, *range =
@ -424,7 +425,8 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth);
} else
}
else
www_auth = 0;
if (strlen(connection->ftp_proxy->username)
@ -487,11 +489,13 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
{
connection_change_status(connection, LOGINFAIL);
return FTPLOGREFUSED;
} else if (err == HTTPNSFOD)
}
else if (err == HTTPNSFOD)
{
connection_change_status(connection, REMOTEFATAL);
return FTPNSFOD;
} else if (err != HOK)
}
else if (err != HOK)
{
connection_change_status(connection, REMOTEFATAL);
return FTPERR;
@ -526,5 +530,4 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
return FTPOK;
else
return err;
}

View File

@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
/* $Id: http-retr.h,v 1.5 2001/06/25 12:30:56 kalum Exp $ */
/* $Id$ */
#ifndef HTTP_RETR_H

View File

@ -19,7 +19,7 @@
/* HTTP support. */
/* $Id: http.c,v 1.22 2005/03/31 20:10:57 sean Exp $ */
/* $Id$ */
#include "common.h"
@ -154,7 +154,8 @@ uerr_t fetch_next_header(int fd, char **hdr, struct timeval * timeout)
break;
}
} else if (res == 0)
}
else if (res == 0)
return HEOF;
else
return HERR;
@ -216,7 +217,8 @@ int hparsestatline(const char *hdr, const char **rp)
*rp = hdr + 3;
else
return -1;
} else
}
else
*rp = hdr + 4;
return statcode;
@ -409,7 +411,8 @@ uerr_t http_fetch_headers(connection_t * connection, http_stat_t * hs,
kfree(all_headers);
return HEOF;
} else if (err == HERR)
}
else if (err == HERR)
{
proz_debug(_("Read error in headers"));
@ -574,7 +577,8 @@ uerr_t proz_http_get_url_info(connection_t * connection)
connection->http_proxy->proxy_url.host);
return err;
}
} else
}
else
{
connection_show_message(connection, _("Connecting to %s"),
connection->u.host);
@ -612,7 +616,8 @@ uerr_t proz_http_get_url_info(connection_t * connection)
www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth);
} else
}
else
www_auth = 0;
if (http_use_proxy(connection))
@ -629,7 +634,8 @@ uerr_t proz_http_get_url_info(connection_t * connection)
{
remote_port = NULL;
remote_port_len = 0;
} else
}
else
{
remote_port = (char *)alloca(64);
remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
@ -647,7 +653,8 @@ uerr_t proz_http_get_url_info(connection_t * connection)
{
location = (char *)alloca(strlen(connection->u.url) + 1);
strcpy(location, connection->u.url);
} else
}
else
{
location = (char *)alloca(strlen(connection->u.path) + 1);
strcpy(location, connection->u.path);
@ -704,7 +711,6 @@ uerr_t proz_http_get_url_info(connection_t * connection)
/*Loops for connection->attempts */
uerr_t http_get_url_info_loop(connection_t * connection)
{
pthread_mutex_lock(&connection->access_mutex);
connection->running = TRUE;
pthread_mutex_unlock(&connection->access_mutex);
@ -714,7 +720,6 @@ uerr_t http_get_url_info_loop(connection_t * connection)
{
if (connection->attempts > 0 && connection->err != NEWLOCATION)
{
connection_show_message(connection,
_("Retrying...Attempt %d in %d seconds"),
connection->attempts,
@ -756,9 +761,7 @@ uerr_t http_get_url_info_loop(connection_t * connection)
connection_show_message(connection, proz_strerror(connection->err));
break;
}
}
while ((connection->attempts < connection->max_attempts)
} while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0);
@ -782,7 +785,6 @@ uerr_t http_get_url_info_loop(connection_t * connection)
uerr_t ftp_get_url_info_from_http_proxy(connection_t * connection)
{
uerr_t err;
int remote_port_len;
char *user, *passwd, *www_auth = NULL, *proxy_auth =
@ -829,7 +831,8 @@ uerr_t ftp_get_url_info_from_http_proxy(connection_t * connection)
www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth);
} else
}
else
www_auth = 0;
if (strlen(connection->ftp_proxy->username)
@ -897,5 +900,4 @@ uerr_t ftp_get_url_info_from_http_proxy(connection_t * connection)
/* connection->file_type = REGULAR_FILE; */
return FTPERR;
}

View File

@ -19,7 +19,7 @@
/* HTTP support. */
/* $Id: http.h,v 1.12 2005/03/31 20:10:57 sean Exp $ */
/* $Id$ */
#ifndef HTTP_H

View File

@ -41,7 +41,6 @@ int log_create_logfile(int num_connections, int file_size, char *url,
download->u.file, DEFAULT_FILE_EXT);
if (!(fp = fopen(buffer, "wb")))
{
/*
* fixme add the error displaing to the main function
*/
@ -84,7 +83,6 @@ int log_create_logfile(int num_connections, int file_size, char *url,
{
for (i = 0; i < download->num_connections; i++)
{
pthread_mutex_lock(&download->pconnections[i]->access_mutex);
if (fwrite
@ -92,7 +90,6 @@ int log_create_logfile(int num_connections, int file_size, char *url,
sizeof(download->pconnections[i]->local_startpos),
fp) != sizeof(download->pconnections[i]->local_startpos))
{
pthread_mutex_unlock(&download->pconnections[i]->access_mutex);
download_show_message(download, _("Error writing to file %s: %s"),
buffer, strerror(errno));
@ -105,7 +102,6 @@ int log_create_logfile(int num_connections, int file_size, char *url,
sizeof(download->pconnections[i]->orig_remote_startpos),
fp) != sizeof(download->pconnections[i]->orig_remote_startpos))
{
pthread_mutex_unlock(&download->pconnections[i]->access_mutex);
download_show_message(download, _("Error writing to file %s: %s"),
buffer, strerror(errno));
@ -130,7 +126,6 @@ int log_create_logfile(int num_connections, int file_size, char *url,
sizeof(download->pconnections[i]->remote_bytes_received),
fp) != sizeof(download->pconnections[i]->remote_bytes_received))
{
pthread_mutex_unlock(&download->pconnections[i]->access_mutex);
download_show_message(download, _("Error writing to file %s: %s"),
buffer, strerror(errno));
@ -138,9 +133,7 @@ int log_create_logfile(int num_connections, int file_size, char *url,
return -1;
}
pthread_mutex_unlock(&download->pconnections[i]->access_mutex);
}
}
fclose(fp);
@ -167,7 +160,8 @@ int proz_log_logfile_exists(download_t * download)
return 0;
else
return -1;
} else
}
else
return 1;
}
@ -187,7 +181,8 @@ int proz_log_delete_logfile(download_t * download)
{
download_show_message(download, _("logfile doesn't exist"));
return 1;
} else
}
else
{
download_show_message(download, "Error: Unable to delete the logfile: %s", strerror(errno));
return -1;
@ -245,9 +240,6 @@ int proz_log_read_logfile(logfile * lf, download_t * download,
{
for (i = 0; i < lf->num_connections; i++)
{
proz_debug("value before= %d", download->pconnections[i]->local_startpos);
if (fread
@ -309,9 +301,7 @@ int proz_log_read_logfile(logfile * lf, download_t * download,
}
proz_debug("remote_bytes_received after= %d", download->pconnections[i]->remote_bytes_received);
}
}

View File

@ -101,7 +101,9 @@ int proz_init(int argc, char **argv)
sprintf(netrc_file, "%s/%s", libprozrtinfo.home_dir, ".netrc");
libprozrtinfo.netrc_list = parse_netrc(netrc_file);
} else {
}
else
{
/* Make sure home dir is never NULL */
libprozrtinfo.home_dir = kstrdup(".");
}
@ -199,7 +201,6 @@ void proz_set_download_dir(char *dir)
kfree(libprozrtinfo.dl_dir);
libprozrtinfo.dl_dir = kstrdup(dir);
}
void proz_set_logfile_dir(char *dir)
@ -224,6 +225,5 @@ void proz_set_output_dir(char *dir)
char *proz_get_libprozilla_version()
{
return strdup(VERSION);
}

View File

@ -19,7 +19,7 @@
/* Miscellaneous routines. */
/* $Id: misc.c,v 1.32 2005/01/11 01:49:11 sean Exp $ */
/* $Id$ */
#include "common.h"
@ -156,8 +156,7 @@ void prnum(char *where, long num)
{
*p++ = num % 10 + '0';
num /= 10;
}
while (num);
} while (num);
/* And reverse them. */
l = p - where - 1;
@ -183,18 +182,20 @@ int setargval(char *optstr, int *num)
{
*num = atoi(optstr + 1);
return 1;
} else
}
else
return 0;
} else
}
else
{
if (is_number(optstr))
{
*num = atoi(optstr);
return 1;
} else
}
else
return 0;
}
}
/******************************************************************************
@ -264,7 +265,6 @@ char *home_dir(void)
int proz_timeval_subtract(struct timeval *result, struct timeval *x,
struct timeval *y)
{
/* Perform the carry for the later subtraction by updating Y. */
if (x->tv_usec < y->tv_usec)
{
@ -308,8 +308,8 @@ void delay_ms(int ms)
/*Closes a socket and zeroes the socket before returning */
int close_sock(int *sock)
{
int retval = close(*sock);
*sock = 0;
return retval;
}
@ -318,78 +318,109 @@ int close_sock(int *sock)
char *proz_strerror(uerr_t error)
{
switch (error)
{
case HOSTERR:
return _("Unable to lookup hostname");
case CONSOCKERR:
return _("Unable to create socket");
case CONERROR:
return _("Error occured while connecting");
case CONREFUSED:
return _("The connection attempt was refused");
case ACCEPTERR:
return _("Error while accepting the connection");
case BINDERR:
return _("Error while Binding socket");
case LISTENERR:
return _("Error while listening");
case SERVERCLOSECONERR:
return _("The connection was reset/closed by the peer");
case URLUNKNOWN:
return _("The URL Protocol was unknown");
case URLBADPORT:
return _("The port specified in the URL is not valid!");
case URLBADHOST:
return _("The Hostname specified in the URL is not valid!");
case URLBADPATTERN:
return _("The Pattern specified in the URL does not look valid!");
case HEOF:
return _("End of file reached in HTTP connection");
case HERR:
return _("Error occured in HTTP data transfer");
case HAUTHREQ:
return _("Authentification is required to access this resource");
case HAUTHFAIL:
return _("Failed to Authenticate with host!");
case HTTPNSFOD:
return _("The URL was not found on the host!");
case FTPLOGREFUSED:
return _("The host disallowed the login attempt");
case FTPPORTERR:
return _("The PORT request was rejected by the server");
case FTPNSFOD:
return _("The object file/dir was not found on the host!");
case FTPUNKNOWNTYPE:
return _("The TYPE specified in not known by the FTP server!");
case FTPUNKNOWNCMD:
return _("The command is not known by the FTP server!");
case FTPSIZEFAIL:
return _("The SIZE command failed");
case FTPERR:
return _("Error occured in FTP data transfer");
case FTPRESTFAIL:
return _("The REST command failed");
case FTPACCDENIED:
return _("The peer did not allow access");
case FTPPWDERR:
return _("The host rejected the password");
case FTPPWDFAIL:
return _("The host rejected the password");
case FTPINVPASV:
return _("The PASV (passive mode) was not supported the host");
case FTPNOPASV:
return _("The host does not support PASV (passive mode) transfers");
case FTPCONREFUSED:
return _("The connection attempt was refused");
case FTPCWDFAIL:
return _("Failed to (CWD)change to the directory");
case FTPSERVCLOSEDATLOGIN:
return
_
("The host said the requested service was unavailable and closed the control connection");
case CONPORTERR:
return _("getsockname failed!");
@ -420,28 +451,34 @@ char *proz_strerror(uerr_t error)
case FOPENERR:
return _("Error while opening file");
case FWRITEERR:
return _("Error while writing to file");
case DLABORTED:
return _("The Download was aborted");
case DLLOCALFATAL:
return _("The Download encountered a local fatal error");
case CANTRESUME:
return _("Error: Resuming this connection is not possible");
case READERR:
return _("Error while reading data from socket");
case WRITEERR:
return _("Error while writing data to socket");
case PROXERR:
return _("Error while Proxying");
case FILEISDIR:
return _("The location is a directory");
default:
return _("Unknown/Unsupported error code");
}
}
/* Cleanup handler which will be popped and which will be called when the thread is cancelled, it make sure that there will be no sockets left open if the thread is cancelled prematurely
@ -457,6 +494,7 @@ void cleanup_socks(void *cdata)
case URLHTTP:
cleanup_httpsocks(connection);
break;
case URLFTP:
if (ftp_use_proxy(connection)
&& connection->ftp_proxy->type == HTTPPROXY)
@ -464,9 +502,11 @@ void cleanup_socks(void *cdata)
/* We have to cleanup the http socks instead
if we are going through a http proxy */
cleanup_httpsocks(connection);
} else
}
else
cleanup_ftpsocks(connection);
break;
default:
proz_die(_("Error: unsupported protocol"));
}
@ -487,7 +527,8 @@ void cleanup_ftpsocks(connection_t * connection)
if (flags == -1)
{
proz_debug("data sock invalid\n");
} else
}
else
close_sock(&connection->data_sock);
}
@ -497,10 +538,10 @@ void cleanup_ftpsocks(connection_t * connection)
if (flags == -1)
{
proz_debug("control sock invalid\n");
} else
}
else
close_sock(&connection->ctrl_sock);
}
}
@ -516,10 +557,10 @@ void cleanup_httpsocks(connection_t * connection)
if (flags == -1)
{
proz_debug("sock invalid\n");
} else
}
else
close(connection->data_sock);
}
}

View File

@ -19,7 +19,7 @@
/* Miscellaneous routines. */
/* $Id: misc.h,v 1.25 2001/09/02 23:29:16 kalum Exp $ */
/* $Id$ */
#ifndef MISC_H

View File

@ -18,7 +18,7 @@
/* Slightly modified for libprozilla, by Grendel <kalum@delrom.ro>. */
/* $Id: netrc.c,v 1.17 2001/08/09 23:35:26 kalum Exp $ */
/* $Id$ */
#include "common.h"
@ -35,6 +35,7 @@
static void maybe_add_to_list(netrc_entry ** newentry, netrc_entry ** list)
{
netrc_entry *a, *l;
a = *newentry;
l = *list;
@ -46,7 +47,8 @@ static void maybe_add_to_list(netrc_entry ** newentry, netrc_entry ** list)
kfree(a->host);
if (a->password)
kfree(a->password);
} else
}
else
{
if (a)
{
@ -146,13 +148,15 @@ netrc_entry *parse_netrc(char *file)
{
quote_char = 0;
p++;
} else
}
else
{
*pp = *p;
p++;
pp++;
}
} else
}
else
{
if (*p == '"' || *p == '\'')
quote_char = *p;

View File

@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* $Id: netrc.h,v 1.11 2001/05/30 15:01:40 kalum Exp $ */
/* $Id$ */
#ifndef NETRC_H

View File

@ -52,7 +52,8 @@ uerr_t tcp_ping(ping_t * ping_data)
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(ping_data->host, szPort, &hints, &res);
if (error) {
if (error)
{
return ping_data->err = HOSTERR;
}
@ -101,7 +102,8 @@ uerr_t tcp_ping(ping_t * ping_data)
if (errno == EINPROGRESS)
errno = ETIMEDOUT;
} else if (status == 0)
}
else if (status == 0)
errno = ETIMEDOUT, status = -1;
}
@ -113,16 +115,19 @@ uerr_t tcp_ping(ping_t * ping_data)
{
free(res);
return ping_data->err = CONREFUSED;
} else if (errno == ETIMEDOUT)
}
else if (errno == ETIMEDOUT)
{
free(res);
return ping_data->err = PINGTIMEOUT;
} else
}
else
{
free(res);
return ping_data->err = CONERROR;
}
} else
}
else
{
flags = fcntl(ping_data->sock, F_GETFL, 0);
@ -172,12 +177,10 @@ uerr_t tcp_ping(ping_t * ping_data)
void proz_mass_ping(ftps_request_t * request)
{
request->mass_ping_running = TRUE;
if (pthread_create(&request->mass_ping_thread, NULL,
(void *)&mass_ping, (void *)request) != 0)
proz_die(_("Error: Not enough system resources"));
}
void proz_cancel_mass_ping(ftps_request_t * request)
@ -248,7 +251,8 @@ void mass_ping(ftps_request_t * request)
(ping_requests[k].ping_time.tv_usec / 1000);
request->mirrors[k].status = RESPONSEOK;
pthread_mutex_unlock(&request->access_mutex);
} else
}
else
{
pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].status = NORESPONSE;
@ -295,7 +299,8 @@ void mass_ping(ftps_request_t * request)
(ping_requests[k].ping_time.tv_usec / 1000);
request->mirrors[k].status = RESPONSEOK;
pthread_mutex_unlock(&request->access_mutex);
} else
}
else
{
pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].status = NORESPONSE;

View File

@ -19,7 +19,7 @@
/* Main include-file. */
/* $Id: prozilla.h,v 1.63 2005/09/19 15:25:48 kalum Exp $ */
/* $Id$ */
#ifndef PROZILLA_H
@ -223,7 +223,6 @@ extern "C" {
typedef struct connection_t {
/* struct which contains the parsed url info. It includes the remote file,
path,protocol etc. */
urlinfo u;

View File

@ -19,7 +19,7 @@
/* A test program. */
/* $Id: test.c,v 1.30 2001/09/23 01:39:16 kalum Exp $ */
/* $Id$ */
#include "common.h"

View File

@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* $Id: url.c,v 1.23 2001/10/27 11:24:40 kalum Exp $ */
/* $Id$ */
#include "common.h"
@ -181,6 +181,7 @@ int skip_uname(const char *url)
{
const char *p;
const char *q = NULL;
for (p = url; *p && *p != '/'; p++)
if (*p == '@')
q = p;
@ -210,7 +211,8 @@ void decode_string(char *s)
{
copychar:
*t = *h;
} else
}
else
{
/* Do nothing if '%' is not followed by two hex digits. */
if (!*(h + 1) || !*(h + 2)
@ -231,12 +233,14 @@ char *encode_string_maybe(const char *s)
char *p2, *newstr;
int newlen;
int addition = 0;
/*Changes Grendel: (*p1!='%') added */
for (p1 = s; *p1; p1++)
if ((*p1 != '%') && UNSAFE_CHAR(*p1))
addition += 2; /* Two more characters (hex digits) */
addition += 2;
/* Two more characters (hex digits) */
if (!addition)
return (char *)s;
@ -256,7 +260,8 @@ if ((*p1!='%') && UNSAFE_CHAR(*p1))
*p2++ = '%';
*p2++ = XDIGIT_TO_XCHAR(c >> 4);
*p2++ = XDIGIT_TO_XCHAR(c & 0xf);
} else
}
else
*p2++ = *p1++;
}
*p2 = '\0';
@ -290,7 +295,7 @@ char *encode_string(const char *s)
ptr = e_new; \
} \
} while (0)
/* Returns the protocol type if URL's protocol is supported, or
URLUNKNOWN if not. */
uerr_t urlproto(const char *url)
@ -300,7 +305,8 @@ uerr_t urlproto(const char *url)
for (i = 0; i < ARRAY_SIZE(sup_protos); i++)
if (!strncasecmp(url, sup_protos[i].name, strlen(sup_protos[i].name)))
return sup_protos[i].ind;
for (i = 0; url[i] && url[i] != ':' && url[i] != '/'; i++);
for (i = 0; url[i] && url[i] != ':' && url[i] != '/'; i++)
;
if (url[i] == ':')
{
for (++i; url[i] && url[i] != '/'; i++)
@ -310,7 +316,8 @@ uerr_t urlproto(const char *url)
return URLFTP;
else
return URLHTTP;
} else
}
else
return URLHTTP;
}
@ -324,7 +331,8 @@ char process_ftp_type(char *path)
{
path[len - 7] = '\0';
return path[len - 1];
} else
}
else
return '\0';
}
@ -367,7 +375,8 @@ void path_simplify(char *path)
{
i += 3;
ddot = 1;
} else
}
else
break;
}
if (i)
@ -433,7 +442,8 @@ void path_simplify(char *path)
/* Handle `../' or trailing `..' by itself. */
if (path[i + 1] == '.' && (path[i + 2] == '/' || !path[i + 2]))
{
while (--start > -1 && path[start] != '/');
while (--start > -1 && path[start] != '/')
;
strcpy(path + start + 1, path + i + 2);
i = (start < 0) ? 0 : start;
continue;
@ -461,6 +471,7 @@ void path_simplify(char *path)
int urlpath_length(const char *url)
{
const char *q = strchr(url, '?');
if (q)
return q - url;
return strlen(url);
@ -477,7 +488,8 @@ void parse_dir(const char *path, char **dir, char **file)
int i, l;
l = urlpath_length(path);
for (i = l; i && path[i] != '/'; i--);
for (i = l; i && path[i] != '/'; i--)
;
if (!i && *path != '/') /* Just filename */
{
@ -486,31 +498,36 @@ void parse_dir(const char *path, char **dir, char **file)
*dir = strdupdelim(path, path + l);
*file = kstrdup(path + l); /* normally empty, but could
contain ?... */
} else
}
else
{
*dir = kstrdup(""); /* This is required because of FTP */
*file = kstrdup(path);
}
} else if (!i) /* /filename */
}
else if (!i) /* /filename */
{
if (PD_DOTP(path + 1) || PD_DDOTP(path + 1))
{
*dir = strdupdelim(path, path + l);
*file = kstrdup(path + l); /* normally empty, but could
contain ?... */
} else
}
else
{
*dir = kstrdup("/");
*file = kstrdup(path + 1);
}
} else /* Nonempty directory with or without a filename */
}
else /* Nonempty directory with or without a filename */
{
if (PD_DOTP(path + i + 1) || PD_DDOTP(path + i + 1))
{
*dir = strdupdelim(path, path + l);
*file = kstrdup(path + l); /* normally empty, but could
contain ?... */
} else
}
else
{
*dir = strdupdelim(path, path + i);
*file = kstrdup(path + i + 1);
@ -735,7 +752,8 @@ uerr_t proz_parse_url(const char *url, urlinfo * u, int strict)
them for now). */
if (recognizable)
l += skip_uname(url + l);
for (i = l; url[i] && url[i] != ':' && url[i] != '/'; i++);
for (i = l; url[i] && url[i] != ':' && url[i] != '/'; i++)
;
if (i == l)
return URLBADHOST;
/* Get the hostname. */
@ -758,11 +776,13 @@ uerr_t proz_parse_url(const char *url, urlinfo * u, int strict)
return URLBADPORT;
if (!u->port)
return URLBADPORT;
} else if (type == URLUNKNOWN) /* or a directory */
}
else if (type == URLUNKNOWN) /* or a directory */
u->proto = type = URLFTP;
else /* or just a misformed port number */
return URLBADPORT;
} else if (type == URLUNKNOWN)
}
else if (type == URLUNKNOWN)
u->proto = type = URLHTTP;
if (!u->port)
{
@ -868,7 +888,8 @@ char *construct_relative(const char *s1, const char *s2)
{
for (;
s1[i] && s2[i] && s1[i] == s2[i] && s1[i] != '/'
&& s2[i] != '/'; i++);
&& s2[i] != '/'; i++)
;
if (s1[i] == '/' && s2[i] == '/')
cnt = ++i;
else
@ -913,8 +934,6 @@ urlpos *add_url(urlpos * l, const char *url, const char *file)
/*This will copy a url structure to another */
void url_cpy(urlinfo * src, urlinfo * dest)
{
}
@ -983,14 +1002,16 @@ char *uri_merge_1(const char *base, const char *link, int linklength,
/* ^ ('?' gets changed to '/') */
start_insert = end + 1;
need_explicit_slash = 1;
} else if (last_slash && last_slash != base
}
else if (last_slash && last_slash != base
&& *(last_slash - 1) == '/')
{
/* example: http://host" */
/* ^ */
start_insert = end + 1;
need_explicit_slash = 1;
} else
}
else
{
/* example: "whatever/foo/bar" */
/* ^ */
@ -1006,7 +1027,8 @@ char *uri_merge_1(const char *base, const char *link, int linklength,
if (linklength)
memcpy(constr + span, link, linklength);
constr[span + linklength] = '\0';
} else /* *link == `/' */
}
else /* *link == `/' */
{
/* LINK is an absolute path: we need to replace everything
after (and including) the FIRST slash with LINK.
@ -1062,7 +1084,8 @@ char *uri_merge_1(const char *base, const char *link, int linklength,
memcpy(constr + span, link, linklength);
constr[span + linklength] = '\0';
}
} else /* !no_proto */
}
else /* !no_proto */
{
constr = strdupdelim(link, link + linklength);
}

View File

@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* $Id: url.h,v 1.20 2001/08/17 21:53:39 kalum Exp $ */
/* $Id$ */
#ifndef URL_H

View File

@ -1,20 +1,20 @@
/******************************************************************************
fltk prozilla - a front end for prozilla, a download accelerator library
Copyright (C) 2001 Kalum Somaratna
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* fltk prozilla - a front end for prozilla, a download accelerator library
* Copyright (C) 2001 Kalum Somaratna
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
#if HAVE_CONFIG_H
@ -38,7 +38,6 @@
void
DL_Window::cleanup(boolean erase_dlparts)
{
/*handle cleanup */
if (status == DL_DOWNLOADING)
{
@ -69,13 +68,14 @@ DL_Window::cleanup (boolean erase_dlparts)
status = DL_ABORTED;
}
DL_Window::~DL_Window()
{
proz_connection_free_connection(connection, true);
delete (ftpsearch_win);
}
DL_Window::DL_Window(urlinfo *url_data)
{
// key = 0;
@ -90,9 +90,9 @@ DL_Window::DL_Window (urlinfo * url_data)
ftpsearch_win = new FTPS_Window();
do_ftpsearch = FALSE;
using_ftpsearch = FALSE;
}
void
DL_Window::my_cb()
{
@ -104,8 +104,8 @@ DL_Window::my_cb ()
// if ((got_info == TRUE && status == DL_IDLING && got_dl == FALSE)
if ((status == DL_RESTARTING && got_info == TRUE)
|| status == DL_DLPRESTART)
if (((status == DL_RESTARTING) && (got_info == TRUE)) ||
(status == DL_DLPRESTART))
{
do_download();
}
@ -139,15 +139,12 @@ DL_Window::my_cb ()
handle_ftpsearch();
return;
}
}
void
DL_Window::dl_start(int num_connections, boolean ftpsearch)
{
do_ftpsearch = ftpsearch;
connection = proz_connection_init(&u, &getinfo_mutex);
@ -164,6 +161,7 @@ void
DL_Window::do_download()
{
logfile lf;
status = DL_DLPRESTART;
//setup the download
download = proz_download_init(&connection->u);
@ -193,18 +191,22 @@ DL_Window::do_download ()
}
}
if (rt.display_mode == DISP_CURSES)
{
erase();
}
start_download();
}
void
DL_Window::handle_prev_download()
{
int ret = 0;
/* we will check and see if 1. previous partial download exists and
2. if the file to be downloaded already exists in the local
directory
* 2. if the file to be downloaded already exists in the local
* directory
*/
//Check and see if the file is already downloaded..
@ -224,14 +226,12 @@ DL_Window::handle_prev_download ()
status = DL_FATALERR;
return;
}
}
}
/*Check for a prior download */
int previous_dl = proz_download_prev_download_exists(download);
if (previous_dl == 1)
{
download->resume_mode = TRUE;
//connection supports resume
if (connection->resume_support)
@ -241,25 +241,33 @@ DL_Window::handle_prev_download ()
{
//see if the user had a preference, resume or overwrite
if (rt.resume_mode == TRUE)
{
download->resume_mode = TRUE;
}
else
if (rt.force_mode == TRUE)
{
download->resume_mode = FALSE;
}
}
else
{
//ask the user (curses or terminal)
ret = askUserResume(connection, true);
if (ret == 'R')
{
download->resume_mode = TRUE;
}
else
{
download->resume_mode = FALSE;
}
}
}
else
{ //resume NOT supported
// --no-getch and no force-mode means fatal error!!!
if (rt.dont_prompt == TRUE && rt.force_mode == FALSE)
if ((rt.dont_prompt == TRUE) && (rt.force_mode == FALSE))
{
status = DL_FATALERR;
handle_dl_fatal_error();
@ -267,14 +275,18 @@ DL_Window::handle_prev_download ()
}
//force overwrite
if (rt.dont_prompt == TRUE && rt.force_mode == TRUE)
if ((rt.dont_prompt == TRUE) && (rt.force_mode == TRUE))
{
download->resume_mode = FALSE;
}
else
{
//Ask the user
ret = askUserResume(connection, false);
if (ret == 'O')
{
download->resume_mode = FALSE;
}
else
{ //Abort
status = DL_FATALERR;
@ -287,7 +299,6 @@ DL_Window::handle_prev_download ()
}
void
DL_Window::start_download()
{
@ -295,15 +306,19 @@ DL_Window::start_download ()
proz_debug("start_download");
if (using_ftpsearch != TRUE)
{
ret = num_connections =
proz_download_setup_connections_no_ftpsearch
(download, connection, num_connections);
}
else
{
ret = proz_download_setup_connections_ftpsearch(download,
connection,
ftpsearch_win->
request,
num_connections);
}
if (ret == -1)
{
@ -326,10 +341,9 @@ DL_Window::start_download ()
proz_download_start_downloads(download, download->resume_mode);
status = DL_DOWNLOADING;
return;
}
void
DL_Window::handle_info_thread()
{
@ -340,7 +354,7 @@ DL_Window::handle_info_thread ()
{
pthread_join(info_thread, NULL);
if (connection->err == HOK || connection->err == FTPOK)
if ((connection->err == HOK) || (connection->err == FTPOK))
{
got_info = TRUE;
@ -350,11 +364,13 @@ DL_Window::handle_info_thread ()
connection->main_file_size / 1024);
}
else
{
PrintMessage("File Size is UNKOWN\n\n");
}
//Added ftpsearch only is size > min size
if ((connection->main_file_size != -1
&& do_ftpsearch == TRUE) && (connection->main_file_size / 1024 >= rt.min_search_size))
if (((connection->main_file_size != -1) &&
(do_ftpsearch == TRUE)) && (connection->main_file_size / 1024 >= rt.min_search_size))
{
status = DL_FTPSEARCHING;
@ -377,22 +393,21 @@ DL_Window::handle_info_thread ()
"http://ftpsearch.elmundo.es:8000/ftpsearch",
LYCOS, rt.ftps_mirror_req_n);
}
}
else
{
if (connection->main_file_size / 1024 >= rt.min_search_size && (do_ftpsearch == TRUE))
if ((connection->main_file_size / 1024 >= rt.min_search_size) && (do_ftpsearch == TRUE))
{
PrintMessage("File size is less than the minimum, skipping ftpsearch");
}
do_download();
}
}
else
{
if (connection->err == FTPNSFOD
|| connection->err == HTTPNSFOD)
if ((connection->err == FTPNSFOD) ||
(connection->err == HTTPNSFOD))
{
PrintMessage("The URL %s doesnt exist!\n",
connection->u.url);
@ -408,7 +423,6 @@ DL_Window::handle_info_thread ()
got_info = FALSE;
status = DL_FATALERR;
}
}
}
}
@ -417,8 +431,8 @@ DL_Window::handle_info_thread ()
void
DL_Window::handle_ftpsearch()
{
uerr_t err;
err = ftpsearch_win->callback();
if (err == MASSPINGDONE)
{
@ -455,10 +469,10 @@ DL_Window::handle_ftpsearch ()
}
}
void
DL_Window::handle_download_thread()
{
uerr_t err;
struct timeval cur_time;
struct timeval diff_time;
@ -470,10 +484,9 @@ DL_Window::handle_download_thread ()
proz_timeval_subtract(&diff_time, &cur_time, &update_time);
if ((((diff_time.tv_sec * 1000) + (diff_time.tv_usec / 1000)) > 200)
|| err == DLDONE)
if ((((diff_time.tv_sec * 1000) + (diff_time.tv_usec / 1000)) > 200) ||
(err == DLDONE))
{
print_status(download, rt.quiet_mode);
if (download->main_file_size != -1)
@ -507,7 +520,6 @@ DL_Window::handle_download_thread ()
if (err == DLLOCALFATAL)
{
PrintMessage("One connection of the download %s encountered a unrecoverable local error, usually lack of free space, or a write to bad medium, or a problem with permissions,so please fix this and retry\n",
connection->u.url);
got_dl = FALSE;
@ -517,21 +529,18 @@ DL_Window::handle_download_thread ()
if (err == DLREMOTEFATAL)
{
PrintMessage(_
("A connection(s) of the download %s encountered a unrecoverable remote error, usually the file not being present in the remote server, therefore the download had to be aborted!\n"),
connection->u.url);
got_dl = FALSE;
status = DL_FATALERR;
}
}
void
DL_Window::handle_joining_thread()
{
boolean bDone = false;
uerr_t building_status = proz_download_get_join_status(download);
@ -543,12 +552,10 @@ DL_Window::handle_joining_thread ()
proz_download_wait_till_end_joining_thread(download);
joining_thread_running = FALSE;
}
}
if (building_status == JOINDONE)
{
if (joining_thread_running == TRUE)
{
proz_download_wait_till_end_joining_thread(download);
@ -573,26 +580,24 @@ DL_Window::handle_joining_thread ()
void
DL_Window::handle_dl_fatal_error()
{
status = DL_FATALERR;
cleanup(FALSE);
return;
}
void
DL_Window::print_status(download_t *download, int quiet_mode)
{
if (rt.display_mode == DISP_CURSES)
{
DisplayCursesInfo(download);
}
else
{
if (quiet_mode == FALSE)
{
for (int i = 0; i < download->num_connections; i++)
{
fprintf(stdout,
"%2.2d %-30.30s %15.15s %10zd\n",
i + 1, download->pconnections[i]->u.host,
@ -619,17 +624,25 @@ DL_Window::print_status (download_t * download, int quiet_mode)
proz_download_get_est_time_left(download)) != -1)
{
if (secs_left < 60)
{
snprintf(timeLeft, sizeof(timeLeft), "00:%.2d", secs_left);
}
else if (secs_left < 3600)
{
snprintf(timeLeft, sizeof(timeLeft), "00:%.2d:%.2d",
secs_left / 60, secs_left % 60);
}
else
{
snprintf(timeLeft, sizeof(timeLeft), "%.2d:%.2d:00",
secs_left / 3600,
(secs_left % 3600) / 60);
}
}
else
{
sprintf(timeLeft, "??:??:??");
}
off_t totalDownloaded = 0;
off_t totalFile = 0;
@ -650,6 +663,7 @@ DL_Window::print_status (download_t * download, int quiet_mode)
}
}
int DL_Window::askUserResume(connection_t *connection, boolean resumeSupported)
{
int ret = 0;
@ -657,9 +671,12 @@ int DL_Window::askUserResume(connection_t *connection, boolean resumeSupported)
const char msg2[] = "Previous download of %s exists, would you like to (A)bort it or (O)verwrite it?";
do {
do
{
if (rt.display_mode == DISP_CURSES)
{
ret = curses_query_user_input((resumeSupported == TRUE) ? msg : msg2, connection->u.file);
}
else
{
fprintf(stdout, "\n");
@ -672,23 +689,28 @@ int DL_Window::askUserResume(connection_t *connection, boolean resumeSupported)
{
case 'O':
break;
case 'A':
if (resumeSupported == TRUE)
{
ret = 0;
}
break;
case 'R':
if (resumeSupported == FALSE)
{
ret = 0;
}
break;
default:
ret = 0;
break;
}
} while (ret == 0);
return ret;
return(ret);
}
@ -698,9 +720,12 @@ int DL_Window::askUserOverwrite(connection_t *connectionb)
const char msg[] = "File %s already exists, would you like to (A)bort it or (O)verwrite it?";
do {
do
{
if (rt.display_mode == DISP_CURSES)
{
ret = curses_query_user_input(msg, connection->u.file);
}
else
{
fprintf(stdout, "\n");
@ -713,14 +738,15 @@ int DL_Window::askUserOverwrite(connection_t *connectionb)
{
case 'O':
break;
case 'A':
break;
default:
ret = 0;
break;
}
} while (ret == 0);
return ret;
return(ret);
}

View File

@ -35,7 +35,6 @@ typedef enum {
} dlg_class;
class DL_Window {
public:
DL_Window(urlinfo * url_data);
~DL_Window();

View File

@ -68,7 +68,6 @@ FTPS_Window::fetch_mirror_info (urlinfo * u, off_t file_size,
uerr_t
FTPS_Window::callback()
{
if (request_running == TRUE)
{
if (proz_request_info_running(request) == FALSE)
@ -103,7 +102,6 @@ FTPS_Window::callback ()
if (ping_running == TRUE)
{
print_status(request, rt.quiet_mode);
if (proz_request_mass_ping_running(request) == FALSE)
@ -145,7 +143,6 @@ FTPS_Window::cleanup ()
void
cb_exit_ftpsearch(void *data)
{
FTPS_Window *window = (FTPS_Window *)data;
window->exit_ftpsearch_button_pressed = TRUE;
@ -177,17 +174,20 @@ void FTPS_Window::print_status(ftps_request_t *request, int quiet_mode)
request->mirrors[i].server_name,
"NOT TESTED");
break;
case RESPONSEOK:
DisplayInfo(i + 1, 1, "%-30.30s %dms\n",
request->mirrors[i].server_name,
request->mirrors[i].milli_secs);
break;
case NORESPONSE:
case ERROR:
DisplayInfo(i + 1, 1, "%-30.30s %s\n",
request->mirrors[i].server_name,
"NO REPONSE");
break;
default:
DisplayInfo(i + 1, 1, "%-30.30s %s\n",
request->mirrors[i].server_name,
@ -197,7 +197,5 @@ void FTPS_Window::print_status(ftps_request_t *request, int quiet_mode)
}
if (rt.display_mode == DISP_STDOUT)
fprintf(stdout, "\n");
}
}

View File

@ -49,7 +49,6 @@ public:
boolean exit_ftpsearch_button_pressed;
private:
};
#endif

View File

@ -1,37 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Page for Apache Installation</title>
</head>
<body>
<p>If you can see this, it means that the installation of the <a
href="http://www.apache.org/foundation/preFAQ.html">Apache web server</a>
software on this system was successful. You may now add content to this
directory and replace this page.</p>
<hr style="width: 100%; height: 3px;" />
<h2 style="text-align: center">Seeing this instead of the website you expected?</h2>
<p>This page is here because the site administrator has changed the
configuration of this web server. Please <strong>contact the person
responsible for maintaining this server with questions.</strong>
The Apache Software Foundation, which wrote the web server software
this site administrator is using, has nothing to do with
maintaining this site and cannot help resolve configuration
issues.</p>
<hr style="width: 100%; height: 3px;" />
<p>The Apache documentation is available
<a href="http://httpd.apache.org/docs-2.0/">online</a> or has been installed
<a href="/manual/">locally</a>.</p>
<p>You are free to use the image below on an Apache-powered web
server. Thanks for using Apache!</p>
<div style="text-align: center"><img src="apache_pb.gif" alt="" /></div>
</body>
</html>

View File

@ -46,9 +46,9 @@ extern struct runtime rt;
/* Sets the default config */
void set_defaults()
{
struct stat st;
char cwd[PATH_MAX];
/*
* Zero the structure which holds the config data
*/
@ -83,7 +83,8 @@ void set_defaults()
(_("unable to create the directory to store the config info in"));
exit(0);
}
} else
}
else
perror(_("Error while stating the config info directory"));
}
@ -201,7 +202,6 @@ void set_runtime_values()
void cleanuprt()
{
if (rt.config_dir != 0)
free(rt.config_dir);
@ -222,5 +222,4 @@ void cleanuprt()
if (rt.logfile_dir != 0)
free(rt.logfile_dir);
}

View File

@ -57,7 +57,7 @@
* CONREJECTED,
* REMOTEFATAL,
* LOCALFATAL
*} dl_status;
**} dl_status;
*
* And here are the texts for the above enums.
*/
@ -120,6 +120,7 @@ void curses_message(char *message)
short i;
int x, y;
attr_t attrs;
/*
* Lock the mutex
*/
@ -150,7 +151,6 @@ void curses_message(char *message)
move(y, x);
pthread_mutex_unlock(&curses_msg_mutex);
}
@ -184,8 +184,7 @@ int curses_query_user_input(const char *args, ...)
{
napms(20);
ch = getch();
}
while (ch == ERR);
} while (ch == ERR);
refresh();
noecho();
@ -220,9 +219,7 @@ void initCurses()
void shutdownCurses()
{
endwin();
}
@ -282,6 +279,7 @@ void DisplayCursesInfo(download_t * download )
int i = 0;
int line = 1;
int secs_left;
// erase();
refresh();
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);

View File

@ -194,7 +194,6 @@ ms (const char *msg, void *cb_data)
int
open_new_dl_win(urlinfo * url_data, boolean ftpsearch)
{
dl_win = new DL_Window(url_data);
dl_win->dl_start(rt.num_connections, ftpsearch);
@ -221,6 +220,7 @@ main (int argc, char **argv)
int c;
int ret;
char *opt_file = NULL;
proz_init(argc, argv); //init libprozilla
set_defaults(); //set some reasonable defaults
load_prefs(); //load values from the config file
@ -234,18 +234,23 @@ main (int argc, char **argv)
case 'L':
license();
exit(0);
case 'h':
help();
exit(0);
case 'V':
version();
exit(0);
case 'r':
rt.resume_mode = RESUME;
break;
case 'f':
rt.force_mode = TRUE;
break;
case 'k':
if (setargval(optarg, &rt.num_connections) != 1)
{
@ -263,6 +268,7 @@ main (int argc, char **argv)
}
break;
case 't':
if (setargval(optarg, &rt.max_attempts) != 1)
{
@ -273,28 +279,33 @@ main (int argc, char **argv)
exit(0);
}
break;
case 'n':
/*
* Don't use ~/.netrc"
*/
rt.use_netrc = FALSE;
break;
case 'O':
/*
* Output file name
*/
opt_file = kstrdup(optarg);
break;
case 'P':
/*
* Save the downloaded file to DIR
*/
rt.output_dir = kstrdup(optarg);
break;
case '?':
help();
exit(0);
break;
case '1':
rt.num_connections = 1;
break;
@ -314,6 +325,7 @@ main (int argc, char **argv)
*/
rt.ftp_use_pasv = FALSE;
break;
case 130:
/*
* retry-delay option
@ -327,6 +339,7 @@ main (int argc, char **argv)
exit(0);
}
break;
case 131:
/*--timout option */
if (setargval(optarg, &rt.itimeout) != 1)
@ -338,6 +351,7 @@ main (int argc, char **argv)
exit(0);
}
break;
case 132:
/* --no-getch option */
rt.dont_prompt = TRUE;
@ -382,6 +396,7 @@ main (int argc, char **argv)
}
break;
case 137:
/* --pao option */
if (setargval(optarg, &rt.max_simul_pings) != 1)
@ -419,6 +434,7 @@ main (int argc, char **argv)
}
break;
case 139:
/* --max-bps */
if (setlongargval(optarg, &rt.max_bps_per_dl) != 1)
@ -430,9 +446,11 @@ main (int argc, char **argv)
exit(0);
}
break;
case 140:
rt.display_mode = DISP_STDOUT;
break;
case 141:
/* --min-size */
if (setlongargval(optarg, &rt.min_search_size) != 1)
@ -541,17 +559,14 @@ main (int argc, char **argv)
}
shutdown();
}
void shutdown(void)
{
cleanuprt();
if (rt.display_mode == DISP_CURSES)
shutdownCurses();
proz_shutdown();
}

View File

@ -29,7 +29,6 @@ char *kstrdup(const char *s)
// die("Not enough memory to continue: strdup failed");
}
return s1;
}
/* Extracts a numurical argument from a option,
when it has been specified for example as -l=3 or, -l3
@ -44,23 +43,24 @@ int setargval(char *optstr, int *num)
{
*num = atoi(optstr + 1);
return 1;
} else
}
else
{
return 0;
}
} else
}
else
{
if (is_number(optstr) == 1)
{
*num = atoi(optstr);
return 1;
} else
}
else
{
return 0;
}
}
}
int setlongargval(char *optstr, long *num)
@ -71,23 +71,24 @@ int setlongargval(char *optstr, long *num)
{
*num = atol(optstr + 1);
return 1;
} else
}
else
{
return 0;
}
} else
}
else
{
if (is_number(optstr) == 1)
{
*num = atol(optstr);
return 1;
} else
}
else
{
return 0;
}
}
}
void delay_ms(int ms)

View File

@ -107,11 +107,11 @@ prefopt_t pref_opts[] = {
void set_num_threads(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.num_connections);
} else
}
else
{
rt.num_connections = atoi(val);
if (rt.num_connections <= 0 || rt.num_connections > 30)
@ -125,7 +125,8 @@ void set_max_attempts(int i, const char *const val, FILE * const fp)
if (fp != NULL)
{
fprintf(fp, "%d", rt.max_attempts);
} else
}
else
{
rt.max_attempts = atoi(val);
if (rt.max_attempts < 0)
@ -138,7 +139,8 @@ void set_retry_delay(int i, const char *const val, FILE * const fp)
if (fp != NULL)
{
fprintf(fp, "%d", rt.retry_delay);
} else
}
else
{
rt.retry_delay = atoi(val);
if (rt.retry_delay < 0)
@ -152,7 +154,8 @@ void set_conn_timeout(int i, const char *const val, FILE * const fp)
if (fp != NULL)
{
fprintf(fp, "%d", (int)rt.timeout.tv_sec);
} else
}
else
{
rt.timeout.tv_sec = atoi(val);
rt.timeout.tv_usec = 0;
@ -168,37 +171,36 @@ void set_max_bps_per_dl(int i, const char *const val, FILE * const fp)
if (fp != NULL)
{
fprintf(fp, "%d", (int)rt.max_bps_per_dl);
} else
}
else
{
rt.max_bps_per_dl = atoi(val);
if (rt.max_bps_per_dl < 0)
rt.max_bps_per_dl = 0;
}
}
void set_use_pasv(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.ftp_use_pasv);
} else
}
else
{
rt.ftp_use_pasv = atoi(val);
}
}
void set_debug_mode(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.debug_mode);
} else
}
else
{
rt.debug_mode = atoi(val);
}
@ -206,11 +208,11 @@ void set_debug_mode(int i, const char *const val, FILE * const fp)
void set_libdebug_mode(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.libdebug_mode);
} else
}
else
{
rt.libdebug_mode = atoi(val);
}
@ -218,11 +220,11 @@ void set_libdebug_mode(int i, const char *const val, FILE * const fp)
void set_http_no_cache(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.http_no_cache);
} else
}
else
{
rt.http_no_cache = atoi(val);
}
@ -233,18 +235,17 @@ void set_output_dir(int i, const char *const val, FILE * const fp)
if (fp != NULL)
{
fprintf(fp, "%s", rt.output_dir);
} else
}
else
{
free(rt.output_dir);
rt.output_dir = strdup(val);
}
}
void set_http_proxy(int i, const char *const val, FILE * const fp)
{
uerr_t err;
urlinfo url_data;
@ -252,7 +253,8 @@ void set_http_proxy(int i, const char *const val, FILE * const fp)
{
fprintf(fp, "%s:%d", rt.http_proxy->proxy_url.host,
rt.http_proxy->proxy_url.port);
} else
}
else
{
err = proz_parse_url(val, &url_data, 0);
if (err != URLOK)
@ -267,11 +269,11 @@ void set_http_proxy(int i, const char *const val, FILE * const fp)
void set_http_proxy_username(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%s", rt.http_proxy->username);
} else
}
else
{
free(rt.http_proxy->username);
rt.http_proxy->username = strdup(val);
@ -282,11 +284,11 @@ void set_http_proxy_username(int i, const char *const val, FILE * const fp)
void set_http_proxy_passwd(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%s", rt.http_proxy->passwd);
} else
}
else
{
free(rt.http_proxy->passwd);
rt.http_proxy->passwd = strdup(val);
@ -296,11 +298,11 @@ void set_http_proxy_passwd(int i, const char *const val, FILE * const fp)
void set_http_proxy_type(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", (int)rt.http_proxy->type);
} else
}
else
{
rt.http_proxy->type = (proxy_type)atoi(val);
}
@ -310,11 +312,11 @@ void set_http_proxy_type(int i, const char *const val, FILE * const fp)
void set_http_use_proxy(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.use_http_proxy);
} else
}
else
{
rt.use_http_proxy = atoi(val);
}
@ -325,7 +327,6 @@ void set_http_use_proxy(int i, const char *const val, FILE * const fp)
void set_ftp_proxy(int i, const char *const val, FILE * const fp)
{
uerr_t err;
urlinfo url_data;
@ -333,7 +334,8 @@ void set_ftp_proxy(int i, const char *const val, FILE * const fp)
{
fprintf(fp, "%s:%d", rt.ftp_proxy->proxy_url.host,
rt.ftp_proxy->proxy_url.port);
} else
}
else
{
err = proz_parse_url(val, &url_data, 0);
if (err != URLOK)
@ -348,11 +350,11 @@ void set_ftp_proxy(int i, const char *const val, FILE * const fp)
void set_ftp_proxy_username(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%s", rt.ftp_proxy->username);
} else
}
else
{
free(rt.ftp_proxy->username);
rt.ftp_proxy->username = strdup(val);
@ -362,11 +364,11 @@ void set_ftp_proxy_username(int i, const char *const val, FILE * const fp)
void set_ftp_proxy_passwd(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%s", rt.ftp_proxy->passwd);
} else
}
else
{
free(rt.ftp_proxy->passwd);
rt.ftp_proxy->passwd = strdup(val);
@ -375,11 +377,11 @@ void set_ftp_proxy_passwd(int i, const char *const val, FILE * const fp)
void set_ftp_proxy_type(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", (int)rt.ftp_proxy->type);
} else
}
else
{
rt.ftp_proxy->type = (proxy_type)atoi(val);
}
@ -387,11 +389,11 @@ void set_ftp_proxy_type(int i, const char *const val, FILE * const fp)
void set_ftp_use_proxy(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.use_ftp_proxy);
} else
}
else
{
rt.use_ftp_proxy = atoi(val);
}
@ -400,11 +402,11 @@ void set_ftp_use_proxy(int i, const char *const val, FILE * const fp)
void set_mirrors_req(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.ftps_mirror_req_n);
} else
}
else
{
rt.ftps_mirror_req_n = atoi(val);
if (rt.ftps_mirror_req_n <= 0 || rt.ftps_mirror_req_n > 1000)
@ -414,11 +416,11 @@ void set_mirrors_req(int i, const char *const val, FILE * const fp)
void set_max_simul_pings(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.max_simul_pings);
} else
}
else
{
rt.max_simul_pings = atoi(val);
if (rt.max_simul_pings <= 0 || rt.max_simul_pings > 30)
@ -430,11 +432,11 @@ void set_max_simul_pings(int i, const char *const val, FILE * const fp)
void set_max_ping_wait(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.max_ping_wait);
} else
}
else
{
rt.max_ping_wait = atoi(val);
if (rt.max_ping_wait <= 0 || rt.max_ping_wait > 30)
@ -445,15 +447,14 @@ void set_max_ping_wait(int i, const char *const val, FILE * const fp)
void set_use_ftpsearch(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.ftp_search);
} else
}
else
{
rt.ftp_search = atoi(val);
}
}
void set_ftpsearch_server_id(int i, const char *const val, FILE * const fp)
@ -461,24 +462,24 @@ void set_ftpsearch_server_id(int i, const char *const val, FILE * const fp)
if (fp != NULL)
{
fprintf(fp, "%d", rt.ftpsearch_server_id);
} else
}
else
{
rt.ftpsearch_server_id = atoi(val);
if (rt.ftpsearch_server_id < 0)
rt.ftpsearch_server_id = 0;
else if (rt.ftpsearch_server_id > 1)
rt.ftpsearch_server_id = 1;
}
}
void set_display_mode(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%d", rt.display_mode);
} else
}
else
{
rt.display_mode = atoi(val);
}
@ -486,11 +487,11 @@ void set_display_mode(int i, const char *const val, FILE * const fp)
void set_search_size(int i, const char *const val, FILE * const fp)
{
if (fp != NULL)
{
fprintf(fp, "%ld", rt.min_search_size);
} else
}
else
{
rt.min_search_size = atoi(val);
}
@ -537,7 +538,6 @@ void load_prefs()
if ((fp = fopen(config_fname, "rt")) == NULL)
{
if (errno == ENOENT) /*Create the file then if it doesnt exist */
{
save_prefs();