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. */ /* Common #includes and #defines. */
/* $Id: common.h,v 1.7 2001/10/27 23:20:24 kalum Exp $ */ /* $Id$ */
#ifndef COMMON_H #ifndef COMMON_H
@@ -170,10 +170,10 @@ typedef int boolean;
/* Gettext */ /* Gettext */
#include <libintl.h> #include <libintl.h>
#define _(String) dgettext (PACKAGE, String) #define _(String) dgettext(PACKAGE, String)
#define gettext_noop(String) (String) #define gettext_noop(String) (String)
#ifndef HAVE_GNOME #ifndef HAVE_GNOME
#define N_(String) gettext_noop (String) #define N_(String) gettext_noop(String)
#endif #endif
/* Gettext */ /* Gettext */

View File

@@ -40,7 +40,7 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
extern int h_errno; extern int h_errno;
int opt; int opt;
struct timeval timeout; struct timeval timeout;
struct addrinfo hints, *res=NULL; struct addrinfo hints, *res = NULL;
int error; int error;
@@ -98,7 +98,8 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
if (errno == EINPROGRESS) if (errno == EINPROGRESS)
errno = ETIMEDOUT; errno = ETIMEDOUT;
} else if (status == 0) }
else if (status == 0)
errno = ETIMEDOUT, status = -1; errno = ETIMEDOUT, status = -1;
} }
@@ -110,12 +111,14 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
{ {
freeaddrinfo(res); freeaddrinfo(res);
return CONREFUSED; return CONREFUSED;
} else }
else
{ {
freeaddrinfo(res); freeaddrinfo(res);
return CONERROR; return CONERROR;
} }
} else }
else
{ {
flags = fcntl(*sock, F_GETFL, 0); flags = fcntl(*sock, F_GETFL, 0);
@@ -129,7 +132,7 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
* in /proc/sys/net/ipv4/tcp_* files. */ * in /proc/sys/net/ipv4/tcp_* files. */
opt = 1; opt = 1;
setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE, setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE,
(char *) &opt, (int) sizeof(opt)); (char *)&opt, (int)sizeof(opt));
freeaddrinfo(res); freeaddrinfo(res);
@@ -148,13 +151,13 @@ uerr_t bind_socket(int *sockfd)
return CONSOCKERR; return CONSOCKERR;
/* Fill in the structure fields for binding. */ /* Fill in the structure fields for binding. */
memset((void *) &serv_addr, 0, sizeof(serv_addr)); memset((void *)&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(0); /* Let the system choose. */ serv_addr.sin_port = htons(0); /* Let the system choose. */
/* Bind the address to the socket. */ /* Bind the address to the socket. */
if (bind(*sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) if (bind(*sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{ {
perror("bind"); perror("bind");
close(*sockfd); close(*sockfd);
@@ -186,7 +189,7 @@ int select_fd(int fd, struct timeval *timeout, int writep)
FD_SET(fd, &exceptfds); FD_SET(fd, &exceptfds);
memcpy(&to, timeout, sizeof(struct timeval)); memcpy(&to, timeout, sizeof(struct timeval));
return (select(fd + 1, writep ? NULL : &fds, writep ? &fds : NULL, return(select(fd + 1, writep ? NULL : &fds, writep ? &fds : NULL,
&exceptfds, &to)); &exceptfds, &to));
} }
@@ -209,8 +212,7 @@ int krecv(int sock, char *buffer, int size, int flags,
do do
{ {
ret = select_fd(sock, timeout, 0); ret = select_fd(sock, timeout, 0);
} } while ((ret == -1) && (errno == EINTR));
while ((ret == -1) && (errno == EINTR));
if (ret <= 0) if (ret <= 0)
@@ -226,8 +228,7 @@ int krecv(int sock, char *buffer, int size, int flags,
} }
ret = recv(sock, buffer, size, flags); ret = recv(sock, buffer, size, flags);
} } while ((ret == -1) && (errno == EINTR));
while ((ret == -1) && (errno == EINTR));
return ret; return ret;
} }
@@ -254,8 +255,7 @@ int ksend(int sock, char *buffer, int size, int flags,
do do
{ {
ret = select_fd(sock, timeout, 1); ret = select_fd(sock, timeout, 1);
} } while ((ret == -1) && (errno == EINTR));
while ((ret == -1) && (errno == EINTR));
if (ret <= 0) if (ret <= 0)
{ {
@@ -266,8 +266,7 @@ int ksend(int sock, char *buffer, int size, int flags,
} }
} }
ret = send(sock, buffer, size, flags); ret = send(sock, buffer, size, flags);
} } while ((ret == -1) && (errno == EINTR));
while ((ret == -1) && (errno == EINTR));
if (ret <= 0) if (ret <= 0)
break; break;
@@ -287,7 +286,7 @@ uerr_t accept_connection(int listen_sock, int *data_sock)
socklen_t clilen = sizeof(cli_addr); socklen_t clilen = sizeof(cli_addr);
int sockfd; int sockfd;
sockfd = accept(listen_sock, (struct sockaddr *) &cli_addr, &clilen); sockfd = accept(listen_sock, (struct sockaddr *)&cli_addr, &clilen);
if (sockfd < 0) if (sockfd < 0)
{ {
perror("accept"); perror("accept");

View File

@@ -19,7 +19,7 @@
/* Connection routines. */ /* Connection routines. */
/* $Id: connect.h,v 1.17 2001/05/09 22:58:00 kalum Exp $ */ /* $Id$ */
#ifndef CONNECT_H #ifndef CONNECT_H
@@ -34,18 +34,18 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
uerr_t connect_to_server(int *sock, const char *name, int port, uerr_t connect_to_server(int *sock, const char *name, int port,
struct timeval *timeout); struct timeval *timeout);
uerr_t bind_socket(int *sockfd); uerr_t bind_socket(int *sockfd);
int select_fd(int fd, struct timeval *timeout, int writep); int select_fd(int fd, struct timeval *timeout, int writep);
int krecv(int sock, char *buffer, int size, int flags, int krecv(int sock, char *buffer, int size, int flags,
struct timeval *timeout); struct timeval *timeout);
int ksend(int sock, char *buffer, int size, int flags, int ksend(int sock, char *buffer, int size, int flags,
struct timeval *timeout); struct timeval *timeout);
uerr_t accept_connection(int listen_sock, int *data_sock); uerr_t accept_connection(int listen_sock, int *data_sock);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -19,7 +19,7 @@
/* Several connection-related routines. */ /* Several connection-related routines. */
/* $Id: connection.c,v 1.48 2005/09/19 16:18:02 kalum Exp $ */ /* $Id$ */
#include "common.h" #include "common.h"
@@ -59,8 +59,7 @@ void done_with_response(connection_t * connection)
p = p1; p = p1;
p1 = p->next; p1 = p->next;
kfree(p); kfree(p);
} } while (p1 != 0);
while (p1 != 0);
connection->serv_ret_lines = 0; connection->serv_ret_lines = 0;
} }
@@ -69,14 +68,14 @@ void done_with_response(connection_t * connection)
Initialises the connection and sets it with values from the runtime struct. Initialises the connection and sets it with values from the runtime struct.
******************************************************************************/ ******************************************************************************/
connection_t * proz_connection_init(urlinfo *url,pthread_mutex_t * mutex) connection_t * proz_connection_init(urlinfo *url, pthread_mutex_t * mutex)
{ {
connection_t * connection = kmalloc(sizeof(connection_t));
connection_t * connection=kmalloc(sizeof(connection_t));
memset(connection, 0, sizeof(connection_t)); memset(connection, 0, sizeof(connection_t));
/* memcpy(&connection->u, url, sizeof(urlinfo));*/ /* memcpy(&connection->u, url, sizeof(urlinfo));*/
if(url) if (url)
memcpy(&connection->u, memcpy(&connection->u,
proz_copy_url(url), proz_copy_url(url),
sizeof(urlinfo)); sizeof(urlinfo));
@@ -154,7 +153,7 @@ void connection_change_status(connection_t * connection, dl_status status)
(which should be already setup) till a EOF is reached or (which should be already setup) till a EOF is reached or
the server closes the connection, in which case there is no way to know the server closes the connection, in which case there is no way to know
whether we got the complete file. whether we got the complete file.
*/ */
uerr_t connection_retr_fsize_not_known(connection_t * connection, uerr_t connection_retr_fsize_not_known(connection_t * connection,
char *read_buffer, char *read_buffer,
@@ -191,8 +190,7 @@ uerr_t connection_retr_fsize_not_known(connection_t * connection,
connection_calc_ratebps(connection); connection_calc_ratebps(connection);
connection_throttle_bps(connection); connection_throttle_bps(connection);
} }
} } while (bytes_read > 0);
while (bytes_read > 0);
if (bytes_read == -1) if (bytes_read == -1)
{ {
@@ -221,7 +219,7 @@ uerr_t connection_retr_fsize_not_known(connection_t * connection,
Now since we explicitly know how much bytes to get we can do so, and is the server Now since we explicitly know how much bytes to get we can do so, and is the server
closes the connection prematurely we know that has hapenned (because it hasn't supplied closes the connection prematurely we know that has hapenned (because it hasn't supplied
the required number of bytes) and return a READERR. the required number of bytes) and return a READERR.
*/ */
uerr_t connection_retr_fsize_known(connection_t * connection, uerr_t connection_retr_fsize_known(connection_t * connection,
char *read_buffer, int read_buffer_size) char *read_buffer, int read_buffer_size)
{ {
@@ -267,10 +265,8 @@ uerr_t connection_retr_fsize_known(connection_t * connection,
if (bytes_read > 0) if (bytes_read > 0)
{ {
if (write_data_with_lock(connection, read_buffer, sizeof(char), bytes_read) < bytes_read) if (write_data_with_lock(connection, read_buffer, sizeof(char), bytes_read) < bytes_read)
{ {
proz_debug(_("write failed")); proz_debug(_("write failed"));
connection_show_message(connection, connection_show_message(connection,
_ _
@@ -302,19 +298,16 @@ uerr_t connection_retr_fsize_known(connection_t * connection,
/* This function modifies a single connections download start and /* This function modifies a single connections download start and
end info it returns 1 on sucess and -1 on error. end info it returns 1 on sucess and -1 on error.
*/ */
int connection_load_resume_info(connection_t * connection) int connection_load_resume_info(connection_t * connection)
{ {
if (connection->remote_startpos - connection->orig_remote_startpos != connection->remote_bytes_received)
if(connection->remote_startpos-connection->orig_remote_startpos!=connection->remote_bytes_received)
{ {
proz_debug("connection->remote start pos before loading %ld", connection->remote_startpos); proz_debug("connection->remote start pos before loading %ld", connection->remote_startpos);
//connection->remote_startpos +=connection->remote_bytes_received; //connection->remote_startpos +=connection->remote_bytes_received;
connection->remote_startpos +=(connection->remote_bytes_received-(connection->remote_startpos-connection->orig_remote_startpos)); connection->remote_startpos += (connection->remote_bytes_received - (connection->remote_startpos - connection->orig_remote_startpos));
proz_debug("connection->remote start pos after loading %ld", connection->remote_startpos); proz_debug("connection->remote start pos after 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 proz_connection_get_status(connection_t * connection)
{ {
dl_status status; dl_status status;
pthread_mutex_lock(connection->status_change_mutex); pthread_mutex_lock(connection->status_change_mutex);
status = connection->status; status = connection->status;
pthread_mutex_unlock(connection->status_change_mutex); pthread_mutex_unlock(connection->status_change_mutex);
@@ -335,47 +329,49 @@ dl_status proz_connection_get_status(connection_t * connection)
char *proz_connection_get_status_string(connection_t * connection) char *proz_connection_get_status_string(connection_t * connection)
{ {
dl_status status; dl_status status;
pthread_mutex_lock(connection->status_change_mutex); pthread_mutex_lock(connection->status_change_mutex);
status = connection->status; status = connection->status;
pthread_mutex_unlock(connection->status_change_mutex); pthread_mutex_unlock(connection->status_change_mutex);
switch (connection->status) switch (connection->status)
{ {
case IDLE: case IDLE:
return (_("Idle")); return(_("Idle"));
case CONNECTING: case CONNECTING:
return (_("Connecting")); return(_("Connecting"));
case LOGGININ: case LOGGININ:
return (_("Logging in")); return(_("Logging in"));
case DOWNLOADING: case DOWNLOADING:
return (_("Downloading")); return(_("Downloading"));
break; break;
case COMPLETED: case COMPLETED:
return (_("Completed")); return(_("Completed"));
case LOGINFAIL: case LOGINFAIL:
return (_("Login Denied")); return(_("Login Denied"));
case CONREJECT: case CONREJECT:
return (_("Connect Refused")); return(_("Connect Refused"));
case REMOTEFATAL: case REMOTEFATAL:
return (_("Remote Fatal")); return(_("Remote Fatal"));
case LOCALFATAL: case LOCALFATAL:
return (_("Local Fatal")); return(_("Local Fatal"));
case TIMEDOUT: case TIMEDOUT:
return (_("Timed Out")); return(_("Timed Out"));
case MAXTRYS: case MAXTRYS:
return (_("Max attempts reached")); return(_("Max attempts reached"));
default: default:
return (_("Unkown Status!")); return(_("Unkown Status!"));
} }
} }
@@ -412,19 +408,19 @@ off_t proz_connection_get_total_bytes_got(connection_t * connection)
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
return ret; return ret;
} }
/***************************************************************************** /*****************************************************************************
Returns the total number of bytes that has being got from the server Returns the total number of bytes that has being got from the server
by this connection. by this connection.
******************************************************************************/ ******************************************************************************/
off_t proz_connection_get_total_remote_bytes_got(connection_t * connection) off_t proz_connection_get_total_remote_bytes_got(connection_t * connection)
{ {
off_t ret; off_t ret;
pthread_mutex_lock(&connection->access_mutex); pthread_mutex_lock(&connection->access_mutex);
ret = (connection->remote_bytes_received ret = (connection->remote_bytes_received
- (connection->remote_startpos-connection->orig_remote_startpos)); - (connection->remote_startpos - connection->orig_remote_startpos));
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
//proz_debug("CONNECTION TOTAL REMOTE BYTES GOT =%lld", ret); //proz_debug("CONNECTION TOTAL REMOTE BYTES GOT =%lld", ret);
return ret; return ret;
@@ -436,18 +432,17 @@ void proz_get_url_info_loop(connection_t * connection, pthread_t *thread)
assert(thread); assert(thread);
connection->running = TRUE; connection->running = TRUE;
pthread_create(thread, NULL, pthread_create(thread, NULL,
(void *(*)(void *)) get_url_info_loop, (void *(*)(void *))get_url_info_loop,
(void *) connection); (void *)connection);
} }
/************************************************************************ /************************************************************************
This Fucntion will retreive info about the given url in the connection, This Fucntion will retreive info about the given url in the connection,
handling conditions like redirection from http to ftp etc handling conditions like redirection from http to ftp etc
*************************************************************************/ *************************************************************************/
void get_url_info_loop(connection_t * connection) void get_url_info_loop(connection_t * connection)
{ {
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
/*TODO Should we try to make it broadcast a condition to the other threads? */ /*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: case URLHTTP:
connection->err = http_get_url_info_loop(connection); connection->err = http_get_url_info_loop(connection);
break; break;
case URLFTP: case URLFTP:
connection->err = ftp_get_url_info_loop(connection); connection->err = ftp_get_url_info_loop(connection);
break; break;
default: default:
proz_die(_("Error: unsupported protocol")); proz_die(_("Error: unsupported protocol"));
} }
@@ -473,7 +470,7 @@ void get_url_info_loop(connection_t * connection)
{ {
char *constructed_newloc; char *constructed_newloc;
char *referer; char *referer;
referer=kstrdup(connection->u.url); referer = kstrdup(connection->u.url);
/*DONE : handle relative urls too */ /*DONE : handle relative urls too */
constructed_newloc = constructed_newloc =
uri_merge(connection->u.url, connection->hs.newloc); uri_merge(connection->u.url, connection->hs.newloc);
@@ -498,16 +495,15 @@ void get_url_info_loop(connection_t * connection)
kfree(constructed_newloc); kfree(constructed_newloc);
connection->err = HERR; connection->err = HERR;
return; return;
} else }
else
connection_show_message(connection, _("Redirected to => %s"), connection_show_message(connection, _("Redirected to => %s"),
constructed_newloc); constructed_newloc);
connection->u.referer=referer; connection->u.referer = referer;
kfree(constructed_newloc); kfree(constructed_newloc);
connection->err = NEWLOCATION; connection->err = NEWLOCATION;
} }
} while (connection->err == NEWLOCATION);
}
while (connection->err == NEWLOCATION);
return; return;
} }
@@ -536,15 +532,15 @@ void connection_calc_ratebps(connection_t * connection)
if (connection->time_begin.tv_sec == 0 if (connection->time_begin.tv_sec == 0
&& connection->time_begin.tv_usec == 0) && connection->time_begin.tv_usec == 0)
{ {
connection->rate_bps = 0; connection->rate_bps = 0;
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
return; return;
} else }
else
{ {
gettimeofday(&tv_cur, NULL); gettimeofday(&tv_cur, NULL);
proz_timeval_subtract(&tv_diff, &tv_cur, &(connection->time_begin)); proz_timeval_subtract(&tv_diff, &tv_cur, &(connection->time_begin));
diff_us = ((float) tv_diff.tv_sec * 10e5) + tv_diff.tv_usec; diff_us = ((float)tv_diff.tv_sec * 10e5) + tv_diff.tv_usec;
/* if (diff_us == 0) */ /* if (diff_us == 0) */
/* { */ /* { */
@@ -556,7 +552,7 @@ void connection_calc_ratebps(connection_t * connection)
/* - (connection->remote_startpos-connection->orig_remote_startpos)) * 10e5 / diff_us); */ /* - (connection->remote_startpos-connection->orig_remote_startpos)) * 10e5 / diff_us); */
/* } */ /* } */
if (diff_us <100000) if (diff_us < 100000)
{ {
connection->rate_bps = 0; connection->rate_bps = 0;
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
@@ -564,8 +560,8 @@ void connection_calc_ratebps(connection_t * connection)
} }
else else
connection->rate_bps = connection->rate_bps =
((float) (connection->remote_bytes_received ((float)(connection->remote_bytes_received
- (connection->remote_startpos-connection->orig_remote_startpos)) * 10e5 / diff_us); - (connection->remote_startpos - connection->orig_remote_startpos)) * 10e5 / diff_us);
} }
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
@@ -575,7 +571,6 @@ void connection_calc_ratebps(connection_t * connection)
void connection_throttle_bps(connection_t * connection) void connection_throttle_bps(connection_t * connection)
{ {
struct timeval tv_cur; struct timeval tv_cur;
struct timeval tv_diff; struct timeval tv_diff;
float diff_us; float diff_us;
@@ -605,7 +600,7 @@ void connection_throttle_bps(connection_t * connection)
gettimeofday(&tv_cur, NULL); gettimeofday(&tv_cur, NULL);
proz_timeval_subtract(&tv_diff, &tv_cur, &(connection->time_begin)); proz_timeval_subtract(&tv_diff, &tv_cur, &(connection->time_begin));
diff_us = ((float) tv_diff.tv_sec * 10e5) + tv_diff.tv_usec; diff_us = ((float)tv_diff.tv_sec * 10e5) + tv_diff.tv_usec;
if (diff_us == 0) if (diff_us == 0)
{ {
@@ -616,7 +611,7 @@ void connection_throttle_bps(connection_t * connection)
wtime = wtime =
10e5 * (connection->remote_bytes_received 10e5 * (connection->remote_bytes_received
- (connection->remote_startpos-connection->orig_remote_startpos)) / - (connection->remote_startpos - connection->orig_remote_startpos)) /
connection->max_allowed_bps; connection->max_allowed_bps;
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
@@ -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"); */ ("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); proz_debug("delaymaxlimit %ld sec\n", tv_delay.tv_usec);
} else }
else
{ {
tv_delay.tv_usec = (wtime - diff_us); tv_delay.tv_usec = (wtime - diff_us);
//#warning "comment out the following line before releasing the code base" //#warning "comment out the following line before releasing the code base"
@@ -661,11 +657,10 @@ void connection_throttle_bps(connection_t * connection)
tv_delay.tv_sec = tv_delay.tv_usec / 1000000; tv_delay.tv_sec = tv_delay.tv_usec / 1000000;
tv_delay.tv_usec = tv_delay.tv_usec % 1000000; tv_delay.tv_usec = tv_delay.tv_usec % 1000000;
if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &tv_delay) < 0) if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv_delay) < 0)
{ {
proz_debug("Unable to throttle Bandwith\n"); 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 proz_connection_running(connection_t * connection)
{ {
boolean running; boolean running;
pthread_mutex_lock(&connection->access_mutex); pthread_mutex_lock(&connection->access_mutex);
running = connection->running; running = connection->running;
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
@@ -719,11 +715,12 @@ 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 write_data_with_lock(connection_t * connection, const void *ptr, size_t size, size_t nmemb)
{ {
size_t ret; size_t ret;
flockfile(connection->fp); flockfile(connection->fp);
/*Seek appropriately......*/ /*Seek appropriately......*/
ret=fseeko(connection->fp, connection->local_startpos+connection->remote_bytes_received, SEEK_SET); ret = fseeko(connection->fp, connection->local_startpos + connection->remote_bytes_received, SEEK_SET);
ret=fwrite( ptr, size, nmemb, connection->fp); ret = fwrite(ptr, size, nmemb, connection->fp);
funlockfile(connection->fp); funlockfile(connection->fp);
return ret; return ret;

View File

@@ -19,7 +19,7 @@
/* Several connection-related routines. */ /* Several connection-related routines. */
/* $Id: connection.h,v 1.34 2005/01/11 01:49:11 sean Exp $ */ /* $Id$ */
#ifndef CONNECTION_H #ifndef CONNECTION_H
@@ -35,27 +35,27 @@
extern "C" { extern "C" {
#endif #endif
void init_response(connection_t * connection); void init_response(connection_t * connection);
void done_with_response(connection_t * connection); void done_with_response(connection_t * connection);
void connection_change_status(connection_t * connection, void connection_change_status(connection_t * connection,
dl_status status); dl_status status);
uerr_t connection_retr_fsize_not_known(connection_t * connection, uerr_t connection_retr_fsize_not_known(connection_t * connection,
char *read_buffer, char *read_buffer,
int read_buffer_size); int read_buffer_size);
uerr_t connection_retr_fsize_known(connection_t * connection, uerr_t connection_retr_fsize_known(connection_t * connection,
char *read_buffer, char *read_buffer,
int read_buffer_size); int read_buffer_size);
int connection_load_resume_info(connection_t * connection); int connection_load_resume_info(connection_t * connection);
void connection_show_message(connection_t * connection, void connection_show_message(connection_t * connection,
const char *format, ...); const char *format, ...);
void connection_calc_ratebps(connection_t * connection); void connection_calc_ratebps(connection_t * connection);
void connection_throttle_bps(connection_t * connection); void connection_throttle_bps(connection_t * connection);
void get_url_info_loop(connection_t * connection); void get_url_info_loop(connection_t * connection);
size_t write_data_with_lock(connection_t *connection, const void *ptr, size_t size, size_t nmemb); size_t write_data_with_lock(connection_t *connection, const void *ptr, size_t size, size_t nmemb);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -19,7 +19,7 @@
/* Debugging routines. */ /* Debugging routines. */
/* $Id: debug.c,v 1.20 2001/08/17 21:53:39 kalum Exp $ */ /* $Id$ */
#include "common.h" #include "common.h"
@@ -32,7 +32,7 @@ static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
/****************************************************************************** /******************************************************************************
Initialises the debug system, deletes any prior debug.log file if present Initialises the debug system, deletes any prior debug.log file if present
******************************************************************************/ ******************************************************************************/
void debug_init() void debug_init()
{ {
@@ -43,8 +43,8 @@ void debug_init()
void proz_debug_delete_log() void proz_debug_delete_log()
{ {
char logfile_name[PATH_MAX]; char logfile_name[PATH_MAX];
snprintf(logfile_name, PATH_MAX, "%s/debug.log", libprozrtinfo.log_dir); 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 message[MAX_MSG_SIZE + 1 + 1];
char logfile_name[PATH_MAX]; char logfile_name[PATH_MAX];
snprintf(logfile_name, PATH_MAX, "%s/debug.log", libprozrtinfo.log_dir); snprintf(logfile_name, PATH_MAX, "%s/debug.log", libprozrtinfo.log_dir);
@@ -81,7 +82,7 @@ void proz_debug(const char *format, ...)
if (libprozrtinfo.debug_mode == TRUE) if (libprozrtinfo.debug_mode == TRUE)
{ {
va_start(args, format); va_start(args, format);
vsnprintf((char *) &message, MAX_MSG_SIZE, format, args); vsnprintf((char *)&message, MAX_MSG_SIZE, format, args);
va_end(args); va_end(args);
/* Remove all newlines from the end of the string. */ /* Remove all newlines from the end of the string. */

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -19,7 +19,7 @@
/* Download routines. */ /* Download routines. */
/* $Id: download.h,v 1.25 2001/09/30 23:13:50 kalum Exp $ */ /* $Id$ */
#ifndef DOWNLOAD_H #ifndef DOWNLOAD_H
@@ -35,16 +35,16 @@
extern "C" { extern "C" {
#endif #endif
void download_show_message(download_t * download, const char *format, void download_show_message(download_t * download, const char *format,
...); ...);
int download_query_conns_status_count(download_t * download, int download_query_conns_status_count(download_t * download,
dl_status status, char *server); dl_status status, char *server);
void download_join_downloads(download_t * download); void download_join_downloads(download_t * download);
void join_downloads(download_t * download); void join_downloads(download_t * download);
void download_calc_throttle_factor(download_t * download); void download_calc_throttle_factor(download_t * download);
uerr_t download_handle_threads_ftpsearch(download_t * download); uerr_t download_handle_threads_ftpsearch(download_t * download);
uerr_t download_handle_threads_no_ftpsearch(download_t * download); uerr_t download_handle_threads_no_ftpsearch(download_t * download);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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" #include "common.h"
@@ -85,7 +85,8 @@ uerr_t proz_ftp_get_file(connection_t * connection)
err = ftp_connect_to_server(connection, err = ftp_connect_to_server(connection,
connection->ftp_proxy->proxy_url.host, connection->ftp_proxy->proxy_url.host,
connection->ftp_proxy->proxy_url.port); connection->ftp_proxy->proxy_url.port);
} else }
else
{ {
err = ftp_connect_to_server(connection, connection->u.host, err = ftp_connect_to_server(connection, connection->u.host,
connection->u.port); connection->u.port);
@@ -133,7 +134,8 @@ uerr_t proz_ftp_get_file(connection_t * connection)
if (err == FTPLOGREFUSED) if (err == FTPLOGREFUSED)
{ {
connection_change_status(connection, LOGINFAIL); connection_change_status(connection, LOGINFAIL);
} else }
else
{ {
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
} }
@@ -166,12 +168,14 @@ uerr_t proz_ftp_get_file(connection_t * connection)
connection->u.dir); connection->u.dir);
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
return err; return err;
} else }
else
{ {
proz_debug(_("CWD ok.")); proz_debug(_("CWD ok."));
done_with_response(connection); done_with_response(connection);
} }
} else }
else
proz_debug(_("CWD not needed.")); proz_debug(_("CWD not needed."));
err = ftp_setup_data_sock_1(connection, &passive_mode); err = ftp_setup_data_sock_1(connection, &passive_mode);
@@ -234,10 +238,10 @@ uerr_t proz_ftp_get_file(connection_t * connection)
/* A genuine loop ;) It willed be called by the main thread, and /* A genuine loop ;) It willed be called by the main thread, and
this will handle all possible errors itself, retrying until the number this will handle all possible errors itself, retrying until the number
of maximum tries for the connection is realised or a error occurs which of maximum tries for the connection is realised or a error occurs which
needs to be passed upwards for handling, such as LOGINFAIL needs to be passed upwards for handling, such as LOGINFAIL
*/ */
uerr_t ftp_loop(connection_t * connection) uerr_t ftp_loop(connection_t * connection)
{ {
@@ -252,7 +256,6 @@ uerr_t ftp_loop(connection_t * connection)
{ {
if (connection->attempts > 0) if (connection->attempts > 0)
{ {
if (retrying_from_loop == TRUE) if (retrying_from_loop == TRUE)
{ {
connection_show_message(connection, connection_show_message(connection,
@@ -270,7 +273,8 @@ uerr_t ftp_loop(connection_t * connection)
_ _
("Error while attemting to process download file ")); ("Error while attemting to process download file "));
} }
} else }
else
{ {
/*If we cant resume then reset the connections bytesreceived to 0 */ /*If we cant resume then reset the connections bytesreceived to 0 */
connection->remote_bytes_received = 0; connection->remote_bytes_received = 0;
@@ -279,7 +283,7 @@ uerr_t ftp_loop(connection_t * connection)
/*Push the handler which will cleanup any sockets that are left open */ /*Push the handler which will cleanup any sockets that are left open */
pthread_cleanup_push(cleanup_socks, (void *) connection); pthread_cleanup_push(cleanup_socks, (void *)connection);
connection->err = proz_ftp_get_file(connection); connection->err = proz_ftp_get_file(connection);
@@ -309,8 +313,7 @@ uerr_t ftp_loop(connection_t * connection)
break; break;
} }
retrying_from_loop = TRUE; retrying_from_loop = TRUE;
} } while ((connection->attempts < connection->max_attempts)
while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0); || connection->max_attempts == 0);
@@ -322,11 +325,10 @@ uerr_t ftp_loop(connection_t * connection)
} }
/*Return true if it is a error which can be handled within the ftp_loop, /*Return true if it is a error which can be handled within the ftp_loop,
or false if it should be passed upwards so that the main download thread can 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 */ restart it when necessary after processing other threads status too */
boolean ftp_loop_handle_error(uerr_t err) boolean ftp_loop_handle_error(uerr_t err)
{ {
proz_debug("Error encountered in ftp_loop is %d", err); proz_debug("Error encountered in ftp_loop is %d", err);
if (err == FTPNSFOD || err == FTPLOGREFUSED || err == FTPCONREFUSED if (err == FTPNSFOD || err == FTPLOGREFUSED || err == FTPCONREFUSED
|| err == FWRITEERR || err == FOPENERR || err == FTPCWDFAIL || err == FWRITEERR || err == FOPENERR || err == FTPCWDFAIL
@@ -334,5 +336,4 @@ boolean ftp_loop_handle_error(uerr_t err)
return FALSE; return FALSE;
else else
return TRUE; return TRUE;
} }

View File

@@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 #ifndef FTP_RETR_H
#define FTP_RETR_H #define FTP_RETR_H
@@ -29,10 +29,10 @@
extern "C" { extern "C" {
#endif #endif
uerr_t proz_ftp_get_file(connection_t * connection); uerr_t proz_ftp_get_file(connection_t * connection);
uerr_t ftp_loop(connection_t * connection); uerr_t ftp_loop(connection_t * connection);
boolean ftp_loop_handle_error(uerr_t err); boolean ftp_loop_handle_error(uerr_t err);
uerr_t ftp_get_file_from_http_proxy(connection_t * connection); uerr_t ftp_get_file_from_http_proxy(connection_t * connection);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -19,7 +19,7 @@
/* FTP support. */ /* FTP support. */
/* $Id: ftp.c,v 1.55 2005/09/04 00:06:50 kalum Exp $ */ /* $Id$ */
#include "common.h" #include "common.h"
@@ -44,6 +44,7 @@
static int ftp_get_return(const char *ftp_buffer) static int ftp_get_return(const char *ftp_buffer)
{ {
char code[4]; char code[4];
strncpy(code, ftp_buffer, 3); strncpy(code, ftp_buffer, 3);
code[3] = '\0'; code[3] = '\0';
return atoi(code); return atoi(code);
@@ -62,7 +63,7 @@ static uerr_t ftp_get_reply(connection_t * connection)
/* Allocate the space in the buffer for the request. */ /* Allocate the space in the buffer for the request. */
char szBuffer[FTP_BUFFER_SIZE]; char szBuffer[FTP_BUFFER_SIZE];
char *strtok_saveptr;// = (char *) alloca(FTP_BUFFER_SIZE); char *strtok_saveptr; // = (char *) alloca(FTP_BUFFER_SIZE);
memset(szBuffer, 0, FTP_BUFFER_SIZE); memset(szBuffer, 0, FTP_BUFFER_SIZE);
@@ -82,7 +83,7 @@ static uerr_t ftp_get_reply(connection_t * connection)
else else
cont = 0; cont = 0;
(void) strtok_r(szBuffer, "\r\n", &strtok_saveptr); (void)strtok_r(szBuffer, "\r\n", &strtok_saveptr);
srl = connection->serv_ret_lines = kmalloc(sizeof(response_line)); srl = connection->serv_ret_lines = kmalloc(sizeof(response_line));
srl->line = kstrdup(szBuffer); srl->line = kstrdup(szBuffer);
@@ -103,7 +104,7 @@ static uerr_t ftp_get_reply(connection_t * connection)
if ((ftp_get_return(szBuffer) == code) && (szBuffer[3] == ' ')) if ((ftp_get_return(szBuffer) == code) && (szBuffer[3] == ' '))
cont = 0; cont = 0;
(void) strtok_r(szBuffer, "\r\n", &strtok_saveptr); (void)strtok_r(szBuffer, "\r\n", &strtok_saveptr);
// proz_debug(_("Message = %s"), szBuffer); // proz_debug(_("Message = %s"), szBuffer);
srl->next = kmalloc(sizeof(response_line)); srl->next = kmalloc(sizeof(response_line));
srl = srl->next; srl = srl->next;
@@ -209,7 +210,7 @@ uerr_t ftp_get_line(connection_t * connection, char *line)
return FTPERR; return FTPERR;
/* if zero bytes were found that means the server has closed the connection*/ /* if zero bytes were found that means the server has closed the connection*/
if(ret==0) if (ret == 0)
*(szptr) = '\0'; *(szptr) = '\0';
else else
*(szptr + 1) = '\0'; *(szptr + 1) = '\0';
@@ -297,7 +298,7 @@ uerr_t ftp_list(connection_t * connection, const char *file)
if (err != FTPOK) if (err != FTPOK)
return err; return err;
if(ftp_get_return(connection->serv_ret_lines->line)==550) if (ftp_get_return(connection->serv_ret_lines->line) == 550)
{ {
return FTPNSFOD; return FTPNSFOD;
} }
@@ -361,8 +362,9 @@ uerr_t ftp_pasv(connection_t * connection, unsigned char *addr)
return FTPNOPASV; return FTPNOPASV;
/* Parse it. */ /* Parse it. */
p = (unsigned char *) connection->serv_ret_lines->line; p = (unsigned char *)connection->serv_ret_lines->line;
for (p += 4; *p && !isdigit(*p); p++); for (p += 4; *p && !isdigit(*p); p++)
;
if (!*p) if (!*p)
return FTPINVPASV; return FTPINVPASV;
@@ -469,7 +471,8 @@ uerr_t ftp_pwd(connection_t * connection, char *dir)
strcpy(dir, l); strcpy(dir, l);
*r = '"'; *r = '"';
} }
} else }
else
{ {
if ((r = strchr(connection->serv_ret_lines->line, ' ')) != NULL) if ((r = strchr(connection->serv_ret_lines->line, ' ')) != NULL)
{ {
@@ -504,10 +507,10 @@ uerr_t ftp_size(connection_t * connection, const char *file, off_t *size)
{ {
sscanf(connection->serv_ret_lines->line + 3, "%lld", size); sscanf(connection->serv_ret_lines->line + 3, "%lld", size);
return FTPOK; 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)
if(ftp_get_return(connection->serv_ret_lines->line)==550)
{ {
return FTPNSFOD; return FTPNSFOD;
} }
@@ -565,7 +568,7 @@ uerr_t ftp_get_listen_socket(connection_t * connection, int *listen_sock)
return LISTENERR; return LISTENERR;
len = sizeof(serv_addr); len = sizeof(serv_addr);
if (getsockname(sockfd, (struct sockaddr *) &serv_addr, &len) < 0) if (getsockname(sockfd, (struct sockaddr *)&serv_addr, &len) < 0)
{ {
perror("getsockname"); perror("getsockname");
close(sockfd); close(sockfd);
@@ -576,7 +579,7 @@ uerr_t ftp_get_listen_socket(connection_t * connection, int *listen_sock)
/* Get hosts info. */ /* Get hosts info. */
len = sizeof(TempAddr); len = sizeof(TempAddr);
if (getsockname(connection->ctrl_sock, (struct sockaddr *) &TempAddr, if (getsockname(connection->ctrl_sock, (struct sockaddr *)&TempAddr,
&len) < 0) &len) < 0)
{ {
perror("getsockname"); perror("getsockname");
@@ -584,11 +587,11 @@ uerr_t ftp_get_listen_socket(connection_t * connection, int *listen_sock)
return CONPORTERR; return CONPORTERR;
} }
ipaddr = (char *) &TempAddr.sin_addr; ipaddr = (char *)&TempAddr.sin_addr;
port = (char *) &serv_addr.sin_port; port = (char *)&serv_addr.sin_port;
#define UC(b) (((int)b)&0xff) #define UC(b) (((int)b) & 0xff)
sprintf(command, "PORT %d,%d,%d,%d,%d,%d\r\n", UC(ipaddr[0]), sprintf(command, "PORT %d,%d,%d,%d,%d,%d\r\n", UC(ipaddr[0]),
UC(ipaddr[1]), UC(ipaddr[2]), UC(ipaddr[3]), UC(port[0]), UC(ipaddr[1]), UC(ipaddr[2]), UC(ipaddr[3]), UC(port[0]),
@@ -624,7 +627,8 @@ uerr_t ftp_login(connection_t * connection, const char *username,
{ {
/* No proxy just direct connection. */ /* No proxy just direct connection. */
err = ftp_send_msg(connection, "USER %s\r\n", username); err = ftp_send_msg(connection, "USER %s\r\n", username);
} else }
else
{ {
switch (connection->ftp_proxy->type) 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, err = ftp_send_msg(connection, "USER %s@%s:%d\r\n", username,
connection->u.host, connection->u.port); connection->u.host, connection->u.port);
break; break;
case USERatPROXYUSERatSITE: case USERatPROXYUSERatSITE:
err = ftp_send_msg(connection, "USER %s@%s@%s:%d\r\n", username, err = ftp_send_msg(connection, "USER %s@%s@%s:%d\r\n", username,
connection->ftp_proxy->username, connection->ftp_proxy->username,
connection->u.host, connection->u.port); connection->u.host, connection->u.port);
break; break;
case USERatSITE_PROXYUSER: case USERatSITE_PROXYUSER:
err = ftp_send_msg(connection, "USER %s:%d@%s %s\r\n", username, err = ftp_send_msg(connection, "USER %s:%d@%s %s\r\n", username,
connection->u.host, connection->u.port, connection->u.host, connection->u.port,
connection->ftp_proxy->username); connection->ftp_proxy->username);
break; break;
case PROXYUSERatSITE: case PROXYUSERatSITE:
err = ftp_send_msg(connection, "USER %s@%s:%d\r\n", err = ftp_send_msg(connection, "USER %s@%s:%d\r\n",
connection->ftp_proxy->username, connection->ftp_proxy->username,
connection->u.host, connection->u.port); connection->u.host, connection->u.port);
break; break;
default: default:
/* Something else, just send PROXY USER. */ /* Something else, just send PROXY USER. */
err = ftp_send_msg(connection, "USER %s\r\n", 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, err = ftp_send_msg(connection, "USER %s@%s:%d\r\n", username,
connection->u.host, connection->u.port); connection->u.host, connection->u.port);
break; break;
case OPENSITE: case OPENSITE:
err = err =
ftp_send_msg(connection, "OPEN %s:%d\r\n", connection->u.host, ftp_send_msg(connection, "OPEN %s:%d\r\n", connection->u.host,
connection->u.port); connection->u.port);
break; break;
case SITESITE: case SITESITE:
err = err =
ftp_send_msg(connection, "SITE %s:%d\r\n", connection->u.host, ftp_send_msg(connection, "SITE %s:%d\r\n", connection->u.host,
connection->u.port); connection->u.port);
break; break;
case PROXYUSERatSITE: case PROXYUSERatSITE:
err = ftp_send_msg(connection, "USER %s\r\n", username); err = ftp_send_msg(connection, "USER %s\r\n", username);
break; break;
default: default:
/* TODO What is the default here? */ /* TODO What is the default here? */
return FTPOK; return FTPOK;
@@ -721,24 +733,29 @@ uerr_t ftp_login(connection_t * connection, const char *username,
{ {
/* No proxy just direct connection. */ /* No proxy just direct connection. */
err = ftp_send_msg(connection, "PASS %s\r\n", passwd); err = ftp_send_msg(connection, "PASS %s\r\n", passwd);
} else }
else
{ {
switch (connection->ftp_proxy->type) switch (connection->ftp_proxy->type)
{ {
case USERatSITE: case USERatSITE:
err = ftp_send_msg(connection, "PASS %s\r\n", passwd); err = ftp_send_msg(connection, "PASS %s\r\n", passwd);
break; break;
case USERatPROXYUSERatSITE: case USERatPROXYUSERatSITE:
err = ftp_send_msg(connection, "PASS %s@%s\r\n", passwd, err = ftp_send_msg(connection, "PASS %s@%s\r\n", passwd,
connection->ftp_proxy->passwd); connection->ftp_proxy->passwd);
break; break;
case USERatSITE_PROXYUSER: case USERatSITE_PROXYUSER:
err = ftp_send_msg(connection, "PASS %s\r\n", passwd); err = ftp_send_msg(connection, "PASS %s\r\n", passwd);
break; break;
case PROXYUSERatSITE: case PROXYUSERatSITE:
err = ftp_send_msg(connection, "PASS %s\r\n", err = ftp_send_msg(connection, "PASS %s\r\n",
connection->ftp_proxy->passwd); connection->ftp_proxy->passwd);
break; break;
default: default:
/* Something else we dont know about. */ /* Something else we dont know about. */
err = ftp_send_msg(connection, "PASS %s\r\n", 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; longstring buffer;
boolean size_ok; boolean size_ok;
struct ftpparse fp; struct ftpparse fp;
/* if we have to use a HTTP proxy call the routine which is defined in http.c /* if we have to use a HTTP proxy call the routine which is defined in http.c
and just return. 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_show_message(connection, _("Connected to %s"),
connection->ftp_proxy->proxy_url.host); connection->ftp_proxy->proxy_url.host);
} else }
else
{ {
connection_show_message(connection, _("Connecting to %s"), connection_show_message(connection, _("Connecting to %s"),
connection->u.host); connection->u.host);
@@ -890,7 +909,7 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
else else
{ {
int pwd_len = strlen(passwd); int pwd_len = strlen(passwd);
char *tmp_pwd = (char *) kmalloc(pwd_len + 1); char *tmp_pwd = (char *)kmalloc(pwd_len + 1);
memset(tmp_pwd, 'x', pwd_len); memset(tmp_pwd, 'x', pwd_len);
tmp_pwd[pwd_len] = 0; tmp_pwd[pwd_len] = 0;
connection_show_message(connection, connection_show_message(connection,
@@ -932,11 +951,13 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
connection->u.dir); connection->u.dir);
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
return err; return err;
} else }
else
{ {
done_with_response(connection); done_with_response(connection);
} }
} else }
else
connection_show_message(connection, _("CWD not needed")); connection_show_message(connection, _("CWD not needed"));
init_response(connection); init_response(connection);
@@ -946,7 +967,8 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
connection->resume_support = FALSE; connection->resume_support = FALSE;
connection_show_message(connection, _("REST failed")); connection_show_message(connection, _("REST failed"));
/* NOTE: removed return err; */ /* NOTE: removed return err; */
} else }
else
{ {
connection->resume_support = TRUE; connection->resume_support = TRUE;
connection_show_message(connection, _("REST ok")); 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. */ /* So connection->u.file is a directory and not a file. */
connection->file_type = DIRECTORY; connection->file_type = DIRECTORY;
return FTPOK; return FTPOK;
} else }
else
{ {
/* FIXME: The statement below is strictly not true, it could be a symlink /* 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 but for the moment lets leave this as it is, later we will perform a
LIST command and detect whether it is a symlink. */ LIST command and detect whether it is a symlink. */
@@ -993,13 +1015,15 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
} }
case FTPOK: case FTPOK:
size_ok=TRUE; size_ok = TRUE;
break; break;
case FTPSIZEFAIL: case FTPSIZEFAIL:
size_ok=FALSE; size_ok = FALSE;
break; break;
default: default:
size_ok=FALSE; size_ok = FALSE;
} }
@@ -1008,7 +1032,7 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
/* Now we additionaly will get the server to display info with the /* Now we additionaly will get the server to display info with the
list command, initially we only called the LIST command only if the list command, initially we only called the LIST command only if the
SIZE failed SIZE failed
*/ */
err = ftp_setup_data_sock_1(connection, &passive_mode); err = ftp_setup_data_sock_1(connection, &passive_mode);
if (err != FTPOK) if (err != FTPOK)
@@ -1033,7 +1057,7 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
err = ftp_list(connection, connection->u.file); err = ftp_list(connection, connection->u.file);
if (err != FTPOK) if (err != FTPOK)
{ {
if(err==FTPNSFOD) if (err == FTPNSFOD)
{ {
//If the remote server returns ftpnsfod which could be due //If the remote server returns ftpnsfod which could be due
//to the fact that the server doesnt permit the directory //to the fact that the server doesnt permit the directory
@@ -1047,7 +1071,7 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
else else
{ {
connection_show_message(connection, connection_show_message(connection,
"FTP LIST failed: Server returned %s",connection->serv_ret_lines->line ); "FTP LIST failed: Server returned %s", connection->serv_ret_lines->line);
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
return FTPOK; return FTPOK;
} }
@@ -1080,13 +1104,14 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
while ((tmp = strrchr(buffer, '\n')) || (tmp = strrchr(buffer, '\r'))) while ((tmp = strrchr(buffer, '\n')) || (tmp = strrchr(buffer, '\r')))
{ {
*tmp = 0; *tmp = 0;
}; }
;
close_sock(&connection->data_sock); close_sock(&connection->data_sock);
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
// size_rt = size_returner(buffer, strlen(buffer)); // size_rt = size_returner(buffer, strlen(buffer));
err =ftp_parse(&fp, buffer, strlen(buffer)); err = ftp_parse(&fp, buffer, strlen(buffer));
if (err != FTPPARSEOK) if (err != FTPPARSEOK)
{ {
connection_show_message(connection, connection_show_message(connection,
@@ -1094,11 +1119,11 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
("Unable to parse the line the FTP server returned:please report URL to prozilla@genesys.ro ")); ("Unable to parse the line the FTP server returned:please report URL to prozilla@genesys.ro "));
} }
if(err==FTPPARSEOK) if (err == FTPPARSEOK)
{ {
proz_debug("size returned from LIST %ld",fp.filesize); proz_debug("size returned from LIST %ld", fp.filesize);
//SEC size_rt off_t? //SEC size_rt off_t?
if(size_ok==FALSE) if (size_ok == FALSE)
{ {
proz_debug("SIZE failed, setting file size based on LIST"); proz_debug("SIZE failed, setting file size based on LIST");
connection->main_file_size = fp.filesize; connection->main_file_size = fp.filesize;
@@ -1128,7 +1153,8 @@ uerr_t ftp_setup_data_sock_1(connection_t * connection,
{ {
proz_debug(_("Server doesn't seem to support PASV")); proz_debug(_("Server doesn't seem to support PASV"));
*passive_mode = FALSE; *passive_mode = FALSE;
} else if (err == FTPOK) /* Server supports PASV. */ }
else if (err == FTPOK) /* Server supports PASV. */
{ {
char dhost[256]; char dhost[256];
unsigned short dport; unsigned short dport;
@@ -1146,11 +1172,13 @@ uerr_t ftp_setup_data_sock_1(connection_t * connection,
/* Everything seems to be ok. */ /* Everything seems to be ok. */
*passive_mode = TRUE; *passive_mode = TRUE;
} else }
else
return err; return err;
done_with_response(connection); done_with_response(connection);
} else }
else
*passive_mode = FALSE; /* Ok... Since PASV is not to be used. */ *passive_mode = FALSE; /* Ok... Since PASV is not to be used. */
if (*passive_mode == FALSE) if (*passive_mode == FALSE)
@@ -1200,17 +1228,15 @@ uerr_t ftp_get_url_info_loop(connection_t * connection)
{ {
if (connection->attempts > 0 && connection->err != NEWLOCATION) if (connection->attempts > 0 && connection->err != NEWLOCATION)
{ {
connection_show_message(connection, connection_show_message(connection,
_("Retrying attempt %d in %d seconds"), _("Retrying attempt %d in %d seconds"),
connection->attempts, connection->attempts,
connection->retry_delay.tv_sec); connection->retry_delay.tv_sec);
delay_ms(connection->retry_delay.tv_sec * 1000); delay_ms(connection->retry_delay.tv_sec * 1000);
} }
/*Push the handler which will cleanup any sockets that are left open */ /*Push the handler which will cleanup any sockets that are left open */
pthread_cleanup_push(cleanup_socks, (void *) connection); pthread_cleanup_push(cleanup_socks, (void *)connection);
connection->err = proz_ftp_get_url_info(connection); connection->err = proz_ftp_get_url_info(connection);
/*pop the handler */ /*pop the handler */
@@ -1240,9 +1266,7 @@ uerr_t ftp_get_url_info_loop(connection_t * connection)
connection_show_message(connection, proz_strerror(connection->err)); connection_show_message(connection, proz_strerror(connection->err));
break; break;
} }
} while ((connection->attempts < connection->max_attempts)
}
while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0); || connection->max_attempts == 0);

View File

@@ -19,7 +19,7 @@
/* FTP support. */ /* FTP support. */
/* $Id: ftp.h,v 1.35 2005/09/04 00:06:50 kalum Exp $ */ /* $Id$ */
#ifndef FTP_H #ifndef FTP_H
@@ -34,43 +34,43 @@
extern "C" { extern "C" {
#endif #endif
int ftp_check_msg(connection_t * connection, int len); int ftp_check_msg(connection_t * connection, int len);
int ftp_read_msg(connection_t * connection, int len); int ftp_read_msg(connection_t * connection, int len);
uerr_t ftp_send_msg(connection_t * connection, const char *format, ...); uerr_t ftp_send_msg(connection_t * connection, const char *format, ...);
uerr_t ftp_get_line(connection_t * connection, char *line); uerr_t ftp_get_line(connection_t * connection, char *line);
uerr_t ftp_ascii(connection_t * connection); uerr_t ftp_ascii(connection_t * connection);
uerr_t ftp_binary(connection_t * connection); uerr_t ftp_binary(connection_t * connection);
uerr_t ftp_port(connection_t * connection, const char *command); uerr_t ftp_port(connection_t * connection, const char *command);
uerr_t ftp_list(connection_t * connection, const char *file); uerr_t ftp_list(connection_t * connection, const char *file);
uerr_t ftp_retr(connection_t * connection, const char *file); uerr_t ftp_retr(connection_t * connection, const char *file);
uerr_t ftp_pasv(connection_t * connection, unsigned char *addr); uerr_t ftp_pasv(connection_t * connection, unsigned char *addr);
uerr_t ftp_rest(connection_t * connection, off_t bytes); uerr_t ftp_rest(connection_t * connection, off_t bytes);
uerr_t ftp_cwd(connection_t * connection, const char *dir); uerr_t ftp_cwd(connection_t * connection, const char *dir);
uerr_t ftp_pwd(connection_t * connection, char *dir); uerr_t ftp_pwd(connection_t * connection, char *dir);
uerr_t ftp_size(connection_t * connection, const char *file, off_t *size); uerr_t ftp_size(connection_t * connection, const char *file, off_t *size);
uerr_t ftp_connect_to_server(connection_t * connection, const char *name, uerr_t ftp_connect_to_server(connection_t * connection, const char *name,
int port); int port);
uerr_t ftp_get_listen_socket(connection_t * connection, uerr_t ftp_get_listen_socket(connection_t * connection,
int *listen_sock); int *listen_sock);
uerr_t ftp_login(connection_t * connection, const char *username, uerr_t ftp_login(connection_t * connection, const char *username,
const char *passwd); const char *passwd);
boolean ftp_use_proxy(connection_t * connection); boolean ftp_use_proxy(connection_t * connection);
uerr_t proz_ftp_get_url_info(connection_t * connection); uerr_t proz_ftp_get_url_info(connection_t * connection);
uerr_t ftp_setup_data_sock_1(connection_t * connection, uerr_t ftp_setup_data_sock_1(connection_t * connection,
boolean * passive_mode); boolean * passive_mode);
uerr_t ftp_setup_data_sock_2(connection_t * connection, uerr_t ftp_setup_data_sock_2(connection_t * connection,
boolean * passive_mode); boolean * passive_mode);
uerr_t ftp_get_url_info_loop(connection_t * connection); uerr_t ftp_get_url_info_loop(connection_t * connection);
uerr_t ftp_get_url_info_from_http_proxy(connection_t * connection); uerr_t ftp_get_url_info_from_http_proxy(connection_t * connection);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -28,22 +28,23 @@
/* MultiNet (some spaces removed from examples) */ /* MultiNet (some spaces removed from examples) */
/* "00README.TXT;1 2 30-DEC-1996 17:44 [SYSTEM] (RWED,RWED,RE,RE)" */ /* "00README.TXT;1 2 30-DEC-1996 17:44 [SYSTEM] (RWED,RWED,RE,RE)" */
/* "CORE.DIR;1 1 8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)" */ /* "CORE.DIR;1 1 8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)" */
/* and non-MutliNet VMS: */ /* and non-MutliNet VMS: */
/* "CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)" */ /* "CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)" */
/* MSDOS format */ /* MSDOS format */
/* 04-27-00 09:09PM <DIR> licensed */ /* 04-27-00 09:09PM <DIR> licensed */
/* 07-18-00 10:16AM <DIR> pub */ /* 07-18-00 10:16AM <DIR> pub */
/* 04-14-00 03:47PM 589 readme.htm */ /* 04-14-00 03:47PM 589 readme.htm */
long getlong(char *buf,int len) long getlong(char *buf, int len)
{ {
long u = 0; long u = 0;
while (len-- > 0) while (len-- > 0)
u = u * 10 + (*buf++ - '0'); u = u * 10 + (*buf++ - '0');
return u; return u;
@@ -66,56 +67,75 @@ long getlong(char *buf,int len)
** **
** Returns a pointer to the first word or NULL on error ** Returns a pointer to the first word or NULL on error
*/ */
char * get_nextfield (char ** pstr) char * get_nextfield(char ** pstr)
{ {
char * p = *pstr; char * p = *pstr;
char * start = NULL; char * start = NULL;
if (!pstr || !*pstr) return NULL;
while (1) { if (!pstr || !*pstr)
return NULL;
while (1)
{
/* Strip white space and other delimiters */ /* Strip white space and other delimiters */
while (*p && (isspace((int) *p) || *p==',' || *p==';' || *p=='=')) p++; while (*p && (isspace((int)*p) || *p == ',' || *p == ';' || *p == '='))
if (!*p) { p++;
if (!*p)
{
*pstr = p; *pstr = p;
return NULL; /* No field */ return NULL; /* No field */
} }
if (*p == '"') { /* quoted field */ if (*p == '"') /* quoted field */
{
start = ++p; start = ++p;
for(;*p && *p!='"'; p++) for (; *p && *p != '"'; p++)
if (*p == '\\' && *(p+1)) p++; /* Skip escaped chars */ if (*p == '\\' && *(p + 1))
break; /* kr95-10-9: needs to stop here */
} 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 */
p++; p++;
} else { /* Spool field */ /* Skip escaped chars */
break; /* kr95-10-9: needs to stop here */
}
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 */
p++;
}
else /* Spool field */
{
start = p; start = p;
while(*p && !isspace((int) *p) && *p!=',' && *p!=';' && *p!='=') while (*p && !isspace((int)*p) && *p != ',' && *p != ';' && *p != '=')
p++; p++;
break; /* Got it */ break; /* Got it */
} }
} }
if (*p) *p++ = '\0'; if (*p)
*p++ = '\0';
*pstr = p; *pstr = p;
return start; return start;
} }
uerr_t ftp_parse(ftpparse *fp,char *buf,int len) uerr_t ftp_parse(ftpparse *fp, char *buf, int len)
{ {
char *cp; char *cp;
char *token; char *token;
char *ptr; char *ptr;
char *date; char *date;
int i; int i;
fp->filename = 0; fp->filename = 0;
fp->namelen = 0; fp->namelen = 0;
// fp->flagtrycwd = 0; // fp->flagtrycwd = 0;
@@ -128,13 +148,14 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
fp->id = 0; fp->id = 0;
// fp->idlen = 0; // fp->idlen = 0;
proz_debug("FTP LIST to be parsed is %s", cp=strdup(buf)); proz_debug("FTP LIST to be parsed is %s", cp = strdup(buf));
free(cp); free(cp);
if (len < 2) /* an empty name in EPLF, with no info, could be 2 chars */ if (len < 2) /* an empty name in EPLF, with no info, could be 2 chars */
return FTPPARSENOTEXIST; return FTPPARSENOTEXIST;
switch(*buf) { switch (*buf)
{
case 'b': case 'b':
case 'c': case 'c':
case 'd': case 'd':
@@ -160,34 +181,41 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
/* "drwxrwxr-x folder 2 May 10 1996 network" /* "drwxrwxr-x folder 2 May 10 1996 network"
*/ */
if (*buf == 'd') fp->filetype = DIRECTORY; if (*buf == 'd')
if (*buf == '-') fp->filetype = DIRECTORY; fp->filetype = DIRECTORY;
if (*buf == 'l') fp->filetype = SYMBOLIC_LINK; if (*buf == '-')
ptr=cp=strdup(buf); fp->filetype = DIRECTORY;
if (*buf == 'l')
fp->filetype = SYMBOLIC_LINK;
ptr = cp = strdup(buf);
for (i=0;i<4;i++) for (i = 0; i < 4; i++)
{ {
//add checking //add checking
token= get_nextfield(&cp); token = get_nextfield(&cp);
if(token == NULL) //failed to parse if (token == NULL) //failed to parse
return FTPPARSEFAIL; return FTPPARSEFAIL;
} }
/* /*
** This field can either be group or size. We find out by looking at the ** 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. ** next field. If this is a non-digit then this field is the size.
*/ */
while (*cp && isspace((int) *cp)) cp++; while (*cp && isspace((int)*cp))
if (isdigit((int) *cp)) { cp++;
if (isdigit((int)*cp))
{
token = get_nextfield(&cp); token = get_nextfield(&cp);
while (*cp && isspace((int) *cp)) cp++; while (*cp && isspace((int)*cp))
cp++;
} }
//if it is a filename //if it is a filename
fp->filesize=strtol(token,NULL,10); fp->filesize = strtol(token, NULL, 10);
proz_debug("FTP file size is %ld", fp->filesize); proz_debug("FTP file size is %ld", fp->filesize);
while (*cp && isspace((int) *cp)) cp++; while (*cp && isspace((int)*cp))
assert(cp+12<ptr+len); cp++;
assert(cp + 12 < ptr + len);
date = cp; date = cp;
cp += 12; cp += 12;
*cp++ = '\0'; *cp++ = '\0';
@@ -196,11 +224,10 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
proz_debug("LIST date is %s", fp->date_str); proz_debug("LIST date is %s", fp->date_str);
return FTPPARSEOK; return FTPPARSEOK;
default: default:
return FTPPARSEFAIL; return FTPPARSEFAIL;
} }
} }
@@ -208,18 +235,16 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
time_t parse_time(const char * str) time_t parse_time(const char * str)
{ {
char * p; char * p;
struct tm tm; struct tm tm;
time_t t; time_t t;
if (!str) return 0; if (!str)
return 0;
if ((p = strchr(str, ','))) if ((p = strchr(str, ',')))
{ {
}
}
return 0; return 0;
} }

View File

@@ -19,7 +19,7 @@
/* FTP LIST command parsing code. */ /* FTP LIST command parsing code. */
/* $Id: ftpparse.h,v 1.15 2005/08/06 17:07:35 kalum Exp $ */ /* $Id$ */
#ifndef FTPPARSE_H #ifndef FTPPARSE_H
@@ -41,11 +41,11 @@ typedef struct ftpparse {
time_t mtime; /* modification time */ time_t mtime; /* modification time */
file_type_t filetype; file_type_t filetype;
char *id; /* not necessarily 0-terminated */ char *id; /* not necessarily 0-terminated */
char *date_str; char *date_str;
}ftpparse ; }ftpparse;
uerr_t ftp_parse(ftpparse *fp,char *buf,int len); uerr_t ftp_parse(ftpparse *fp, char *buf, int len);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -62,7 +62,7 @@ ftps_request_t * proz_ftps_request_init(
assert(requested_url); assert(requested_url);
assert(requested_url->file); assert(requested_url->file);
request=kmalloc(sizeof(ftps_request_t)); request = kmalloc(sizeof(ftps_request_t));
memset(request, 0, sizeof(ftps_request_t)); memset(request, 0, sizeof(ftps_request_t));
request->file_name = strdup(requested_url->file); request->file_name = strdup(requested_url->file);
request->requested_url = proz_copy_url(requested_url); request->requested_url = proz_copy_url(requested_url);
@@ -78,18 +78,20 @@ ftps_request_t * proz_ftps_request_init(
proz_die("Bad URl specification"); proz_die("Bad URl specification");
/*NOTE pasing zero as the status change mutes as we dont need it here */ /*NOTE pasing zero as the status change mutes as we dont need it here */
request->connection=proz_connection_init(url,0); request->connection = proz_connection_init(url, 0);
break; break;
case FILESEARCH_RU: case FILESEARCH_RU:
url = prepare_filesearching_url(request, ftps_loc, num_req_mirrors); url = prepare_filesearching_url(request, ftps_loc, num_req_mirrors);
if (url == 0) if (url == 0)
proz_die("Bad URl specification"); proz_die("Bad URl specification");
/*NOTE pasing zero as the status change mutes as we dont need it here */ /*NOTE pasing zero as the status change mutes as we dont need it here */
request->connection=proz_connection_init(url,0); request->connection = proz_connection_init(url, 0);
break; break;
default: default:
proz_debug("Unsupported FTP search server type"); proz_debug("Unsupported FTP search server type");
proz_die("Unsupported FTP search server type"); proz_die("Unsupported FTP search server type");
@@ -112,11 +114,11 @@ urlinfo *prepare_lycos_url(ftps_request_t * request, char *ftps_loc,
assert(request->file_name); assert(request->file_name);
url = (urlinfo *) kmalloc(sizeof(urlinfo)); url = (urlinfo *)kmalloc(sizeof(urlinfo));
/* Okay lets now construct the URL we want to do lycos */ /* Okay lets now construct the URL we want to do lycos */
lycos_url_buf = lycos_url_buf =
(char *) kmalloc(lycos_url_len + strlen(request->file_name) + 300); (char *)kmalloc(lycos_url_len + strlen(request->file_name) + 300);
sprintf(lycos_url_buf, sprintf(lycos_url_buf,
"%s?form=advanced&query=%s&doit=Search&type=Exact+search&hits=%d&matches=&hitsprmatch=&limdom=&limpath=&limsize1=%zd&limsize2=%zd&f1=Host&f2=Path&f3=Size&f4=-&f5=-&f6=-&header=none&sort=none&trlen=20", "%s?form=advanced&query=%s&doit=Search&type=Exact+search&hits=%d&matches=&hitsprmatch=&limdom=&limpath=&limsize1=%zd&limsize2=%zd&f1=Host&f2=Path&f3=Size&f4=-&f5=-&f6=-&header=none&sort=none&trlen=20",
@@ -152,11 +154,11 @@ urlinfo *prepare_filesearching_url(ftps_request_t * request, char *ftps_loc,
assert(request->file_name); assert(request->file_name);
url = (urlinfo *) kmalloc(sizeof(urlinfo)); url = (urlinfo *)kmalloc(sizeof(urlinfo));
/* Okay lets now construct the URL we want to do lycos */ /* Okay lets now construct the URL we want to do lycos */
filesearching_url_buf = filesearching_url_buf =
(char *) kmalloc(filesearching_url_len + strlen(request->file_name) + 300); (char *)kmalloc(filesearching_url_len + strlen(request->file_name) + 300);
sprintf(filesearching_url_buf, sprintf(filesearching_url_buf,
"%s?q=%s&l=en&t=f&e=on&m=%d&o=n&s=on&s1=%zd&s2=%zd&d=&p=&p2=&x=10&y=14", "%s?q=%s&l=en&t=f&e=on&m=%d&o=n&s=on&s1=%zd&s2=%zd&d=&p=&p2=&x=10&y=14",
@@ -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) uerr_t parse_html_mirror_list(ftps_request_t * request, char *p)
{ {
switch (request->server_type) switch (request->server_type)
{ {
case LYCOS: case LYCOS:
return parse_lycos_html_mirror_list(request, p); return parse_lycos_html_mirror_list(request, p);
break; break;
case FILESEARCH_RU: case FILESEARCH_RU:
return parse_filesearching_html_mirror_list(request, p); return parse_filesearching_html_mirror_list(request, p);
break; break;
default: default:
proz_debug("Unsupported FTP search server type"); proz_debug("Unsupported FTP search server type");
proz_die("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) uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
{ {
struct ftp_mirror **pmirrors = &request->mirrors; struct ftp_mirror **pmirrors = &request->mirrors;
int *num_servers = &request->num_mirrors; int *num_servers = &request->num_mirrors;
char *p1, *p2, *i = 0, *j; 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 (num_pre == 1)
{ {
if ((i = strstr(p, "<PRE>")) == NULL) if ((i = strstr(p, "<PRE>")) == NULL)
{ {
proz_debug("nomatches found"); 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"); proz_debug("nomatches found");
return MIRPARSEFAIL; return MIRPARSEFAIL;
} }
} else }
else
{ {
/*search for the reported hits text */ /*search for the reported hits text */
char *rep_hits; char *rep_hits;
@@ -311,15 +313,15 @@ uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
/* Allocate +1 because we need to add the user specified server as well /* Allocate +1 because we need to add the user specified server as well
*/ */
ftp_mirrors = ftp_mirrors =
(ftp_mirror_t *) kmalloc(sizeof(ftp_mirror_t) * (ftp_mirror_t *)kmalloc(sizeof(ftp_mirror_t) *
((*num_servers) + 1)); ((*num_servers) + 1));
for (k = 0; k < *num_servers; k++) for (k = 0; k < *num_servers; k++)
{ {
memset(&(ftp_mirrors[k]), 0, sizeof(ftp_mirror_t)); memset(&(ftp_mirrors[k]), 0, sizeof(ftp_mirror_t));
p2 = get_string_ahref(p2, buf, sizeof(buf)/sizeof(char)); p2 = get_string_ahref(p2, buf, sizeof(buf) / sizeof(char));
ftp_mirrors[k].server_name = kstrdup(buf); ftp_mirrors[k].server_name = kstrdup(buf);
p2 = get_string_ahref(p2, buf, sizeof(buf)/sizeof(char)); p2 = get_string_ahref(p2, buf, sizeof(buf) / sizeof(char));
ftp_mirrors[k].paths = kmalloc(sizeof(mirror_path_t)); ftp_mirrors[k].paths = kmalloc(sizeof(mirror_path_t));
@@ -332,7 +334,7 @@ uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
else else
ftp_mirrors[k].paths[0].path = kstrdup(buf); ftp_mirrors[k].paths[0].path = kstrdup(buf);
p2 = get_string_ahref(p2, buf,sizeof(buf)/sizeof(char)); p2 = get_string_ahref(p2, buf, sizeof(buf) / sizeof(char));
ftp_mirrors[k].file_name = kstrdup(buf); ftp_mirrors[k].file_name = kstrdup(buf);
} }
@@ -358,9 +360,8 @@ uerr_t parse_lycos_html_mirror_list(ftps_request_t * request, char *p)
for (k = 0; k < *num_servers; k++) for (k = 0; k < *num_servers; k++)
{ {
ftp_mirrors[k].full_name = ftp_mirrors[k].full_name =
(char *) kmalloc(strlen(ftp_mirrors[k].server_name) + (char *)kmalloc(strlen(ftp_mirrors[k].server_name) +
strlen(ftp_mirrors[k].paths[0].path) + strlen(ftp_mirrors[k].paths[0].path) +
strlen(ftp_mirrors[k].file_name) + 13); strlen(ftp_mirrors[k].file_name) + 13);
sprintf(ftp_mirrors[k].full_name, "%s%s:21/%s%s%s", "ftp://", sprintf(ftp_mirrors[k].full_name, "%s%s:21/%s%s%s", "ftp://",
@@ -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) uerr_t parse_filesearching_html_mirror_list(ftps_request_t * request, char *p)
{ {
struct ftp_mirror **pmirrors = &request->mirrors; struct ftp_mirror **pmirrors = &request->mirrors;
int *num_servers = &request->num_mirrors; int *num_servers = &request->num_mirrors;
char *p1, *p2, *i = 0, *j; 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 (num_pre == 1)
{ {
if ((i = strstr(p, "<pre class=list>")) == NULL) if ((i = strstr(p, "<pre class=list>")) == NULL)
{ {
proz_debug("nomatches found"); 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"); proz_debug("nomatches found");
return MIRPARSEFAIL; return MIRPARSEFAIL;
} }
} else }
else
{ {
/*search for the reported hits text */ /*search for the reported hits text */
char *rep_hits; char *rep_hits;
@@ -493,23 +493,23 @@ uerr_t parse_filesearching_html_mirror_list(ftps_request_t * request, char *p)
/* Allocate +1 because we need to add the user specified server as well /* Allocate +1 because we need to add the user specified server as well
*/ */
ftp_mirrors = ftp_mirrors =
(ftp_mirror_t *) kmalloc(sizeof(ftp_mirror_t) * (ftp_mirror_t *)kmalloc(sizeof(ftp_mirror_t) *
((*num_servers) + 1)); ((*num_servers) + 1));
for (k = 0; k < *num_servers; k++) for (k = 0; k < *num_servers; k++)
{ {
memset(&(ftp_mirrors[k]), 0, sizeof(ftp_mirror_t)); memset(&(ftp_mirrors[k]), 0, sizeof(ftp_mirror_t));
p2 = get_string_ahref(p2, buf,sizeof(buf)/sizeof(char)); p2 = get_string_ahref(p2, buf, sizeof(buf) / sizeof(char));
ftp_mirrors[k].server_name = kstrdup(buf); ftp_mirrors[k].server_name = kstrdup(buf);
p2 = get_string_ahref(p2, buf,sizeof(buf)/sizeof(char)); p2 = get_string_ahref(p2, buf, sizeof(buf) / sizeof(char));
ftp_mirrors[k].paths = kmalloc(sizeof(mirror_path_t)); ftp_mirrors[k].paths = kmalloc(sizeof(mirror_path_t));
// ftp_mirrors[k].paths=kmalloc (sizeof (char *)); // ftp_mirrors[k].paths=kmalloc (sizeof (char *));
ftp_mirrors[k].num_paths = 1; ftp_mirrors[k].num_paths = 1;
/*Strip any trailing slash */ /*Strip any trailing slash */
if(buf[strlen(buf)-1]=='/') if (buf[strlen(buf) - 1] == '/')
buf[strlen(buf)-1]=0; buf[strlen(buf) - 1] = 0;
/*Strip any leading slash in the path name if preent */ /*Strip any leading slash in the path name if preent */
if (*buf == '/') if (*buf == '/')
@@ -517,7 +517,7 @@ uerr_t parse_filesearching_html_mirror_list(ftps_request_t * request, char *p)
else else
ftp_mirrors[k].paths[0].path = kstrdup(buf); ftp_mirrors[k].paths[0].path = kstrdup(buf);
p2 = get_string_ahref(p2, buf,sizeof(buf)/sizeof(char)); p2 = get_string_ahref(p2, buf, sizeof(buf) / sizeof(char));
ftp_mirrors[k].file_name = kstrdup(buf); ftp_mirrors[k].file_name = kstrdup(buf);
} }
@@ -543,9 +543,8 @@ uerr_t parse_filesearching_html_mirror_list(ftps_request_t * request, char *p)
for (k = 0; k < *num_servers; k++) for (k = 0; k < *num_servers; k++)
{ {
ftp_mirrors[k].full_name = ftp_mirrors[k].full_name =
(char *) kmalloc(strlen(ftp_mirrors[k].server_name) + (char *)kmalloc(strlen(ftp_mirrors[k].server_name) +
strlen(ftp_mirrors[k].paths[0].path) + strlen(ftp_mirrors[k].paths[0].path) +
strlen(ftp_mirrors[k].file_name) + 13); strlen(ftp_mirrors[k].file_name) + 13);
sprintf(ftp_mirrors[k].full_name, "%s%s:21/%s%s%s", "ftp://", sprintf(ftp_mirrors[k].full_name, "%s%s:21/%s%s%s", "ftp://",
@@ -603,7 +602,8 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
return err; return err;
} }
} else }
else
{ {
connection_show_message(connection, _("Connecting to %s"), connection_show_message(connection, _("Connecting to %s"),
connection->u.host); 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"); www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd); proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth); proz_debug(_("Authentification string=%s"), www_auth);
} else }
else
www_auth = 0; www_auth = 0;
if (http_use_proxy(connection)) if (http_use_proxy(connection))
@@ -659,37 +660,39 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
{ {
remote_port = NULL; remote_port = NULL;
remote_port_len = 0; remote_port_len = 0;
} else }
else
{ {
remote_port = (char *) alloca(64); remote_port = (char *)alloca(64);
remote_port_len = sprintf(remote_port, ":%d", connection->u.port); remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
} }
if (connection->u.referer) if (connection->u.referer)
{ {
referer = (char *) alloca(13 + strlen(connection->u.referer)); referer = (char *)alloca(13 + strlen(connection->u.referer));
sprintf(referer, "Referer: %s\r\n", connection->u.referer); sprintf(referer, "Referer: %s\r\n", connection->u.referer);
} }
/* If we go through a proxy the request for the URL is different */ /* If we go through a proxy the request for the URL is different */
if (http_use_proxy(connection)) if (http_use_proxy(connection))
{ {
location = (char *) alloca(strlen(connection->u.url) + 1); location = (char *)alloca(strlen(connection->u.url) + 1);
strcpy(location, connection->u.url); strcpy(location, connection->u.url);
} else }
else
{ {
location = (char *) alloca(strlen(connection->u.path) + 1); location = (char *)alloca(strlen(connection->u.path) + 1);
strcpy(location, connection->u.path); strcpy(location, connection->u.path);
} }
/*Use no-cache directive for proxy servers, yes by default here as we dont want ftpsearch rsults which can change soon to be cached */ /*Use no-cache directive for proxy servers, yes by default here as we dont want ftpsearch rsults which can change soon to be cached */
if (http_use_proxy(connection)) if (http_use_proxy(connection))
{ {
pragma_no_cache = (char *) alloca(21); pragma_no_cache = (char *)alloca(21);
sprintf(pragma_no_cache, "Pragma: no-cache\r\n"); sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
} }
request = (char *) alloca(strlen(location) request = (char *)alloca(strlen(location)
+ strlen(connection->user_agent) + strlen(connection->user_agent)
+ strlen(connection->u.host) + remote_port_len + strlen(connection->u.host) + remote_port_len
+ (referer ? strlen(referer) : 0) + (referer ? strlen(referer) : 0)
@@ -717,7 +720,7 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
/* What hapenned ? */ /* What hapenned ? */
if (err != HOK) if (err != HOK)
{ {
proz_debug("1 http_fetch_headers err != HOK %d",err); proz_debug("1 http_fetch_headers err != HOK %d", err);
/*Check if we authenticated using any user or password and if we /*Check if we authenticated using any user or password and if we
were kicked out, if so return HAUTHFAIL */ were kicked out, if so return HAUTHFAIL */
if (err == HAUTHREQ && (strlen(user) || strlen(passwd))) if (err == HAUTHREQ && (strlen(user) || strlen(passwd)))
@@ -732,14 +735,13 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
/* Ok start fetching the data */ /* Ok start fetching the data */
p1 = p = (char *) kmalloc(HTTP_BUFFER_SIZE + 1); p1 = p = (char *)kmalloc(HTTP_BUFFER_SIZE + 1);
p_len = HTTP_BUFFER_SIZE + 1; p_len = HTTP_BUFFER_SIZE + 1;
total = 0; total = 0;
do do
{ {
ret = ret =
krecv(connection->data_sock, buffer, sizeof(buffer), 0, krecv(connection->data_sock, buffer, sizeof(buffer), 0,
&connection->xfer_timeout); &connection->xfer_timeout);
@@ -751,8 +753,7 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
p = p2; p = p2;
} }
total += ret; total += ret;
} } while (ret > 0);
while (ret > 0);
if (ret == -1) if (ret == -1)
{ {
@@ -777,18 +778,17 @@ uerr_t get_mirror_info(connection_t * connection, char **ret_buf)
char *find_ahref(char *buf) char *find_ahref(char *buf)
{ {
return(strcasestr(buf, "<A HREF="));
return (strcasestr(buf, "<A HREF="));
} }
char *find_end(char *buf) char *find_end(char *buf)
{ {
return (strcasestr(buf, ">")); return(strcasestr(buf, ">"));
} }
char *find_closed_a(char *buf) char *find_closed_a(char *buf)
{ {
return (strcasestr(buf, "</A")); return(strcasestr(buf, "</A"));
} }
char *get_string_ahref(char *buf, char *out, size_t out_size) char *get_string_ahref(char *buf, char *out, size_t out_size)
@@ -835,7 +835,8 @@ char *grow_buffer(char *buf_start, char *cur_pos, int *buf_len,
p = krealloc(buf_start, *buf_len + INIT_SIZE); p = krealloc(buf_start, *buf_len + INIT_SIZE);
*buf_len += INIT_SIZE; *buf_len += INIT_SIZE;
return p; return p;
} else }
else
{ {
return buf_start; return buf_start;
} }
@@ -849,12 +850,9 @@ void proz_get_complete_mirror_list(ftps_request_t * request)
/* get_complete_mirror_list(request); */ /* get_complete_mirror_list(request); */
if (pthread_create(&request->info_thread, NULL, if (pthread_create(&request->info_thread, NULL,
(void *) &get_complete_mirror_list, (void *)&get_complete_mirror_list,
(void *) request) != 0) (void *)request) != 0)
proz_die(_("Error: Not enough system resources")); proz_die(_("Error: Not enough system resources"));
} }
@@ -862,7 +860,7 @@ void proz_cancel_mirror_list_request(ftps_request_t * request)
{ {
request->info_running = FALSE; request->info_running = FALSE;
pthread_cancel(request->info_thread); pthread_cancel(request->info_thread);
pthread_join(request->info_thread,0); pthread_join(request->info_thread, 0);
} }
uerr_t get_complete_mirror_list(ftps_request_t * request) uerr_t get_complete_mirror_list(ftps_request_t * request)
@@ -877,7 +875,7 @@ uerr_t get_complete_mirror_list(ftps_request_t * request)
request->info_running = TRUE; request->info_running = TRUE;
pthread_mutex_unlock(&request->access_mutex); pthread_mutex_unlock(&request->access_mutex);
pthread_cleanup_push(cleanup_socks, (void *) request->connection); pthread_cleanup_push(cleanup_socks, (void *)request->connection);
request->err = get_mirror_info(request->connection, &data_buf); request->err = get_mirror_info(request->connection, &data_buf);
pthread_cleanup_pop(0); pthread_cleanup_pop(0);
@@ -910,8 +908,9 @@ uerr_t get_complete_mirror_list(ftps_request_t * request)
pthread_mutex_lock(&request->access_mutex); pthread_mutex_lock(&request->access_mutex);
request->info_running = FALSE; request->info_running = FALSE;
pthread_mutex_unlock(&request->access_mutex); pthread_mutex_unlock(&request->access_mutex);
return (request->err = HERR); return(request->err = HERR);
} else }
else
connection_show_message(request->connection, connection_show_message(request->connection,
_("Redirected to => %s"), _("Redirected to => %s"),
constructed_newloc); constructed_newloc);
@@ -919,8 +918,7 @@ uerr_t get_complete_mirror_list(ftps_request_t * request)
kfree(constructed_newloc); kfree(constructed_newloc);
request->err = NEWLOCATION; request->err = NEWLOCATION;
} }
} } while (request->err == NEWLOCATION);
while (request->err == NEWLOCATION);
/*TODO handle and process the redirection here */ /*TODO handle and process the redirection here */
if (request->err != HOK) if (request->err != HOK)
@@ -937,13 +935,13 @@ uerr_t get_complete_mirror_list(ftps_request_t * request)
request->info_running = FALSE; request->info_running = FALSE;
pthread_mutex_unlock(&request->access_mutex); pthread_mutex_unlock(&request->access_mutex);
return request->err; return request->err;
} }
boolean proz_request_info_running(ftps_request_t * request) boolean proz_request_info_running(ftps_request_t * request)
{ {
boolean ret; boolean ret;
pthread_mutex_lock(&request->access_mutex); pthread_mutex_lock(&request->access_mutex);
ret = request->info_running; ret = request->info_running;
pthread_mutex_unlock(&request->access_mutex); 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 proz_request_mass_ping_running(ftps_request_t * request)
{ {
boolean ret; boolean ret;
pthread_mutex_lock(&request->access_mutex); pthread_mutex_lock(&request->access_mutex);
ret = request->mass_ping_running; ret = request->mass_ping_running;
pthread_mutex_unlock(&request->access_mutex); pthread_mutex_unlock(&request->access_mutex);
@@ -964,13 +963,12 @@ boolean proz_request_mass_ping_running(ftps_request_t * request)
ftp_mirror_t *reprocess_mirror_list(ftp_mirror_t * mirrors, ftp_mirror_t *reprocess_mirror_list(ftp_mirror_t * mirrors,
int *num_servers) int *num_servers)
{ {
ftp_mirror_t *ftp_mirrors; ftp_mirror_t *ftp_mirrors;
int i, j; int i, j;
int num_new_servers = 0; int num_new_servers = 0;
ftp_mirrors = ftp_mirrors =
(ftp_mirror_t *) kmalloc(sizeof(ftp_mirror_t) * ((*num_servers))); (ftp_mirror_t *)kmalloc(sizeof(ftp_mirror_t) * ((*num_servers)));
for (i = 0; i < *num_servers; i++) for (i = 0; i < *num_servers; i++)
{ {
@@ -982,7 +980,7 @@ ftp_mirror_t *reprocess_mirror_list(ftp_mirror_t * mirrors,
sizeof(ftp_mirror_t)); sizeof(ftp_mirror_t));
/*For the moment assume that all the mirrors support resume */ /*For the moment assume that all the mirrors support resume */
ftp_mirrors[num_new_servers - 1].resume_supported=TRUE; ftp_mirrors[num_new_servers - 1].resume_supported = TRUE;
for (j = i + 1; j < *num_servers; j++) for (j = i + 1; j < *num_servers; j++)
{ {
@@ -1034,8 +1032,8 @@ ftp_mirror_t *reprocess_mirror_list(ftp_mirror_t * mirrors,
int compare_two_servers(const void *a, const void *b) int compare_two_servers(const void *a, const void *b)
{ {
const ftp_mirror_t *ma = (const ftp_mirror_t *) a; const ftp_mirror_t *ma = (const ftp_mirror_t *)a;
const ftp_mirror_t *mb = (const ftp_mirror_t *) b; const ftp_mirror_t *mb = (const ftp_mirror_t *)b;
int milli_sec_a; int milli_sec_a;
int milli_sec_b; int milli_sec_b;
@@ -1060,13 +1058,14 @@ int compare_two_servers(const void *a, const void *b)
} }
return (milli_sec_a - milli_sec_b); return(milli_sec_a - milli_sec_b);
} }
void proz_sort_mirror_list(ftp_mirror_t * mirrors, int num_servers) void proz_sort_mirror_list(ftp_mirror_t * mirrors, int num_servers)
{ {
int i; int i;
qsort(mirrors, num_servers, sizeof(ftp_mirror_t), compare_two_servers); qsort(mirrors, num_servers, sizeof(ftp_mirror_t), compare_two_servers);
for (i = 0; i < num_servers; i++) for (i = 0; i < num_servers; i++)
proz_debug("Mirror = %s, time =%d", mirrors[i].server_name, 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 ftpsearch_get_server_position(ftps_request_t * request, char *server)
{ {
int i; int i;
for (i = 0; i < request->num_mirrors; i++) for (i = 0; i < request->num_mirrors; i++)
{ {
if (strcmp(request->mirrors[i].server_name, server) == 0) if (strcmp(request->mirrors[i].server_name, server) == 0)
return i; 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); proz_debug("path to check is %s", path);
if (strcmp(request->mirrors[pos].paths[i].path, path) == 0) if (strcmp(request->mirrors[pos].paths[i].path, path) == 0)
return i; return i;
} }
return -1; return -1;
} }

View File

@@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 "common.h"
#include "prozilla.h" #include "prozilla.h"
@@ -79,7 +79,8 @@ uerr_t proz_http_get_file(connection_t * connection)
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
return err; return err;
} }
} else }
else
{ {
connection_show_message(connection, _("Connecting to %s"), connection_show_message(connection, _("Connecting to %s"),
connection->u.host); 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"); www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd); proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth); proz_debug(_("Authentification string=%s"), www_auth);
} else }
else
www_auth = 0; www_auth = 0;
if (http_use_proxy(connection)) if (http_use_proxy(connection))
@@ -135,33 +137,35 @@ uerr_t proz_http_get_file(connection_t * connection)
{ {
remote_port = NULL; remote_port = NULL;
remote_port_len = 0; remote_port_len = 0;
} else }
else
{ {
remote_port = (char *) alloca(64); remote_port = (char *)alloca(64);
remote_port_len = sprintf(remote_port, ":%d", connection->u.port); remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
} }
if (connection->hs.accept_ranges == 1) if (connection->hs.accept_ranges == 1)
{ {
range = (char *) alloca(18 + 64); range = (char *)alloca(18 + 64);
sprintf(range, "Range: bytes=%lld-\r\n", connection->remote_startpos); sprintf(range, "Range: bytes=%lld-\r\n", connection->remote_startpos);
proz_debug("Range = %lld Range = %s",connection->remote_startpos, range); proz_debug("Range = %lld Range = %s", connection->remote_startpos, range);
} }
if (connection->u.referer) if (connection->u.referer)
{ {
referer = (char *) alloca(13 + strlen(connection->u.referer)); referer = (char *)alloca(13 + strlen(connection->u.referer));
sprintf(referer, "Referer: %s\r\n", connection->u.referer); sprintf(referer, "Referer: %s\r\n", connection->u.referer);
} }
/* If we go through a proxy the request for the URL is different */ /* If we go through a proxy the request for the URL is different */
if (http_use_proxy(connection)) if (http_use_proxy(connection))
{ {
location = (char *) alloca(strlen(connection->u.url) + 1); location = (char *)alloca(strlen(connection->u.url) + 1);
strcpy(location, connection->u.url); strcpy(location, connection->u.url);
} else }
else
{ {
location = (char *) alloca(strlen(connection->u.path) + 1); location = (char *)alloca(strlen(connection->u.path) + 1);
strcpy(location, connection->u.path); strcpy(location, connection->u.path);
} }
@@ -169,11 +173,11 @@ uerr_t proz_http_get_file(connection_t * connection)
if (http_use_proxy(connection) if (http_use_proxy(connection)
&& (connection->http_no_cache || connection->attempts > 0)) && (connection->http_no_cache || connection->attempts > 0))
{ {
pragma_no_cache = (char *) alloca(21); pragma_no_cache = (char *)alloca(21);
sprintf(pragma_no_cache, "Pragma: no-cache\r\n"); sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
} }
request = (char *) alloca(strlen(location) request = (char *)alloca(strlen(location)
+ strlen(connection->user_agent) + strlen(connection->user_agent)
+ strlen(connection->u.host) + remote_port_len + strlen(connection->u.host) + remote_port_len
+ (range ? strlen(range) : 0) + (range ? strlen(range) : 0)
@@ -253,13 +257,14 @@ uerr_t proz_http_get_file(connection_t * connection)
/* A genuine loop ;) It willed be called by the main thread, and /* A genuine loop ;) It willed be called by the main thread, and
this will handle all possible errors itself, retrying until the number this will handle all possible errors itself, retrying until the number
of maximum tries for the connection is realised of maximum tries for the connection is realised
*/ */
uerr_t http_loop(connection_t * connection) uerr_t http_loop(connection_t * connection)
{ {
boolean retrying_from_loop = FALSE; boolean retrying_from_loop = FALSE;
assert(connection->max_attempts >= 0); assert(connection->max_attempts >= 0);
assert(connection->attempts >= 0); assert(connection->attempts >= 0);
@@ -269,7 +274,6 @@ uerr_t http_loop(connection_t * connection)
{ {
if (connection->attempts > 0) if (connection->attempts > 0)
{ {
if (retrying_from_loop == TRUE) if (retrying_from_loop == TRUE)
{ {
connection_show_message(connection, connection_show_message(connection,
@@ -287,7 +291,8 @@ uerr_t http_loop(connection_t * connection)
_ _
("Error while attemting to process download file ")); ("Error while attemting to process download file "));
} }
} else }
else
{ {
/*If we cant resume then reset the connections bytesreceived to 0 */ /*If we cant resume then reset the connections bytesreceived to 0 */
connection->remote_bytes_received = 0; connection->remote_bytes_received = 0;
@@ -295,7 +300,7 @@ uerr_t http_loop(connection_t * connection)
} }
/*Push the handler which will cleanup any sockets that are left open */ /*Push the handler which will cleanup any sockets that are left open */
pthread_cleanup_push(cleanup_socks, (void *) connection); pthread_cleanup_push(cleanup_socks, (void *)connection);
connection->err = proz_http_get_file(connection); connection->err = proz_http_get_file(connection);
/*pop the handler */ /*pop the handler */
pthread_cleanup_pop(0); pthread_cleanup_pop(0);
@@ -324,9 +329,7 @@ uerr_t http_loop(connection_t * connection)
} }
retrying_from_loop = TRUE; retrying_from_loop = TRUE;
} while ((connection->attempts < connection->max_attempts)
}
while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0); || connection->max_attempts == 0);
@@ -336,13 +339,12 @@ uerr_t http_loop(connection_t * connection)
connection->attempts); connection->attempts);
return connection->err; return connection->err;
} }
/*Return true if it is a error which can be handled within the htp_loop, /*Return true if it is a error which can be handled within the htp_loop,
or false if it should be passed upwards so that the main download thread can 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 */ restart it when necessary after processing other threads status too */
boolean http_loop_handle_error(uerr_t err) boolean http_loop_handle_error(uerr_t err)
{ {
proz_debug("Error encountered in http_loop is %d", err); proz_debug("Error encountered in http_loop is %d", 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 ftp_get_file_from_http_proxy(connection_t * connection)
{ {
uerr_t err; uerr_t err;
int remote_port_len; int remote_port_len;
char *user, *passwd, *www_auth = NULL, *proxy_auth = NULL, *range = 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"); www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd); proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth); proz_debug(_("Authentification string=%s"), www_auth);
} else }
else
www_auth = 0; www_auth = 0;
if (strlen(connection->ftp_proxy->username) if (strlen(connection->ftp_proxy->username)
@@ -434,12 +436,12 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
connection->ftp_proxy->passwd, connection->ftp_proxy->passwd,
"Proxy-Authorization"); "Proxy-Authorization");
remote_port = (char *) alloca(64); remote_port = (char *)alloca(64);
remote_port_len = sprintf(remote_port, ":%d", connection->u.port); remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
if (connection->hs.accept_ranges == 1) if (connection->hs.accept_ranges == 1)
{ {
range = (char *) alloca(18 + 64); range = (char *)alloca(18 + 64);
sprintf(range, "Range: bytes=%lld-\r\n", connection->remote_startpos); sprintf(range, "Range: bytes=%lld-\r\n", connection->remote_startpos);
} }
@@ -448,7 +450,7 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
if (http_use_proxy(connection) if (http_use_proxy(connection)
&& (connection->http_no_cache || connection->attempts > 0)) && (connection->http_no_cache || connection->attempts > 0))
{ {
pragma_no_cache = (char *) alloca(21); pragma_no_cache = (char *)alloca(21);
sprintf(pragma_no_cache, "Pragma: no-cache\r\n"); sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
} }
@@ -456,7 +458,7 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
/*Referrer TAG should not be needed in FTP through HTTP proxy..right */ /*Referrer TAG should not be needed in FTP through HTTP proxy..right */
request = (char *) alloca(strlen(connection->u.url) request = (char *)alloca(strlen(connection->u.url)
+ strlen(connection->user_agent) + strlen(connection->user_agent)
+ strlen(connection->u.host) + remote_port_len + strlen(connection->u.host) + remote_port_len
+ (range ? strlen(range) : 0) + (range ? strlen(range) : 0)
@@ -487,11 +489,13 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
{ {
connection_change_status(connection, LOGINFAIL); connection_change_status(connection, LOGINFAIL);
return FTPLOGREFUSED; return FTPLOGREFUSED;
} else if (err == HTTPNSFOD) }
else if (err == HTTPNSFOD)
{ {
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
return FTPNSFOD; return FTPNSFOD;
} else if (err != HOK) }
else if (err != HOK)
{ {
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
return FTPERR; return FTPERR;
@@ -526,5 +530,4 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
return FTPOK; return FTPOK;
else else
return err; return err;
} }

View File

@@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 #ifndef HTTP_RETR_H
@@ -30,9 +30,9 @@
extern "C" { extern "C" {
#endif #endif
uerr_t proz_http_get_file(connection_t * connection); uerr_t proz_http_get_file(connection_t * connection);
uerr_t http_loop(connection_t * connection); uerr_t http_loop(connection_t * connection);
boolean http_loop_handle_error(uerr_t err); boolean http_loop_handle_error(uerr_t err);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -19,7 +19,7 @@
/* HTTP support. */ /* HTTP support. */
/* $Id: http.c,v 1.22 2005/03/31 20:10:57 sean Exp $ */ /* $Id$ */
#include "common.h" #include "common.h"
@@ -154,7 +154,8 @@ uerr_t fetch_next_header(int fd, char **hdr, struct timeval * timeout)
break; break;
} }
} else if (res == 0) }
else if (res == 0)
return HEOF; return HEOF;
else else
return HERR; return HERR;
@@ -216,7 +217,8 @@ int hparsestatline(const char *hdr, const char **rp)
*rp = hdr + 3; *rp = hdr + 3;
else else
return -1; return -1;
} else }
else
*rp = hdr + 4; *rp = hdr + 4;
return statcode; return statcode;
@@ -259,7 +261,7 @@ off_t hgetlen(const char *hdr)
for (len = 0; isdigit(*hdr); hdr++) for (len = 0; isdigit(*hdr); hdr++)
len = 10 * len + (*hdr - '0'); len = 10 * len + (*hdr - '0');
proz_debug("contenlen %s contentlen %lld",*hdr,len); proz_debug("contenlen %s contentlen %lld", *hdr, len);
return len; return len;
} }
@@ -295,7 +297,7 @@ off_t hgetrange(const char *hdr)
for (len = 0; isdigit(*hdr); hdr++) for (len = 0; isdigit(*hdr); hdr++)
len = 10 * len + (*hdr - '0'); len = 10 * len + (*hdr - '0');
proz_debug("range %s range %lld",*hdr,len); proz_debug("range %s range %lld", *hdr, len);
return len; return len;
} }
@@ -388,7 +390,7 @@ uerr_t http_fetch_headers(connection_t * connection, http_stat_t * hs,
/* Header-fetching loop. */ /* Header-fetching loop. */
hcount = 0; hcount = 0;
for (;;) for (;; )
{ {
++hcount; ++hcount;
@@ -409,7 +411,8 @@ uerr_t http_fetch_headers(connection_t * connection, http_stat_t * hs,
kfree(all_headers); kfree(all_headers);
return HEOF; return HEOF;
} else if (err == HERR) }
else if (err == HERR)
{ {
proz_debug(_("Read error in headers")); 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); connection->http_proxy->proxy_url.host);
return err; return err;
} }
} else }
else
{ {
connection_show_message(connection, _("Connecting to %s"), connection_show_message(connection, _("Connecting to %s"),
connection->u.host); 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"); www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd); proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth); proz_debug(_("Authentification string=%s"), www_auth);
} else }
else
www_auth = 0; www_auth = 0;
if (http_use_proxy(connection)) if (http_use_proxy(connection))
@@ -629,27 +634,29 @@ uerr_t proz_http_get_url_info(connection_t * connection)
{ {
remote_port = NULL; remote_port = NULL;
remote_port_len = 0; remote_port_len = 0;
} else }
else
{ {
remote_port = (char *) alloca(64); remote_port = (char *)alloca(64);
remote_port_len = sprintf(remote_port, ":%d", connection->u.port); remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
} }
if (connection->u.referer) if (connection->u.referer)
{ {
referer = (char *) alloca(13 + strlen(connection->u.referer)); referer = (char *)alloca(13 + strlen(connection->u.referer));
sprintf(referer, "Referer: %s\r\n", connection->u.referer); sprintf(referer, "Referer: %s\r\n", connection->u.referer);
} }
/* If we go through a proxy the request for the URL is different */ /* If we go through a proxy the request for the URL is different */
if (http_use_proxy(connection)) if (http_use_proxy(connection))
{ {
location = (char *) alloca(strlen(connection->u.url) + 1); location = (char *)alloca(strlen(connection->u.url) + 1);
strcpy(location, connection->u.url); strcpy(location, connection->u.url);
} else }
else
{ {
location = (char *) alloca(strlen(connection->u.path) + 1); location = (char *)alloca(strlen(connection->u.path) + 1);
strcpy(location, connection->u.path); strcpy(location, connection->u.path);
} }
@@ -657,11 +664,11 @@ uerr_t proz_http_get_url_info(connection_t * connection)
if (http_use_proxy(connection) if (http_use_proxy(connection)
&& (connection->http_no_cache || connection->attempts > 0)) && (connection->http_no_cache || connection->attempts > 0))
{ {
pragma_no_cache = (char *) alloca(21); pragma_no_cache = (char *)alloca(21);
sprintf(pragma_no_cache, "Pragma: no-cache\r\n"); sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
} }
request = (char *) alloca(strlen(location) request = (char *)alloca(strlen(location)
+ strlen(connection->user_agent) + strlen(connection->user_agent)
+ strlen(connection->u.host) + remote_port_len + strlen(connection->u.host) + remote_port_len
+ (referer ? strlen(referer) : 0) + (referer ? strlen(referer) : 0)
@@ -704,7 +711,6 @@ uerr_t proz_http_get_url_info(connection_t * connection)
/*Loops for connection->attempts */ /*Loops for connection->attempts */
uerr_t http_get_url_info_loop(connection_t * connection) uerr_t http_get_url_info_loop(connection_t * connection)
{ {
pthread_mutex_lock(&connection->access_mutex); pthread_mutex_lock(&connection->access_mutex);
connection->running = TRUE; connection->running = TRUE;
pthread_mutex_unlock(&connection->access_mutex); 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) if (connection->attempts > 0 && connection->err != NEWLOCATION)
{ {
connection_show_message(connection, connection_show_message(connection,
_("Retrying...Attempt %d in %d seconds"), _("Retrying...Attempt %d in %d seconds"),
connection->attempts, connection->attempts,
@@ -723,7 +728,7 @@ uerr_t http_get_url_info_loop(connection_t * connection)
} }
/*Push the handler which will cleanup any sockets that are left open */ /*Push the handler which will cleanup any sockets that are left open */
pthread_cleanup_push(cleanup_socks, (void *) connection); pthread_cleanup_push(cleanup_socks, (void *)connection);
connection->err = proz_http_get_url_info(connection); connection->err = proz_http_get_url_info(connection);
/*pop the handler */ /*pop the handler */
pthread_cleanup_pop(0); pthread_cleanup_pop(0);
@@ -756,9 +761,7 @@ uerr_t http_get_url_info_loop(connection_t * connection)
connection_show_message(connection, proz_strerror(connection->err)); connection_show_message(connection, proz_strerror(connection->err));
break; break;
} }
} while ((connection->attempts < connection->max_attempts)
}
while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0); || 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 ftp_get_url_info_from_http_proxy(connection_t * connection)
{ {
uerr_t err; uerr_t err;
int remote_port_len; int remote_port_len;
char *user, *passwd, *www_auth = NULL, *proxy_auth = 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"); www_auth = get_basic_auth_str(user, passwd, "Authorization");
proz_debug(_("Authenticating as user %s password %s"), user, passwd); proz_debug(_("Authenticating as user %s password %s"), user, passwd);
proz_debug(_("Authentification string=%s"), www_auth); proz_debug(_("Authentification string=%s"), www_auth);
} else }
else
www_auth = 0; www_auth = 0;
if (strlen(connection->ftp_proxy->username) if (strlen(connection->ftp_proxy->username)
@@ -839,20 +842,20 @@ uerr_t ftp_get_url_info_from_http_proxy(connection_t * connection)
connection->ftp_proxy->passwd, connection->ftp_proxy->passwd,
"Proxy-Authorization"); "Proxy-Authorization");
remote_port = (char *) alloca(64); remote_port = (char *)alloca(64);
remote_port_len = sprintf(remote_port, ":%d", connection->u.port); remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
if (http_use_proxy(connection) if (http_use_proxy(connection)
&& (connection->http_no_cache || connection->attempts > 0)) && (connection->http_no_cache || connection->attempts > 0))
{ {
pragma_no_cache = (char *) alloca(21); pragma_no_cache = (char *)alloca(21);
sprintf(pragma_no_cache, "Pragma: no-cache\r\n"); sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
} }
/*Referrer TAG should not be needed in FTP through HTTP proxy..right */ /*Referrer TAG should not be needed in FTP through HTTP proxy..right */
request = (char *) alloca(strlen(connection->u.url) request = (char *)alloca(strlen(connection->u.url)
+ strlen(connection->user_agent) + strlen(connection->user_agent)
+ strlen(connection->u.host) + remote_port_len + strlen(connection->u.host) + remote_port_len
+ (www_auth ? strlen(www_auth) : 0) + (www_auth ? strlen(www_auth) : 0)
@@ -897,5 +900,4 @@ uerr_t ftp_get_url_info_from_http_proxy(connection_t * connection)
/* connection->file_type = REGULAR_FILE; */ /* connection->file_type = REGULAR_FILE; */
return FTPERR; return FTPERR;
} }

View File

@@ -19,7 +19,7 @@
/* HTTP support. */ /* HTTP support. */
/* $Id: http.h,v 1.12 2005/03/31 20:10:57 sean Exp $ */ /* $Id$ */
#ifndef HTTP_H #ifndef HTTP_H
@@ -34,26 +34,26 @@
extern "C" { extern "C" {
#endif #endif
int buf_readchar(int fd, char *ret, struct timeval *timeout); int buf_readchar(int fd, char *ret, struct timeval *timeout);
int buf_peek(int fd, char *ret, struct timeval *timeout); int buf_peek(int fd, char *ret, struct timeval *timeout);
uerr_t fetch_next_header(int fd, char **hdr, struct timeval *timeout); uerr_t fetch_next_header(int fd, char **hdr, struct timeval *timeout);
int hparsestatline(const char *hdr, const char **rp); int hparsestatline(const char *hdr, const char **rp);
int hskip_lws(const char *hdr); int hskip_lws(const char *hdr);
off_t hgetlen(const char *hdr); off_t hgetlen(const char *hdr);
off_t hgetrange(const char *hdr); off_t hgetrange(const char *hdr);
char *hgetlocation(const char *hdr); char *hgetlocation(const char *hdr);
char *hgetmodified(const char *hdr); char *hgetmodified(const char *hdr);
int hgetaccept_ranges(const char *hdr); int hgetaccept_ranges(const char *hdr);
uerr_t http_fetch_headers(connection_t * connection, http_stat_t * hs, uerr_t http_fetch_headers(connection_t * connection, http_stat_t * hs,
char *command); char *command);
char *get_basic_auth_str(char *user, char *passwd, char *auth_header); char *get_basic_auth_str(char *user, char *passwd, char *auth_header);
boolean http_use_proxy(connection_t * connection); boolean http_use_proxy(connection_t * connection);
uerr_t proz_http_get_url_info(connection_t * connection); uerr_t proz_http_get_url_info(connection_t * connection);
uerr_t http_get_url_info_loop(connection_t * connection); uerr_t http_get_url_info_loop(connection_t * connection);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

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

View File

@@ -30,7 +30,7 @@ extern "C" {
#endif #endif
int log_create_logfile(int num_connections, int file_size, char *url, int log_create_logfile(int num_connections, int file_size, char *url,
download_t * download); download_t * download);

View File

@@ -36,7 +36,7 @@
{"use-port", no_argument, NULL, 129}, {"use-port", no_argument, NULL, 129},
{"libdebug", no_argument, NULL, 130}, {"libdebug", no_argument, NULL, 130},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
};*/ };*/
libprozinfo libprozrtinfo; libprozinfo libprozrtinfo;
@@ -88,8 +88,8 @@ int proz_init(int argc, char **argv)
continue; continue;
} }
} }
*/ */
/* TODO Get home directory and read .netrc. */ /* TODO Get home directory and read .netrc. */
libprozrtinfo.home_dir = home_dir(); libprozrtinfo.home_dir = home_dir();
@@ -101,7 +101,9 @@ int proz_init(int argc, char **argv)
sprintf(netrc_file, "%s/%s", libprozrtinfo.home_dir, ".netrc"); sprintf(netrc_file, "%s/%s", libprozrtinfo.home_dir, ".netrc");
libprozrtinfo.netrc_list = parse_netrc(netrc_file); libprozrtinfo.netrc_list = parse_netrc(netrc_file);
} else { }
else
{
/* Make sure home dir is never NULL */ /* Make sure home dir is never NULL */
libprozrtinfo.home_dir = kstrdup("."); libprozrtinfo.home_dir = kstrdup(".");
} }
@@ -199,7 +201,6 @@ void proz_set_download_dir(char *dir)
kfree(libprozrtinfo.dl_dir); kfree(libprozrtinfo.dl_dir);
libprozrtinfo.dl_dir = kstrdup(dir); libprozrtinfo.dl_dir = kstrdup(dir);
} }
void proz_set_logfile_dir(char *dir) void proz_set_logfile_dir(char *dir)
@@ -224,6 +225,5 @@ void proz_set_output_dir(char *dir)
char *proz_get_libprozilla_version() char *proz_get_libprozilla_version()
{ {
return strdup(VERSION); return strdup(VERSION);
} }

View File

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

View File

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

View File

@@ -18,7 +18,7 @@
/* Slightly modified for libprozilla, by Grendel <kalum@delrom.ro>. */ /* 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" #include "common.h"
@@ -35,6 +35,7 @@
static void maybe_add_to_list(netrc_entry ** newentry, netrc_entry ** list) static void maybe_add_to_list(netrc_entry ** newentry, netrc_entry ** list)
{ {
netrc_entry *a, *l; netrc_entry *a, *l;
a = *newentry; a = *newentry;
l = *list; l = *list;
@@ -46,7 +47,8 @@ static void maybe_add_to_list(netrc_entry ** newentry, netrc_entry ** list)
kfree(a->host); kfree(a->host);
if (a->password) if (a->password)
kfree(a->password); kfree(a->password);
} else }
else
{ {
if (a) if (a)
{ {
@@ -105,7 +107,7 @@ netrc_entry *parse_netrc(char *file)
ln++; ln++;
/* Strip trailing CRLF. */ /* Strip trailing CRLF. */
for (p = buf + strlen(buf) - 1; (p >= buf) && isspace((unsigned) *p); for (p = buf + strlen(buf) - 1; (p >= buf) && isspace((unsigned)*p);
p--) p--)
*p = '\0'; *p = '\0';
@@ -128,7 +130,7 @@ netrc_entry *parse_netrc(char *file)
char *pp; char *pp;
/* Skip any whitespace. */ /* Skip any whitespace. */
while (*p && isspace((unsigned) *p)) while (*p && isspace((unsigned)*p))
p++; p++;
/* Discard end-of-line comments. */ /* Discard end-of-line comments. */
@@ -138,7 +140,7 @@ netrc_entry *parse_netrc(char *file)
tok = pp = p; tok = pp = p;
/* Find the end of the token. */ /* Find the end of the token. */
while (*p && (quote_char || !isspace((unsigned) *p))) while (*p && (quote_char || !isspace((unsigned)*p)))
{ {
if (quote_char) if (quote_char)
{ {
@@ -146,13 +148,15 @@ netrc_entry *parse_netrc(char *file)
{ {
quote_char = 0; quote_char = 0;
p++; p++;
} else }
else
{ {
*pp = *p; *pp = *p;
p++; p++;
pp++; pp++;
} }
} else }
else
{ {
if (*p == '"' || *p == '\'') if (*p == '"' || *p == '\'')
quote_char = *p; quote_char = *p;

View File

@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 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 #ifndef NETRC_H

View File

@@ -40,7 +40,7 @@ uerr_t tcp_ping(ping_t * ping_data)
struct timeval end_time; struct timeval end_time;
char ping_buf[TCP_PING_PACKSIZE]; char ping_buf[TCP_PING_PACKSIZE];
int bytes_read; int bytes_read;
struct addrinfo hints, *res=NULL; struct addrinfo hints, *res = NULL;
char szPort[10]; char szPort[10];
int error; int error;
@@ -52,7 +52,8 @@ uerr_t tcp_ping(ping_t * ping_data)
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(ping_data->host, szPort, &hints, &res); error = getaddrinfo(ping_data->host, szPort, &hints, &res);
if (error) { if (error)
{
return ping_data->err = HOSTERR; return ping_data->err = HOSTERR;
} }
@@ -101,7 +102,8 @@ uerr_t tcp_ping(ping_t * ping_data)
if (errno == EINPROGRESS) if (errno == EINPROGRESS)
errno = ETIMEDOUT; errno = ETIMEDOUT;
} else if (status == 0) }
else if (status == 0)
errno = ETIMEDOUT, status = -1; errno = ETIMEDOUT, status = -1;
} }
@@ -113,16 +115,19 @@ uerr_t tcp_ping(ping_t * ping_data)
{ {
free(res); free(res);
return ping_data->err = CONREFUSED; return ping_data->err = CONREFUSED;
} else if (errno == ETIMEDOUT) }
else if (errno == ETIMEDOUT)
{ {
free(res); free(res);
return ping_data->err = PINGTIMEOUT; return ping_data->err = PINGTIMEOUT;
} else }
else
{ {
free(res); free(res);
return ping_data->err = CONERROR; return ping_data->err = CONERROR;
} }
} else }
else
{ {
flags = fcntl(ping_data->sock, F_GETFL, 0); 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) void proz_mass_ping(ftps_request_t * request)
{ {
request->mass_ping_running = TRUE; request->mass_ping_running = TRUE;
if (pthread_create(&request->mass_ping_thread, NULL, if (pthread_create(&request->mass_ping_thread, NULL,
(void *) &mass_ping, (void *) request) != 0) (void *)&mass_ping, (void *)request) != 0)
proz_die(_("Error: Not enough system resources")); proz_die(_("Error: Not enough system resources"));
} }
void proz_cancel_mass_ping(ftps_request_t * request) void proz_cancel_mass_ping(ftps_request_t * request)
@@ -185,7 +188,7 @@ void proz_cancel_mass_ping(ftps_request_t * request)
/*TODO Rewrite so that this will terminate the pingin threads as well */ /*TODO Rewrite so that this will terminate the pingin threads as well */
request->mass_ping_running = FALSE; request->mass_ping_running = FALSE;
pthread_cancel(request->mass_ping_thread); pthread_cancel(request->mass_ping_thread);
pthread_join(request->mass_ping_thread,0); pthread_join(request->mass_ping_thread, 0);
} }
void mass_ping(ftps_request_t * request) void mass_ping(ftps_request_t * request)
@@ -198,7 +201,7 @@ void mass_ping(ftps_request_t * request)
simul_pings = request->max_simul_pings; simul_pings = request->max_simul_pings;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
ping_threads = (pthread_t *) kmalloc(sizeof(pthread_t) * simul_pings); ping_threads = (pthread_t *)kmalloc(sizeof(pthread_t) * simul_pings);
ping_requests = kmalloc(sizeof(ping_t) * request->num_mirrors); ping_requests = kmalloc(sizeof(ping_t) * request->num_mirrors);
num_iter = request->num_mirrors / simul_pings; num_iter = request->num_mirrors / simul_pings;
@@ -227,8 +230,8 @@ void mass_ping(ftps_request_t * request)
ping_requests[k].port = 21; ping_requests[k].port = 21;
if (pthread_create(&ping_threads[j], NULL, if (pthread_create(&ping_threads[j], NULL,
(void *) &tcp_ping, (void *)&tcp_ping,
(void *) (ping_requests + k)) != 0) (void *)(ping_requests + k)) != 0)
proz_die("Error: Not enough system resources" proz_die("Error: Not enough system resources"
"to create thread!\n"); "to create thread!\n");
k++; k++;
@@ -248,7 +251,8 @@ void mass_ping(ftps_request_t * request)
(ping_requests[k].ping_time.tv_usec / 1000); (ping_requests[k].ping_time.tv_usec / 1000);
request->mirrors[k].status = RESPONSEOK; request->mirrors[k].status = RESPONSEOK;
pthread_mutex_unlock(&request->access_mutex); pthread_mutex_unlock(&request->access_mutex);
} else }
else
{ {
pthread_mutex_lock(&request->access_mutex); pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].status = NORESPONSE; request->mirrors[k].status = NORESPONSE;
@@ -271,8 +275,8 @@ void mass_ping(ftps_request_t * request)
ping_requests[k].port = 21; ping_requests[k].port = 21;
if (pthread_create(&ping_threads[j], NULL, if (pthread_create(&ping_threads[j], NULL,
(void *) &tcp_ping, (void *)&tcp_ping,
(void *) (&ping_requests[k])) != 0) (void *)(&ping_requests[k])) != 0)
proz_die("Error: Not enough system resources" "to create thread!\n"); proz_die("Error: Not enough system resources" "to create thread!\n");
k++; k++;
@@ -295,7 +299,8 @@ void mass_ping(ftps_request_t * request)
(ping_requests[k].ping_time.tv_usec / 1000); (ping_requests[k].ping_time.tv_usec / 1000);
request->mirrors[k].status = RESPONSEOK; request->mirrors[k].status = RESPONSEOK;
pthread_mutex_unlock(&request->access_mutex); pthread_mutex_unlock(&request->access_mutex);
} else }
else
{ {
pthread_mutex_lock(&request->access_mutex); pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].status = NORESPONSE; request->mirrors[k].status = NORESPONSE;

View File

@@ -19,7 +19,7 @@
/* Main include-file. */ /* Main include-file. */
/* $Id: prozilla.h,v 1.63 2005/09/19 15:25:48 kalum Exp $ */ /* $Id$ */
#ifndef PROZILLA_H #ifndef PROZILLA_H
@@ -34,7 +34,7 @@
extern "C" { extern "C" {
#endif #endif
typedef enum { typedef enum {
/*Connect establishment related values */ /*Connect establishment related values */
NOCONERROR, HOSTERR, CONSOCKERR, CONERROR, NOCONERROR, HOSTERR, CONSOCKERR, CONERROR,
CONREFUSED, ACCEPTERR, ACCEPTOK, BINDERR, BINDOK, LISTENERR, LISTENOK, CONREFUSED, ACCEPTERR, ACCEPTOK, BINDERR, BINDOK, LISTENERR, LISTENOK,
@@ -82,7 +82,7 @@ extern "C" {
MIRINFOK, MIRPARSEOK, MIRPARSEFAIL, FILEGETOK, MIRINFOK, MIRPARSEOK, MIRPARSEFAIL, FILEGETOK,
/*Related to file joining */ /*Related to file joining */
JOININPROGRESS, JOINDONE, JOINERR JOININPROGRESS, JOINDONE, JOINERR
} uerr_t; } uerr_t;
#define FTP_BUFFER_SIZE 2048 #define FTP_BUFFER_SIZE 2048
@@ -105,14 +105,14 @@ extern "C" {
#define DEFAULT_USER_AGENT "Prozilla" #define DEFAULT_USER_AGENT "Prozilla"
typedef char longstring[1024]; typedef char longstring[1024];
/* Callback message function. */ /* Callback message function. */
typedef void (*message_proc) (const char *msg, void *cb_data); typedef void (*message_proc)(const char *msg, void *cb_data);
/* Structure containing info on a URL. */ /* Structure containing info on a URL. */
typedef struct _urlinfo { typedef struct _urlinfo {
char *url; /* Unchanged URL. */ char *url; /* Unchanged URL. */
uerr_t proto; /* URL protocol. */ uerr_t proto; /* URL protocol. */
char *host; /* Extracted hostname. */ char *host; /* Extracted hostname. */
@@ -123,9 +123,9 @@ extern "C" {
char *referer; /* The source from which the request char *referer; /* The source from which the request
URI was obtained. */ URI was obtained. */
} urlinfo; } urlinfo;
typedef enum { typedef enum {
USERatSITE, USERatSITE,
USERatPROXYUSERatSITE, USERatPROXYUSERatSITE,
USERatSITE_PROXYUSER, USERatSITE_PROXYUSER,
@@ -136,10 +136,10 @@ extern "C" {
HTTPPROXY, HTTPPROXY,
FTPGATE, FTPGATE,
WINGATE WINGATE
} proxy_type; } proxy_type;
typedef enum { typedef enum {
IDLE = 0, IDLE = 0,
CONNECTING, CONNECTING,
LOGGININ, LOGGININ,
@@ -151,19 +151,19 @@ extern "C" {
LOCALFATAL, LOCALFATAL,
TIMEDOUT, TIMEDOUT,
MAXTRYS MAXTRYS
} dl_status; } dl_status;
typedef enum { typedef enum {
NOT_FOUND, NOT_FOUND,
REGULAR_FILE, REGULAR_FILE,
DIRECTORY, DIRECTORY,
SYMBOLIC_LINK, SYMBOLIC_LINK,
UNKNOWN UNKNOWN
} file_type_t; } file_type_t;
typedef struct { typedef struct {
off_t len; /* Received length. */ off_t len; /* Received length. */
off_t contlen; /* Expected length. */ off_t contlen; /* Expected length. */
int res; /* The result of last read. */ int res; /* The result of last read. */
@@ -177,17 +177,17 @@ extern "C" {
char *remote_time; /* Remote time-stamp string. */ char *remote_time; /* Remote time-stamp string. */
char *error; /* Textual HTTP error. */ char *error; /* Textual HTTP error. */
int statcode; /* Status code. */ int statcode; /* Status code. */
} http_stat_t; } http_stat_t;
typedef struct { typedef struct {
urlinfo proxy_url; urlinfo proxy_url;
char *username; char *username;
char *passwd; char *passwd;
proxy_type type; proxy_type type;
boolean use_proxy; boolean use_proxy;
} proxy_info; } proxy_info;
typedef struct libprozinfo { typedef struct libprozinfo {
int argc; int argc;
char **argv; char **argv;
boolean debug_mode; boolean debug_mode;
@@ -211,19 +211,18 @@ extern "C" {
struct timeval conn_retry_delay; struct timeval conn_retry_delay;
int max_attempts; int max_attempts;
long max_bps_per_dl; long max_bps_per_dl;
} libprozinfo; } libprozinfo;
extern libprozinfo libprozrtinfo; extern libprozinfo libprozrtinfo;
typedef struct response_line { typedef struct response_line {
char *line; char *line;
struct response_line *next; struct response_line *next;
} response_line; } response_line;
typedef struct connection_t { typedef struct connection_t {
/* struct which contains the parsed url info. It includes the remote file, /* struct which contains the parsed url info. It includes the remote file,
path,protocol etc. */ path,protocol etc. */
urlinfo u; urlinfo u;
@@ -336,24 +335,24 @@ extern "C" {
long rate_bps; long rate_bps;
/*We limit the connections speed to this */ /*We limit the connections speed to this */
long max_allowed_bps; long max_allowed_bps;
} connection_t; } connection_t;
typedef enum { typedef enum {
UNTESTED = 0, RESPONSEOK, NORESPONSE, ERROR UNTESTED = 0, RESPONSEOK, NORESPONSE, ERROR
} ftp_mirror_stat_t; } ftp_mirror_stat_t;
typedef enum { typedef enum {
LYCOS, FILESEARCH_RU LYCOS, FILESEARCH_RU
} ftpsearch_server_type_t; } ftpsearch_server_type_t;
typedef struct { typedef struct {
char *path; char *path;
boolean valid; boolean valid;
} mirror_path_t; } mirror_path_t;
typedef struct ftp_mirror { typedef struct ftp_mirror {
char *server_name; char *server_name;
mirror_path_t *paths; mirror_path_t *paths;
char *file_name; char *file_name;
@@ -366,9 +365,9 @@ extern "C" {
int copied; int copied;
boolean resume_supported; boolean resume_supported;
int max_simul_connections; int max_simul_connections;
} ftp_mirror_t; } ftp_mirror_t;
typedef struct { typedef struct {
off_t file_size; off_t file_size;
char *file_name; char *file_name;
connection_t *connection; connection_t *connection;
@@ -384,10 +383,10 @@ extern "C" {
int max_simul_pings; int max_simul_pings;
struct timeval ping_timeout; struct timeval ping_timeout;
urlinfo *requested_url; urlinfo *requested_url;
} ftps_request_t; } ftps_request_t;
typedef struct download_t { typedef struct download_t {
urlinfo u; urlinfo u;
char *dl_dir; char *dl_dir;
char *log_dir; char *log_dir;
@@ -422,10 +421,10 @@ extern "C" {
ftps_request_t *ftps_info; ftps_request_t *ftps_info;
boolean using_ftpsearch; boolean using_ftpsearch;
pthread_t join_thread; pthread_t join_thread;
} download_t; } download_t;
typedef struct { typedef struct {
/* the number of connections that this download was started with */ /* the number of connections that this download was started with */
int num_connections; int num_connections;
/*I have added these newly */ /*I have added these newly */
@@ -436,134 +435,134 @@ extern "C" {
int url_len; /*The length in bytes of the url text stred in the log file */ int url_len; /*The length in bytes of the url text stred in the log file */
char *url; char *url;
int reserved[30]; int reserved[30];
} logfile; } logfile;
/*Structs for logfile handling */ /*Structs for logfile handling */
typedef struct { typedef struct {
char *host; char *host;
int port; int port;
struct timeval timeout; struct timeval timeout;
struct timeval ping_time; struct timeval ping_time;
int sock; int sock;
uerr_t err; uerr_t err;
} ping_t; } ping_t;
/*Functions for URL parsing */ /*Functions for URL parsing */
uerr_t proz_parse_url(const char *url, urlinfo * u, boolean strict); uerr_t proz_parse_url(const char *url, urlinfo * u, boolean strict);
urlinfo *proz_copy_url(urlinfo * u); urlinfo *proz_copy_url(urlinfo * u);
void proz_free_url(urlinfo * u, boolean complete); void proz_free_url(urlinfo * u, boolean complete);
/*Functions that set values which will apply for all conenctions. */ /*Functions that set values which will apply for all conenctions. */
int proz_init(int argc, char **argv); int proz_init(int argc, char **argv);
void proz_shutdown(void); void proz_shutdown(void);
void proz_die(const char *message, ...); void proz_die(const char *message, ...);
void proz_set_http_proxy(proxy_info * proxy); void proz_set_http_proxy(proxy_info * proxy);
void proz_set_ftp_proxy(proxy_info * proxy); void proz_set_ftp_proxy(proxy_info * proxy);
void proz_use_ftp_proxy(boolean use); void proz_use_ftp_proxy(boolean use);
void proz_use_http_proxy(boolean use); void proz_use_http_proxy(boolean use);
void proz_set_connection_timeout(struct timeval *timeout); void proz_set_connection_timeout(struct timeval *timeout);
void proz_set_connection_retry_delay(struct timeval *delay); void proz_set_connection_retry_delay(struct timeval *delay);
void proz_set_download_dir(char *dir); void proz_set_download_dir(char *dir);
void proz_set_logfile_dir(char *dir); void proz_set_logfile_dir(char *dir);
void proz_set_output_dir(char *dir); void proz_set_output_dir(char *dir);
char *proz_get_libprozilla_version(); char *proz_get_libprozilla_version();
/*Functions for loggind debug messages */ /*Functions for loggind debug messages */
void proz_debug(const char *format, ...); void proz_debug(const char *format, ...);
void proz_debug_delete_log(); void proz_debug_delete_log();
/*Functions which are for handling a single connection. */ /*Functions which are for handling a single connection. */
connection_t * proz_connection_init(urlinfo * url, pthread_mutex_t * mutex); connection_t * proz_connection_init(urlinfo * url, pthread_mutex_t * mutex);
void proz_connection_set_url(connection_t * connection, urlinfo *url); void proz_connection_set_url(connection_t * connection, urlinfo *url);
char *proz_connection_get_status_string(connection_t * connection); char *proz_connection_get_status_string(connection_t * connection);
off_t proz_connection_get_total_bytes_got(connection_t * connection); off_t proz_connection_get_total_bytes_got(connection_t * connection);
void proz_get_url_info_loop(connection_t * connection, pthread_t *thread); void proz_get_url_info_loop(connection_t * connection, pthread_t *thread);
off_t proz_connection_get_total_remote_bytes_got(connection_t * off_t proz_connection_get_total_remote_bytes_got(connection_t *
connection); connection);
void proz_connection_set_msg_proc(connection_t * connection, void proz_connection_set_msg_proc(connection_t * connection,
message_proc msg_proc, void *cb_data); message_proc msg_proc, void *cb_data);
void proz_connection_free_connection(connection_t * connection, void proz_connection_free_connection(connection_t * connection,
boolean complete); boolean complete);
dl_status proz_connection_get_status(connection_t * connection); dl_status proz_connection_get_status(connection_t * connection);
boolean proz_connection_running(connection_t * connection); boolean proz_connection_running(connection_t * connection);
/*Functions which are for handling a download */ /*Functions which are for handling a download */
download_t *proz_download_init(urlinfo * u); download_t *proz_download_init(urlinfo * u);
int proz_download_setup_connections_no_ftpsearch(download_t * download, int proz_download_setup_connections_no_ftpsearch(download_t * download,
connection_t * connection_t *
connection, connection,
int req_connections); int req_connections);
void proz_download_start_downloads(download_t * download, void proz_download_start_downloads(download_t * download,
boolean resume); boolean resume);
int proz_download_load_resume_info(download_t * download); int proz_download_load_resume_info(download_t * download);
void proz_download_stop_downloads(download_t * download); void proz_download_stop_downloads(download_t * download);
boolean proz_download_all_dls_status(download_t * download, boolean proz_download_all_dls_status(download_t * download,
dl_status status); dl_status status);
boolean proz_download_all_dls_err(download_t * download, uerr_t err); boolean proz_download_all_dls_err(download_t * download, uerr_t err);
boolean proz_download_all_dls_filensfod(download_t * download); boolean proz_download_all_dls_filensfod(download_t * download);
boolean proz_download_all_dls_ftpcwdfail(download_t * download); boolean proz_download_all_dls_ftpcwdfail(download_t * download);
off_t proz_download_get_total_bytes_got(download_t * download); off_t proz_download_get_total_bytes_got(download_t * download);
uerr_t proz_download_handle_threads(download_t * download); uerr_t proz_download_handle_threads(download_t * download);
int proz_download_prev_download_exists(download_t * download); int proz_download_prev_download_exists(download_t * download);
float proz_download_get_average_speed(download_t * download); float proz_download_get_average_speed(download_t * download);
int proz_download_delete_dl_file(download_t * download); int proz_download_delete_dl_file(download_t * download);
void proz_download_wait_till_all_end(download_t * download); void proz_download_wait_till_all_end(download_t * download);
off_t proz_download_get_total_remote_bytes_got(download_t * download); off_t proz_download_get_total_remote_bytes_got(download_t * download);
void proz_download_set_msg_proc(download_t * download, void proz_download_set_msg_proc(download_t * download,
message_proc msg_proc, void *cb_data); message_proc msg_proc, void *cb_data);
off_t proz_download_get_est_time_left(download_t * download); off_t proz_download_get_est_time_left(download_t * download);
void proz_download_free_download(download_t * download, void proz_download_free_download(download_t * download,
boolean complete); boolean complete);
int proz_download_target_exist(download_t * download); int proz_download_target_exist(download_t * download);
int proz_download_delete_target(download_t * download); int proz_download_delete_target(download_t * download);
/* Functions related to handling the logfile created for a download */ /* Functions related to handling the logfile created for a download */
int proz_log_read_logfile(logfile * lf, download_t * download, int proz_log_read_logfile(logfile * lf, download_t * download,
boolean load_con_info); boolean load_con_info);
int proz_log_delete_logfile(download_t * download); int proz_log_delete_logfile(download_t * download);
int proz_log_logfile_exists(download_t * download); int proz_log_logfile_exists(download_t * download);
char *proz_strerror(uerr_t error); char *proz_strerror(uerr_t error);
/*Ftpsearch releated */ /*Ftpsearch releated */
ftps_request_t * proz_ftps_request_init( ftps_request_t * proz_ftps_request_init(
urlinfo * requested_url, off_t file_size, urlinfo * requested_url, off_t file_size,
char *ftps_loc, char *ftps_loc,
ftpsearch_server_type_t server_type, ftpsearch_server_type_t server_type,
int num_req_mirrors); int num_req_mirrors);
void proz_get_complete_mirror_list(ftps_request_t * request); void proz_get_complete_mirror_list(ftps_request_t * request);
boolean proz_request_info_running(ftps_request_t * request); boolean proz_request_info_running(ftps_request_t * request);
boolean proz_request_mass_ping_running(ftps_request_t * request); boolean proz_request_mass_ping_running(ftps_request_t * request);
void proz_mass_ping(ftps_request_t * request); void proz_mass_ping(ftps_request_t * request);
void proz_sort_mirror_list(ftp_mirror_t * mirrors, int num_servers); void proz_sort_mirror_list(ftp_mirror_t * mirrors, int num_servers);
void proz_cancel_mirror_list_request(ftps_request_t * request); void proz_cancel_mirror_list_request(ftps_request_t * request);
int proz_download_setup_connections_ftpsearch(download_t * download, int proz_download_setup_connections_ftpsearch(download_t * download,
connection_t * connection, connection_t * connection,
ftps_request_t * request, ftps_request_t * request,
int req_connections); int req_connections);
void proz_cancel_mass_ping(ftps_request_t * request); void proz_cancel_mass_ping(ftps_request_t * request);
/*Misc functions */ /*Misc functions */
int proz_timeval_subtract(struct timeval *result, struct timeval *x, int proz_timeval_subtract(struct timeval *result, struct timeval *x,
struct timeval *y); struct timeval *y);
/*Funcs related to joining the downloaded file portions */ /*Funcs related to joining the downloaded file portions */
void proz_download_join_downloads(download_t * download); void proz_download_join_downloads(download_t * download);
uerr_t proz_download_get_join_status(download_t *download); uerr_t proz_download_get_join_status(download_t *download);
float proz_download_get_file_build_percentage(download_t *download); float proz_download_get_file_build_percentage(download_t *download);
void proz_download_cancel_joining_thread(download_t * download); void proz_download_cancel_joining_thread(download_t * download);
void proz_download_wait_till_end_joining_thread(download_t * download); void proz_download_wait_till_end_joining_thread(download_t * download);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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

View File

@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 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" #include "common.h"
@@ -82,8 +82,8 @@ char *protostrings[] = {
/* Similar to former, but for supported protocols: */ /* Similar to former, but for supported protocols: */
proto_t sup_protos[] = { proto_t sup_protos[] = {
{"http://", URLHTTP, DEFAULT_HTTP_PORT}, { "http://", URLHTTP, DEFAULT_HTTP_PORT },
{"ftp://", URLFTP, DEFAULT_FTP_PORT} { "ftp://", URLFTP, DEFAULT_FTP_PORT }
/* { "file://", URLFILE, DEFAULT_FTP_PORT } */ /* { "file://", URLFILE, DEFAULT_FTP_PORT } */
}; };
@@ -98,7 +98,7 @@ enum {
#define R urlchr_reserved #define R urlchr_reserved
#define U urlchr_unsafe #define U urlchr_unsafe
#define RU R|U #define RU R | U
#define urlchr_test(c, mask) (urlchr_table[(unsigned char)(c)] & (mask)) #define urlchr_test(c, mask) (urlchr_table[(unsigned char)(c)] & (mask))
@@ -129,7 +129,7 @@ enum {
always in upper case. */ always in upper case. */
#define XDIGIT_TO_XCHAR(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A')) #define XDIGIT_TO_XCHAR(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A'))
#define ARRAY_SIZE(array) (sizeof (array) / sizeof (*(array))) #define ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array)))
const static unsigned char urlchr_table[256] = { const static unsigned char urlchr_table[256] = {
U, U, U, U, U, U, U, U, /* NUL SOH STX ETX EOT ENQ ACK BEL */ U, U, U, U, U, U, U, U, /* NUL SOH STX ETX EOT ENQ ACK BEL */
@@ -181,6 +181,7 @@ int skip_uname(const char *url)
{ {
const char *p; const char *p;
const char *q = NULL; const char *q = NULL;
for (p = url; *p && *p != '/'; p++) for (p = url; *p && *p != '/'; p++)
if (*p == '@') if (*p == '@')
q = p; q = p;
@@ -208,9 +209,10 @@ void decode_string(char *s)
if (*h != '%') if (*h != '%')
// if(1) // if(1)
{ {
copychar: copychar:
*t = *h; *t = *h;
} else }
else
{ {
/* Do nothing if '%' is not followed by two hex digits. */ /* Do nothing if '%' is not followed by two hex digits. */
if (!*(h + 1) || !*(h + 2) if (!*(h + 1) || !*(h + 2)
@@ -231,32 +233,35 @@ char *encode_string_maybe(const char *s)
char *p2, *newstr; char *p2, *newstr;
int newlen; int newlen;
int addition = 0; int addition = 0;
/*Changes Grendel: (*p1!='%') added */ /*Changes Grendel: (*p1!='%') added */
for (p1 = s; *p1; p1++) for (p1 = s; *p1; p1++)
if ((*p1!='%') && UNSAFE_CHAR(*p1)) if ((*p1 != '%') && UNSAFE_CHAR(*p1))
addition += 2; /* Two more characters (hex digits) */ addition += 2;
/* Two more characters (hex digits) */
if (!addition) if (!addition)
return (char *) s; return (char *)s;
newlen = (p1 - s) + addition; newlen = (p1 - s) + addition;
newstr = (char *) kmalloc(newlen + 1); newstr = (char *)kmalloc(newlen + 1);
p1 = s; p1 = s;
p2 = newstr; p2 = newstr;
while (*p1) while (*p1)
{ {
// if (UNSAFE_CHAR(*p1)) // if (UNSAFE_CHAR(*p1))
if ((*p1!='%') && UNSAFE_CHAR(*p1)) if ((*p1 != '%') && UNSAFE_CHAR(*p1))
/* if(0)*/ /* if(0)*/
{ {
const unsigned char c = *p1++; const unsigned char c = *p1++;
*p2++ = '%'; *p2++ = '%';
*p2++ = XDIGIT_TO_XCHAR(c >> 4); *p2++ = XDIGIT_TO_XCHAR(c >> 4);
*p2++ = XDIGIT_TO_XCHAR(c & 0xf); *p2++ = XDIGIT_TO_XCHAR(c & 0xf);
} else }
else
*p2++ = *p1++; *p2++ = *p1++;
} }
*p2 = '\0'; *p2 = '\0';
@@ -283,14 +288,14 @@ char *encode_string(const char *s)
allocated storage. */ allocated storage. */
#define ENCODE(ptr) do { \ #define ENCODE(ptr) do { \
char *e_new = encode_string_maybe (ptr); \ char *e_new = encode_string_maybe(ptr); \
if (e_new != ptr) \ if (e_new != ptr) \
{ \ { \
kfree (ptr); \ kfree(ptr); \
ptr = e_new; \ ptr = e_new; \
} \ } \
} while (0) } while (0)
/* Returns the protocol type if URL's protocol is supported, or /* Returns the protocol type if URL's protocol is supported, or
URLUNKNOWN if not. */ URLUNKNOWN if not. */
uerr_t urlproto(const char *url) 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++) for (i = 0; i < ARRAY_SIZE(sup_protos); i++)
if (!strncasecmp(url, sup_protos[i].name, strlen(sup_protos[i].name))) if (!strncasecmp(url, sup_protos[i].name, strlen(sup_protos[i].name)))
return sup_protos[i].ind; 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] == ':') if (url[i] == ':')
{ {
for (++i; url[i] && url[i] != '/'; i++) for (++i; url[i] && url[i] != '/'; i++)
@@ -310,7 +316,8 @@ uerr_t urlproto(const char *url)
return URLFTP; return URLFTP;
else else
return URLHTTP; return URLHTTP;
} else }
else
return URLHTTP; return URLHTTP;
} }
@@ -324,7 +331,8 @@ char process_ftp_type(char *path)
{ {
path[len - 7] = '\0'; path[len - 7] = '\0';
return path[len - 1]; return path[len - 1];
} else }
else
return '\0'; return '\0';
} }
@@ -367,7 +375,8 @@ void path_simplify(char *path)
{ {
i += 3; i += 3;
ddot = 1; ddot = 1;
} else }
else
break; break;
} }
if (i) if (i)
@@ -410,7 +419,7 @@ void path_simplify(char *path)
/* Check for trailing `/'. */ /* Check for trailing `/'. */
if (start && !path[i]) if (start && !path[i])
{ {
zero_last: zero_last:
path[--i] = '\0'; path[--i] = '\0';
break; break;
} }
@@ -433,7 +442,8 @@ void path_simplify(char *path)
/* Handle `../' or trailing `..' by itself. */ /* Handle `../' or trailing `..' by itself. */
if (path[i + 1] == '.' && (path[i + 2] == '/' || !path[i + 2])) 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); strcpy(path + start + 1, path + i + 2);
i = (start < 0) ? 0 : start; i = (start < 0) ? 0 : start;
continue; continue;
@@ -461,6 +471,7 @@ void path_simplify(char *path)
int urlpath_length(const char *url) int urlpath_length(const char *url)
{ {
const char *q = strchr(url, '?'); const char *q = strchr(url, '?');
if (q) if (q)
return q - url; return q - url;
return strlen(url); return strlen(url);
@@ -477,7 +488,8 @@ void parse_dir(const char *path, char **dir, char **file)
int i, l; int i, l;
l = urlpath_length(path); l = urlpath_length(path);
for (i = l; i && path[i] != '/'; i--); for (i = l; i && path[i] != '/'; i--)
;
if (!i && *path != '/') /* Just filename */ if (!i && *path != '/') /* Just filename */
{ {
@@ -486,31 +498,36 @@ void parse_dir(const char *path, char **dir, char **file)
*dir = strdupdelim(path, path + l); *dir = strdupdelim(path, path + l);
*file = kstrdup(path + l); /* normally empty, but could *file = kstrdup(path + l); /* normally empty, but could
contain ?... */ contain ?... */
} else }
else
{ {
*dir = kstrdup(""); /* This is required because of FTP */ *dir = kstrdup(""); /* This is required because of FTP */
*file = kstrdup(path); *file = kstrdup(path);
} }
} else if (!i) /* /filename */ }
else if (!i) /* /filename */
{ {
if (PD_DOTP(path + 1) || PD_DDOTP(path + 1)) if (PD_DOTP(path + 1) || PD_DDOTP(path + 1))
{ {
*dir = strdupdelim(path, path + l); *dir = strdupdelim(path, path + l);
*file = kstrdup(path + l); /* normally empty, but could *file = kstrdup(path + l); /* normally empty, but could
contain ?... */ contain ?... */
} else }
else
{ {
*dir = kstrdup("/"); *dir = kstrdup("/");
*file = kstrdup(path + 1); *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)) if (PD_DOTP(path + i + 1) || PD_DDOTP(path + i + 1))
{ {
*dir = strdupdelim(path, path + l); *dir = strdupdelim(path, path + l);
*file = kstrdup(path + l); /* normally empty, but could *file = kstrdup(path + l); /* normally empty, but could
contain ?... */ contain ?... */
} else }
else
{ {
*dir = strdupdelim(path, path + i); *dir = strdupdelim(path, path + i);
*file = kstrdup(path + i + 1); *file = kstrdup(path + i + 1);
@@ -568,7 +585,7 @@ static uerr_t parse_uname(const char *url, char **user, char **passwd)
{ {
if (*p == ':' && !*user) if (*p == ':' && !*user)
{ {
*user = (char *) kmalloc(p - url + 1); *user = (char *)kmalloc(p - url + 1);
memcpy(*user, url, p - url); memcpy(*user, url, p - url);
(*user)[p - url] = '\0'; (*user)[p - url] = '\0';
col = p + 1; col = p + 1;
@@ -578,7 +595,7 @@ static uerr_t parse_uname(const char *url, char **user, char **passwd)
} }
/* Decide whether you have only the username or both. */ /* Decide whether you have only the username or both. */
where = *user ? passwd : user; where = *user ? passwd : user;
*where = (char *) kmalloc(q - col + 1); *where = (char *)kmalloc(q - col + 1);
memcpy(*where, col, q - col); memcpy(*where, col, q - col);
(*where)[q - col] = '\0'; (*where)[q - col] = '\0';
return URLOK; return URLOK;
@@ -622,7 +639,7 @@ char *str_url(const urlinfo * u, int hide)
} }
if (u->proto == URLFTP && *dir == '/') if (u->proto == URLFTP && *dir == '/')
{ {
char *tmp = (char *) kmalloc(strlen(dir) + 3); char *tmp = (char *)kmalloc(strlen(dir) + 3);
/*sprintf (tmp, "%%2F%s", dir + 1); */ /*sprintf (tmp, "%%2F%s", dir + 1); */
tmp[0] = '%'; tmp[0] = '%';
tmp[1] = '2'; tmp[1] = '2';
@@ -638,7 +655,7 @@ char *str_url(const urlinfo * u, int hide)
lh = strlen(host); lh = strlen(host);
ld = strlen(dir); ld = strlen(dir);
lf = strlen(file); lf = strlen(file);
res = (char *) kmalloc(ln + lu + lp + lh + ld + lf + 20); /* safe sex */ res = (char *)kmalloc(ln + lu + lp + lh + ld + lf + 20); /* safe sex */
/* sprintf (res, "%s%s%s%s%s%s:%d/%s%s%s", proto_name, /* sprintf (res, "%s%s%s%s%s%s:%d/%s%s%s", proto_name,
(user ? user : ""), (passwd ? ":" : ""), (user ? user : ""), (passwd ? ":" : ""),
(passwd ? passwd : ""), (user ? "@" : ""), (passwd ? passwd : ""), (user ? "@" : ""),
@@ -664,7 +681,7 @@ char *str_url(const urlinfo * u, int hide)
{ {
res[l++] = ':'; res[l++] = ':';
sprintf(res + l, "%ld", (long) u->port); sprintf(res + l, "%ld", (long)u->port);
l += numdigit(u->port); l += numdigit(u->port);
} }
@@ -735,7 +752,8 @@ uerr_t proz_parse_url(const char *url, urlinfo * u, int strict)
them for now). */ them for now). */
if (recognizable) if (recognizable)
l += skip_uname(url + l); 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) if (i == l)
return URLBADHOST; return URLBADHOST;
/* Get the hostname. */ /* Get the hostname. */
@@ -758,11 +776,13 @@ uerr_t proz_parse_url(const char *url, urlinfo * u, int strict)
return URLBADPORT; return URLBADPORT;
if (!u->port) if (!u->port)
return URLBADPORT; return URLBADPORT;
} else if (type == URLUNKNOWN) /* or a directory */ }
else if (type == URLUNKNOWN) /* or a directory */
u->proto = type = URLFTP; u->proto = type = URLFTP;
else /* or just a misformed port number */ else /* or just a misformed port number */
return URLBADPORT; return URLBADPORT;
} else if (type == URLUNKNOWN) }
else if (type == URLUNKNOWN)
u->proto = type = URLHTTP; u->proto = type = URLHTTP;
if (!u->port) if (!u->port)
{ {
@@ -780,7 +800,7 @@ uerr_t proz_parse_url(const char *url, urlinfo * u, int strict)
if (type == URLHTTP) if (type == URLHTTP)
while (url[i] && url[i] == '/') while (url[i] && url[i] == '/')
++i; ++i;
u->path = (char *) kmalloc(strlen(url + i) + 8); u->path = (char *)kmalloc(strlen(url + i) + 8);
strcpy(u->path, url + i); strcpy(u->path, url + i);
if (type == URLFTP) if (type == URLFTP)
{ {
@@ -868,7 +888,8 @@ char *construct_relative(const char *s1, const char *s2)
{ {
for (; for (;
s1[i] && s2[i] && s1[i] == s2[i] && s1[i] != '/' s1[i] && s2[i] && s1[i] == s2[i] && s1[i] != '/'
&& s2[i] != '/'; i++); && s2[i] != '/'; i++)
;
if (s1[i] == '/' && s2[i] == '/') if (s1[i] == '/' && s2[i] == '/')
cnt = ++i; cnt = ++i;
else else
@@ -913,8 +934,6 @@ urlpos *add_url(urlpos * l, const char *url, const char *file)
/*This will copy a url structure to another */ /*This will copy a url structure to another */
void url_cpy(urlinfo * src, urlinfo * dest) 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 '/') */ /* ^ ('?' gets changed to '/') */
start_insert = end + 1; start_insert = end + 1;
need_explicit_slash = 1; need_explicit_slash = 1;
} else if (last_slash && last_slash != base }
else if (last_slash && last_slash != base
&& *(last_slash - 1) == '/') && *(last_slash - 1) == '/')
{ {
/* example: http://host" */ /* example: http://host" */
/* ^ */ /* ^ */
start_insert = end + 1; start_insert = end + 1;
need_explicit_slash = 1; need_explicit_slash = 1;
} else }
else
{ {
/* example: "whatever/foo/bar" */ /* example: "whatever/foo/bar" */
/* ^ */ /* ^ */
@@ -998,7 +1019,7 @@ char *uri_merge_1(const char *base, const char *link, int linklength,
} }
span = start_insert - base; span = start_insert - base;
constr = (char *) kmalloc(span + linklength + 1); constr = (char *)kmalloc(span + linklength + 1);
if (span) if (span)
memcpy(constr, base, span); memcpy(constr, base, span);
if (need_explicit_slash) if (need_explicit_slash)
@@ -1006,7 +1027,8 @@ char *uri_merge_1(const char *base, const char *link, int linklength,
if (linklength) if (linklength)
memcpy(constr + span, link, linklength); memcpy(constr + span, link, linklength);
constr[span + linklength] = '\0'; constr[span + linklength] = '\0';
} else /* *link == `/' */ }
else /* *link == `/' */
{ {
/* LINK is an absolute path: we need to replace everything /* LINK is an absolute path: we need to replace everything
after (and including) the FIRST slash with LINK. after (and including) the FIRST slash with LINK.
@@ -1021,7 +1043,7 @@ char *uri_merge_1(const char *base, const char *link, int linklength,
int seen_slash_slash = 0; int seen_slash_slash = 0;
/* We're looking for the first slash, but want to ignore /* We're looking for the first slash, but want to ignore
double slash. */ double slash. */
again: again:
slash = memchr(pos, '/', end - pos); slash = memchr(pos, '/', end - pos);
if (slash && !seen_slash_slash) if (slash && !seen_slash_slash)
if (*(slash + 1) == '/') if (*(slash + 1) == '/')
@@ -1055,14 +1077,15 @@ char *uri_merge_1(const char *base, const char *link, int linklength,
start_insert = slash; start_insert = slash;
span = start_insert - base; span = start_insert - base;
constr = (char *) kmalloc(span + linklength + 1); constr = (char *)kmalloc(span + linklength + 1);
if (span) if (span)
memcpy(constr, base, span); memcpy(constr, base, span);
if (linklength) if (linklength)
memcpy(constr + span, link, linklength); memcpy(constr + span, link, linklength);
constr[span + linklength] = '\0'; constr[span + linklength] = '\0';
} }
} else /* !no_proto */ }
else /* !no_proto */
{ {
constr = strdupdelim(link, link + linklength); constr = strdupdelim(link, link + linklength);
} }
@@ -1112,7 +1135,7 @@ urlinfo *proz_copy_url(urlinfo * u)
{ {
urlinfo *dest_url; urlinfo *dest_url;
dest_url = (urlinfo *) kmalloc(sizeof(urlinfo)); dest_url = (urlinfo *)kmalloc(sizeof(urlinfo));
memset(dest_url, 0, sizeof(urlinfo)); memset(dest_url, 0, sizeof(urlinfo));
if (u->url) if (u->url)

View File

@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 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 #ifndef URL_H
@@ -31,43 +31,43 @@ extern "C" {
#endif #endif
/* Structure containing info on a protocol. */ /* Structure containing info on a protocol. */
typedef struct proto { typedef struct proto {
char *name; char *name;
uerr_t ind; uerr_t ind;
unsigned short port; unsigned short port;
} proto_t; } proto_t;
enum uflags { enum uflags {
URELATIVE = 0x0001, /* Is URL relative? */ URELATIVE = 0x0001, /* Is URL relative? */
UNOPROTO = 0x0002, /* Is URL without a protocol? */ UNOPROTO = 0x0002, /* Is URL without a protocol? */
UABS2REL = 0x0004, /* Convert absolute to relative? */ UABS2REL = 0x0004, /* Convert absolute to relative? */
UREL2ABS = 0x0008 /* Convert relative to absolute? */ UREL2ABS = 0x0008 /* Convert relative to absolute? */
}; };
/* A structure that defines the whereabouts of a URL, i.e. its /* A structure that defines the whereabouts of a URL, i.e. its
position in an HTML document, etc. */ position in an HTML document, etc. */
typedef struct _urlpos { typedef struct _urlpos {
char *url; /* URL */ char *url; /* URL */
char *local_name; /* Local file to which it was saved. */ char *local_name; /* Local file to which it was saved. */
enum uflags flags; /* Various flags. */ enum uflags flags; /* Various flags. */
int pos, size; /* Rekative position in the buffer. */ int pos, size; /* Rekative position in the buffer. */
struct _urlpos *next; /* Next struct in list. */ struct _urlpos *next; /* Next struct in list. */
} urlpos; } urlpos;
int int
has_proto(const char *url); has_proto(const char *url);
int int
skip_uname(const char *url); skip_uname(const char *url);
void void
parse_dir(const char *path, char **dir, char **file); parse_dir(const char *path, char **dir, char **file);
void void
path_simplify(char *path); path_simplify(char *path);
char *uri_merge(const char *base, const char *link); char *uri_merge(const char *base, const char *link);
int int
urlpath_length(const char *url); urlpath_length(const char *url);
int int
skip_proto(const char *url); skip_proto(const char *url);
char *str_url(const urlinfo * u, int hide); char *str_url(const urlinfo * u, int hide);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
fltk prozilla - a front end for prozilla, a download accelerator library * fltk prozilla - a front end for prozilla, a download accelerator library
Copyright (C) 2001 Kalum Somaratna * Copyright (C) 2001 Kalum Somaratna
*
This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. * (at your option) any later version.
*
This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. * GNU General Public License for more details.
*
You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/ ******************************************************************************/
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
@@ -36,96 +36,96 @@
#include "interface.h" #include "interface.h"
void void
DL_Window::cleanup (boolean erase_dlparts) DL_Window::cleanup(boolean erase_dlparts)
{ {
/*handle cleanup */ /*handle cleanup */
if (status == DL_DOWNLOADING) if (status == DL_DOWNLOADING)
{ {
proz_download_stop_downloads (download); proz_download_stop_downloads(download);
if (erase_dlparts == TRUE) if (erase_dlparts == TRUE)
{ {
proz_download_delete_target (download); proz_download_delete_target(download);
proz_log_delete_logfile (download); proz_log_delete_logfile(download);
} }
} }
else if (status == DL_GETTING_INFO) else if (status == DL_GETTING_INFO)
{ {
/*terminate info thread */ /*terminate info thread */
pthread_cancel (info_thread); pthread_cancel(info_thread);
pthread_join (info_thread, NULL); pthread_join(info_thread, NULL);
} }
else if (status == DL_JOINING) else if (status == DL_JOINING)
{ {
/*terminate joining thread */ /*terminate joining thread */
proz_download_cancel_joining_thread (download); proz_download_cancel_joining_thread(download);
pthread_join (download->join_thread, NULL); pthread_join(download->join_thread, NULL);
} }
else if (status == DL_FTPSEARCHING) else if (status == DL_FTPSEARCHING)
{ {
ftpsearch_win->cleanup (); ftpsearch_win->cleanup();
} }
status = DL_ABORTED; status = DL_ABORTED;
} }
DL_Window::~DL_Window ()
{
proz_connection_free_connection (connection, true);
delete (ftpsearch_win);
DL_Window::~DL_Window()
{
proz_connection_free_connection(connection, true);
delete (ftpsearch_win);
} }
DL_Window::DL_Window (urlinfo * url_data)
DL_Window::DL_Window(urlinfo *url_data)
{ {
// key = 0; // key = 0;
got_info = FALSE; got_info = FALSE;
got_dl = FALSE; got_dl = FALSE;
status = DL_IDLING; status = DL_IDLING;
memcpy (&u, url_data, sizeof (u)); memcpy(&u, url_data, sizeof(u));
memset (&update_time, 0, sizeof (struct timeval)); memset(&update_time, 0, sizeof(struct timeval));
num_connections = rt.num_connections; num_connections = rt.num_connections;
ftpsearch_win = new FTPS_Window (); ftpsearch_win = new FTPS_Window();
do_ftpsearch = FALSE; do_ftpsearch = FALSE;
using_ftpsearch = FALSE; using_ftpsearch = FALSE;
} }
void void
DL_Window::my_cb () DL_Window::my_cb()
{ {
if (status == DL_GETTING_INFO) if (status == DL_GETTING_INFO)
{ {
handle_info_thread (); handle_info_thread();
return; return;
} }
// if ((got_info == TRUE && status == DL_IDLING && got_dl == FALSE) // if ((got_info == TRUE && status == DL_IDLING && got_dl == FALSE)
if ((status == DL_RESTARTING && got_info == TRUE) if (((status == DL_RESTARTING) && (got_info == TRUE)) ||
|| status == DL_DLPRESTART) (status == DL_DLPRESTART))
{ {
do_download (); do_download();
} }
if (status == DL_DOWNLOADING) if (status == DL_DOWNLOADING)
{ {
handle_download_thread (); handle_download_thread();
return; return;
} }
if (status == DL_JOINING) if (status == DL_JOINING)
{ {
handle_joining_thread (); handle_joining_thread();
return; return;
} }
if (status == DL_FATALERR) if (status == DL_FATALERR)
{ {
handle_dl_fatal_error (); handle_dl_fatal_error();
return; return;
} }
@@ -136,45 +136,43 @@ DL_Window::my_cb ()
} }
if (status == DL_FTPSEARCHING) if (status == DL_FTPSEARCHING)
{ {
handle_ftpsearch (); handle_ftpsearch();
return; return;
} }
} }
void void
DL_Window::dl_start (int num_connections, boolean ftpsearch) DL_Window::dl_start(int num_connections, boolean ftpsearch)
{ {
do_ftpsearch = ftpsearch; do_ftpsearch = ftpsearch;
connection = proz_connection_init (&u, &getinfo_mutex); connection = proz_connection_init(&u, &getinfo_mutex);
proz_connection_set_msg_proc (connection, ms, this); proz_connection_set_msg_proc(connection, ms, this);
PrintMessage("Creating the thread that gets info about file..\n"); PrintMessage("Creating the thread that gets info about file..\n");
proz_get_url_info_loop (connection, &info_thread); proz_get_url_info_loop(connection, &info_thread);
status = DL_GETTING_INFO; status = DL_GETTING_INFO;
} }
void void
DL_Window::do_download () DL_Window::do_download()
{ {
logfile lf; logfile lf;
status = DL_DLPRESTART; status = DL_DLPRESTART;
//setup the download //setup the download
download = proz_download_init (&connection->u); download = proz_download_init(&connection->u);
proz_debug("proz_download_init complete"); proz_debug("proz_download_init complete");
handle_prev_download (); handle_prev_download();
if(status==DL_FATALERR) if (status == DL_FATALERR)
{ {
return; return;
} }
if(download->resume_mode ==TRUE) if (download->resume_mode == TRUE)
{ {
if (proz_log_read_logfile(&lf, download, FALSE) != 1) if (proz_log_read_logfile(&lf, download, FALSE) != 1)
{ {
@@ -193,45 +191,47 @@ DL_Window::do_download ()
} }
} }
if (rt.display_mode == DISP_CURSES) if (rt.display_mode == DISP_CURSES)
{
erase(); erase();
}
start_download (); start_download();
} }
void void
DL_Window::handle_prev_download () DL_Window::handle_prev_download()
{ {
int ret = 0; int ret = 0;
/* we will check and see if 1. previous partial download exists and /* we will check and see if 1. previous partial download exists and
2. if the file to be downloaded already exists in the local * 2. if the file to be downloaded already exists in the local
directory * directory
*/ */
//Check and see if the file is already downloaded.. //Check and see if the file is already downloaded..
//check the --no-getch flag //check the --no-getch flag
if (rt.dont_prompt != TRUE) if (rt.dont_prompt != TRUE)
{ {
int target_exists=proz_download_target_exist(download); int target_exists = proz_download_target_exist(download);
if(target_exists) if (target_exists)
{ {
ret=askUserOverwrite(connection); ret = askUserOverwrite(connection);
if(ret=='O') if (ret == 'O')
{ {
//just continue, it will anyway be overwritten by the download routines. //just continue, it will anyway be overwritten by the download routines.
} }
if(ret=='A') if (ret == 'A')
{ {
status = DL_FATALERR; status = DL_FATALERR;
return; return;
} }
} }
} }
/*Check for a prior download */ /*Check for a prior download */
int previous_dl = proz_download_prev_download_exists (download); int previous_dl = proz_download_prev_download_exists(download);
if (previous_dl == 1) if (previous_dl == 1)
{ {
download->resume_mode = TRUE; download->resume_mode = TRUE;
//connection supports resume //connection supports resume
if (connection->resume_support) if (connection->resume_support)
@@ -241,69 +241,84 @@ DL_Window::handle_prev_download ()
{ {
//see if the user had a preference, resume or overwrite //see if the user had a preference, resume or overwrite
if (rt.resume_mode == TRUE) if (rt.resume_mode == TRUE)
{
download->resume_mode = TRUE; download->resume_mode = TRUE;
}
else else
if (rt.force_mode == TRUE) if (rt.force_mode == TRUE)
{
download->resume_mode = FALSE; download->resume_mode = FALSE;
} }
}
else else
{ {
//ask the user (curses or terminal) //ask the user (curses or terminal)
ret = askUserResume(connection, true); ret = askUserResume(connection, true);
if (ret == 'R') if (ret == 'R')
{
download->resume_mode = TRUE; download->resume_mode = TRUE;
}
else else
{
download->resume_mode = FALSE; download->resume_mode = FALSE;
} }
} }
}
else else
{//resume NOT supported { //resume NOT supported
// --no-getch and no force-mode means fatal error!!! // --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; status = DL_FATALERR;
handle_dl_fatal_error (); handle_dl_fatal_error();
return; return;
} }
//force overwrite //force overwrite
if (rt.dont_prompt == TRUE && rt.force_mode == TRUE) if ((rt.dont_prompt == TRUE) && (rt.force_mode == TRUE))
{
download->resume_mode = FALSE; download->resume_mode = FALSE;
}
else else
{ {
//Ask the user //Ask the user
ret = askUserResume(connection, false); ret = askUserResume(connection, false);
if (ret == 'O') if (ret == 'O')
{
download->resume_mode = FALSE; download->resume_mode = FALSE;
}
else else
{ //Abort { //Abort
status = DL_FATALERR; status = DL_FATALERR;
handle_dl_fatal_error (); handle_dl_fatal_error();
return; return;
} }
} }
} }
} }
} }
void void
DL_Window::start_download () DL_Window::start_download()
{ {
int ret = 0; int ret = 0;
proz_debug("start_download"); proz_debug("start_download");
if (using_ftpsearch != TRUE) if (using_ftpsearch != TRUE)
{
ret = num_connections = ret = num_connections =
proz_download_setup_connections_no_ftpsearch proz_download_setup_connections_no_ftpsearch
(download, connection, num_connections); (download, connection, num_connections);
}
else else
ret = proz_download_setup_connections_ftpsearch (download, {
ret = proz_download_setup_connections_ftpsearch(download,
connection, connection,
ftpsearch_win-> ftpsearch_win->
request, request,
num_connections); num_connections);
}
if (ret == -1) if (ret == -1)
{ {
@@ -322,25 +337,24 @@ DL_Window::start_download ()
PrintMessage("RESUME NOT supported\n"); PrintMessage("RESUME NOT supported\n");
} }
gettimeofday (&update_time, NULL); gettimeofday(&update_time, NULL);
proz_download_start_downloads (download, download->resume_mode); proz_download_start_downloads(download, download->resume_mode);
status = DL_DOWNLOADING; status = DL_DOWNLOADING;
return;
} }
void void
DL_Window::handle_info_thread () DL_Window::handle_info_thread()
{ {
bool getting_info = proz_connection_running (connection); bool getting_info = proz_connection_running(connection);
if (getting_info == FALSE) if (getting_info == FALSE)
{ {
pthread_join (info_thread, NULL); pthread_join(info_thread, NULL);
if (connection->err == HOK || connection->err == FTPOK) if ((connection->err == HOK) || (connection->err == FTPOK))
{ {
got_info = TRUE; got_info = TRUE;
@@ -350,11 +364,13 @@ DL_Window::handle_info_thread ()
connection->main_file_size / 1024); connection->main_file_size / 1024);
} }
else else
{
PrintMessage("File Size is UNKOWN\n\n"); PrintMessage("File Size is UNKOWN\n\n");
}
//Added ftpsearch only is size > min size //Added ftpsearch only is size > min size
if ((connection->main_file_size != -1 if (((connection->main_file_size != -1) &&
&& do_ftpsearch == TRUE) && (connection->main_file_size / 1024 >= rt.min_search_size)) (do_ftpsearch == TRUE)) && (connection->main_file_size / 1024 >= rt.min_search_size))
{ {
status = DL_FTPSEARCHING; status = DL_FTPSEARCHING;
@@ -377,22 +393,21 @@ DL_Window::handle_info_thread ()
"http://ftpsearch.elmundo.es:8000/ftpsearch", "http://ftpsearch.elmundo.es:8000/ftpsearch",
LYCOS, rt.ftps_mirror_req_n); LYCOS, rt.ftps_mirror_req_n);
} }
} }
else 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"); PrintMessage("File size is less than the minimum, skipping ftpsearch");
do_download ();
} }
do_download();
}
} }
else else
{ {
if ((connection->err == FTPNSFOD) ||
if (connection->err == FTPNSFOD (connection->err == HTTPNSFOD))
|| connection->err == HTTPNSFOD)
{ {
PrintMessage("The URL %s doesnt exist!\n", PrintMessage("The URL %s doesnt exist!\n",
connection->u.url); connection->u.url);
@@ -408,35 +423,34 @@ DL_Window::handle_info_thread ()
got_info = FALSE; got_info = FALSE;
status = DL_FATALERR; status = DL_FATALERR;
} }
} }
} }
} }
void void
DL_Window::handle_ftpsearch () DL_Window::handle_ftpsearch()
{ {
uerr_t err; uerr_t err;
err = ftpsearch_win->callback ();
err = ftpsearch_win->callback();
if (err == MASSPINGDONE) if (err == MASSPINGDONE)
{ {
if (ftpsearch_win->request->num_mirrors == 0) if (ftpsearch_win->request->num_mirrors == 0)
{ {
using_ftpsearch = FALSE; using_ftpsearch = FALSE;
PrintMessage("No suitable mirrors were found, downloading from original server\n"); PrintMessage("No suitable mirrors were found, downloading from original server\n");
do_download (); do_download();
return; return;
} }
using_ftpsearch = TRUE; using_ftpsearch = TRUE;
do_download (); do_download();
return; return;
} }
if (err == FTPSFAIL) if (err == FTPSFAIL)
{ {
using_ftpsearch = FALSE; using_ftpsearch = FALSE;
do_download (); do_download();
return; return;
} }
@@ -451,37 +465,36 @@ DL_Window::handle_ftpsearch ()
{ {
using_ftpsearch = FALSE; using_ftpsearch = FALSE;
} }
do_download (); do_download();
} }
} }
void
DL_Window::handle_download_thread ()
{
void
DL_Window::handle_download_thread()
{
uerr_t err; uerr_t err;
struct timeval cur_time; struct timeval cur_time;
struct timeval diff_time; struct timeval diff_time;
err = proz_download_handle_threads (download); err = proz_download_handle_threads(download);
gettimeofday (&cur_time, NULL); gettimeofday(&cur_time, NULL);
proz_timeval_subtract (&diff_time, &cur_time, &update_time); proz_timeval_subtract(&diff_time, &cur_time, &update_time);
if ((((diff_time.tv_sec * 1000) + (diff_time.tv_usec / 1000)) > 200) if ((((diff_time.tv_sec * 1000) + (diff_time.tv_usec / 1000)) > 200) ||
|| err == DLDONE) (err == DLDONE))
{ {
print_status(download, rt.quiet_mode);
print_status (download, rt.quiet_mode);
if (download->main_file_size != -1) if (download->main_file_size != -1)
{ {
} }
/*The time of the current screen */ /*The time of the current screen */
gettimeofday (&update_time, NULL); gettimeofday(&update_time, NULL);
} }
if (err == DLDONE) if (err == DLDONE)
@@ -489,10 +502,10 @@ DL_Window::handle_download_thread ()
PrintMessage("Got DL succesfully, now renaming file\n"); PrintMessage("Got DL succesfully, now renaming file\n");
got_dl = TRUE; got_dl = TRUE;
PrintMessage ("Renaming file %s .....\n", PrintMessage("Renaming file %s .....\n",
download->u.file); download->u.file);
status = DL_JOINING; status = DL_JOINING;
proz_download_join_downloads (download); proz_download_join_downloads(download);
joining_thread_running = TRUE; joining_thread_running = TRUE;
} }
@@ -507,8 +520,7 @@ DL_Window::handle_download_thread ()
if (err == DLLOCALFATAL) 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",
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); connection->u.url);
got_dl = FALSE; got_dl = FALSE;
status = DL_FATALERR; status = DL_FATALERR;
@@ -517,41 +529,36 @@ DL_Window::handle_download_thread ()
if (err == DLREMOTEFATAL) if (err == DLREMOTEFATAL)
{ {
PrintMessage(_
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"), ("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); connection->u.url);
got_dl = FALSE; got_dl = FALSE;
status = DL_FATALERR; status = DL_FATALERR;
} }
} }
void void
DL_Window::handle_joining_thread () DL_Window::handle_joining_thread()
{ {
boolean bDone = false; boolean bDone = false;
uerr_t building_status = proz_download_get_join_status (download); uerr_t building_status = proz_download_get_join_status(download);
if (building_status == JOINERR) if (building_status == JOINERR)
{ {
if (joining_thread_running == TRUE) if (joining_thread_running == TRUE)
{ {
proz_download_wait_till_end_joining_thread (download); proz_download_wait_till_end_joining_thread(download);
joining_thread_running = FALSE; joining_thread_running = FALSE;
} }
} }
if (building_status == JOINDONE) if (building_status == JOINDONE)
{ {
if (joining_thread_running == TRUE) if (joining_thread_running == TRUE)
{ {
proz_download_wait_till_end_joining_thread (download); proz_download_wait_till_end_joining_thread(download);
joining_thread_running = FALSE; joining_thread_running = FALSE;
bDone = true; bDone = true;
} }
@@ -561,8 +568,8 @@ DL_Window::handle_joining_thread ()
{ {
PrintMessage("All Done.\n"); PrintMessage("All Done.\n");
//curses_query_user_input("Press any key to exit."); //curses_query_user_input("Press any key to exit.");
proz_download_delete_dl_file (download); proz_download_delete_dl_file(download);
proz_download_free_download (download, 0); proz_download_free_download(download, 0);
status = DL_IDLING; status = DL_IDLING;
} }
status = DL_DONE; status = DL_DONE;
@@ -571,44 +578,42 @@ DL_Window::handle_joining_thread ()
void void
DL_Window::handle_dl_fatal_error () DL_Window::handle_dl_fatal_error()
{ {
status = DL_FATALERR; status = DL_FATALERR;
cleanup (FALSE); cleanup(FALSE);
return;
} }
void
DL_Window::print_status (download_t * download, int quiet_mode)
{
void
DL_Window::print_status(download_t *download, int quiet_mode)
{
if (rt.display_mode == DISP_CURSES) if (rt.display_mode == DISP_CURSES)
{
DisplayCursesInfo(download); DisplayCursesInfo(download);
}
else else
{ {
if (quiet_mode == FALSE) if (quiet_mode == FALSE)
{ {
for (int i = 0; i < download->num_connections; i++) for (int i = 0; i < download->num_connections; i++)
{ {
fprintf(stdout,
fprintf (stdout,
"%2.2d %-30.30s %15.15s %10zd\n", "%2.2d %-30.30s %15.15s %10zd\n",
i + 1, download->pconnections[i]->u.host, i + 1, download->pconnections[i]->u.host,
proz_connection_get_status_string (download-> proz_connection_get_status_string(download->
pconnections pconnections
[i]), [i]),
proz_connection_get_total_bytes_got proz_connection_get_total_bytes_got
(download->pconnections[i])); (download->pconnections[i]));
} }
fprintf (stdout, "Total Bytes received %zd Kb\n", fprintf(stdout, "Total Bytes received %zd Kb\n",
proz_download_get_total_bytes_got (download) / 1024); proz_download_get_total_bytes_got(download) / 1024);
fprintf (stdout, "Average Speed = %.3f Kb/sec\n", fprintf(stdout, "Average Speed = %.3f Kb/sec\n",
proz_download_get_average_speed (download) / 1024); proz_download_get_average_speed(download) / 1024);
} }
@@ -616,40 +621,49 @@ DL_Window::print_status (download_t * download, int quiet_mode)
char timeLeft[30]; char timeLeft[30];
if ((secs_left = if ((secs_left =
proz_download_get_est_time_left (download)) != -1) proz_download_get_est_time_left(download)) != -1)
{ {
if (secs_left < 60) if (secs_left < 60)
snprintf (timeLeft, sizeof(timeLeft), "00:%.2d", secs_left); {
snprintf(timeLeft, sizeof(timeLeft), "00:%.2d", secs_left);
}
else if (secs_left < 3600) else if (secs_left < 3600)
snprintf (timeLeft, sizeof(timeLeft), "00:%.2d:%.2d", {
snprintf(timeLeft, sizeof(timeLeft), "00:%.2d:%.2d",
secs_left / 60, secs_left % 60); secs_left / 60, secs_left % 60);
}
else else
snprintf (timeLeft, sizeof(timeLeft), "%.2d:%.2d:00", {
snprintf(timeLeft, sizeof(timeLeft), "%.2d:%.2d:00",
secs_left / 3600, secs_left / 3600,
(secs_left % 3600) / 60); (secs_left % 3600) / 60);
} }
}
else else
sprintf (timeLeft, "??:??:??"); {
sprintf(timeLeft, "??:??:??");
}
off_t totalDownloaded = 0; off_t totalDownloaded = 0;
off_t totalFile = 0; off_t totalFile = 0;
long aveSpeed = 0; long aveSpeed = 0;
totalFile = download->main_file_size / 1024; totalFile = download->main_file_size / 1024;
totalDownloaded = totalDownloaded =
proz_download_get_total_bytes_got (download) / proz_download_get_total_bytes_got(download) /
1024; 1024;
aveSpeed = (long)(proz_download_get_average_speed (download) / 1024); aveSpeed = (long)(proz_download_get_average_speed(download) / 1024);
//WGET looks like this: //WGET looks like this:
//xx% [=======> ] nnn,nnn,nnn XXXX.XXK/s ETA hh:mm:ss //xx% [=======> ] nnn,nnn,nnn XXXX.XXK/s ETA hh:mm:ss
fprintf (stdout, " %.2lf%% %zdKb/%zdkb %0.3fKb/s ETA %s \r", fprintf(stdout, " %.2lf%% %zdKb/%zdkb %0.3fKb/s ETA %s \r",
((float)totalDownloaded) / ((float)totalFile / 100), ((float)totalDownloaded) / ((float)totalFile / 100),
totalDownloaded, totalFile, (float)aveSpeed, timeLeft); totalDownloaded, totalFile, (float)aveSpeed, timeLeft);
fflush (stdout); fflush(stdout);
} }
} }
int DL_Window::askUserResume(connection_t *connection, boolean resumeSupported) int DL_Window::askUserResume(connection_t *connection, boolean resumeSupported)
{ {
int ret = 0; int ret = 0;
@@ -657,38 +671,46 @@ 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?"; 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) if (rt.display_mode == DISP_CURSES)
ret = curses_query_user_input((resumeSupported == TRUE)?msg:msg2,connection->u.file); {
ret = curses_query_user_input((resumeSupported == TRUE) ? msg : msg2, connection->u.file);
}
else else
{ {
fprintf(stdout,"\n"); fprintf(stdout, "\n");
fprintf(stdout,(resumeSupported == TRUE)?msg:msg2,connection->u.file); fprintf(stdout, (resumeSupported == TRUE) ? msg : msg2, connection->u.file);
ret = getc(stdin); ret = getc(stdin);
ret = islower(ret) ? toupper(ret) : ret; ret = islower(ret) ? toupper(ret) : ret;
} }
switch(ret) switch (ret)
{ {
case 'O': case 'O':
break; break;
case 'A': case 'A':
if (resumeSupported == TRUE) if (resumeSupported == TRUE)
ret=0; {
ret = 0;
}
break; break;
case 'R': case 'R':
if (resumeSupported == FALSE) if (resumeSupported == FALSE)
ret=0; {
ret = 0;
}
break; break;
default: default:
ret=0; ret = 0;
break; break;
} }
} while (ret == 0); } while (ret == 0);
return ret; return(ret);
} }
@@ -698,29 +720,33 @@ 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?"; 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) if (rt.display_mode == DISP_CURSES)
ret = curses_query_user_input(msg,connection->u.file); {
ret = curses_query_user_input(msg, connection->u.file);
}
else else
{ {
fprintf(stdout,"\n"); fprintf(stdout, "\n");
fprintf(stdout,msg,connection->u.file); fprintf(stdout, msg, connection->u.file);
ret = getc(stdin); ret = getc(stdin);
ret = islower(ret) ? toupper(ret) : ret; ret = islower(ret) ? toupper(ret) : ret;
} }
switch(ret) switch (ret)
{ {
case 'O': case 'O':
break; break;
case 'A': case 'A':
break; break;
default: default:
ret=0; ret = 0;
break; break;
} }
} while (ret == 0); } while (ret == 0);
return ret; return(ret);
} }

View File

@@ -35,48 +35,47 @@ typedef enum {
} dlg_class; } dlg_class;
class DL_Window { class DL_Window {
public: public:
DL_Window(urlinfo * url_data); DL_Window(urlinfo * url_data);
~DL_Window(); ~DL_Window();
void dl_start(int num_connections, boolean ftpsearch); void dl_start(int num_connections, boolean ftpsearch);
void my_cb(); void my_cb();
void handle_info_thread(); void handle_info_thread();
void handle_ftpsearch(); void handle_ftpsearch();
void handle_download_thread(); void handle_download_thread();
void start_download(); void start_download();
void handle_joining_thread(); void handle_joining_thread();
void handle_dl_fatal_error(); void handle_dl_fatal_error();
void cleanup(boolean erase_dlparts); void cleanup(boolean erase_dlparts);
void print_status(download_t * download, int quiet_mode); void print_status(download_t * download, int quiet_mode);
connection_t *connection; connection_t *connection;
download_t *download; download_t *download;
urlinfo u; urlinfo u;
boolean got_info; boolean got_info;
boolean got_dl; boolean got_dl;
dlwin_status_t status; dlwin_status_t status;
pthread_t info_thread; pthread_t info_thread;
pthread_mutex_t getinfo_mutex; pthread_mutex_t getinfo_mutex;
int num_connections; int num_connections;
/*The time elapsed since the last update */ /*The time elapsed since the last update */
struct timeval update_time; struct timeval update_time;
private: private:
void do_download(); void do_download();
void handle_prev_download(); void handle_prev_download();
boolean joining_thread_running; boolean joining_thread_running;
boolean do_ftpsearch; boolean do_ftpsearch;
boolean using_ftpsearch; boolean using_ftpsearch;
FTPS_Window *ftpsearch_win; FTPS_Window *ftpsearch_win;
int askUserResume(connection_t *connection, boolean resumeSupported); int askUserResume(connection_t *connection, boolean resumeSupported);
int askUserOverwrite(connection_t *connection); int askUserOverwrite(connection_t *connection);
}; };
#endif #endif

View File

@@ -3,9 +3,9 @@
#define ftps_win_h #define ftps_win_h
#include "prozilla.h" #include "prozilla.h"
/* /*
class ftps_gui { class ftps_gui {
public: public:
ftps_gui(); ftps_gui();
}; };
*/ */
#endif #endif

View File

@@ -32,7 +32,7 @@
FTPS_Window::FTPS_Window () FTPS_Window::FTPS_Window ()
{ {
memset (&request, 0, sizeof (request)); memset(&request, 0, sizeof(request));
request_running = FALSE; request_running = FALSE;
ping_running = FALSE; ping_running = FALSE;
@@ -41,19 +41,19 @@ FTPS_Window::FTPS_Window ()
void void
FTPS_Window::fetch_mirror_info (urlinfo * u, off_t file_size, FTPS_Window::fetch_mirror_info(urlinfo * u, off_t file_size,
char *ftps_loc, char *ftps_loc,
ftpsearch_server_type_t server_type, ftpsearch_server_type_t server_type,
int num_req_mirrors) int num_req_mirrors)
{ {
assert (u->file); assert(u->file);
request = proz_ftps_request_init (u, file_size, ftps_loc, request = proz_ftps_request_init(u, file_size, ftps_loc,
server_type, num_req_mirrors); server_type, num_req_mirrors);
PrintMessage("Attempting to get %d mirrors from %s\n\n",num_req_mirrors, ftps_loc); PrintMessage("Attempting to get %d mirrors from %s\n\n", num_req_mirrors, ftps_loc);
//proz_connection_set_msg_proc (request->connection, //proz_connection_set_msg_proc (request->connection,
// ftps_win_message_proc, this); // ftps_win_message_proc, this);
proz_get_complete_mirror_list (request); proz_get_complete_mirror_list(request);
request_running = TRUE; request_running = TRUE;
} }
@@ -66,14 +66,13 @@ FTPS_Window::fetch_mirror_info (urlinfo * u, off_t file_size,
//} //}
uerr_t uerr_t
FTPS_Window::callback () FTPS_Window::callback()
{ {
if (request_running == TRUE) if (request_running == TRUE)
{ {
if (proz_request_info_running (request) == FALSE) if (proz_request_info_running(request) == FALSE)
{ {
pthread_join (request->info_thread, NULL); pthread_join(request->info_thread, NULL);
if (request->err != MIRINFOK) if (request->err != MIRINFOK)
{ {
request_running = FALSE; request_running = FALSE;
@@ -94,7 +93,7 @@ FTPS_Window::callback ()
//Launch the pinging thread //Launch the pinging thread
PrintMessage("Got mirror info, %d server(s) found\n", request->num_mirrors); PrintMessage("Got mirror info, %d server(s) found\n", request->num_mirrors);
proz_mass_ping (request); proz_mass_ping(request);
ping_running = TRUE; ping_running = TRUE;
return MASSPINGINPROGRESS; return MASSPINGINPROGRESS;
} }
@@ -103,14 +102,13 @@ FTPS_Window::callback ()
if (ping_running == TRUE) if (ping_running == TRUE)
{ {
print_status(request, rt.quiet_mode); print_status(request, rt.quiet_mode);
if (proz_request_mass_ping_running (request) == FALSE) if (proz_request_mass_ping_running(request) == FALSE)
{ {
ping_done = TRUE; ping_done = TRUE;
ping_running = FALSE; ping_running = FALSE;
proz_sort_mirror_list (request->mirrors, proz_sort_mirror_list(request->mirrors,
request->num_mirrors); request->num_mirrors);
// We have a seprate func to display this // We have a seprate func to display this
@@ -126,38 +124,37 @@ FTPS_Window::callback ()
void void
FTPS_Window::cleanup () FTPS_Window::cleanup()
{ {
if (request_running == TRUE) if (request_running == TRUE)
{ {
proz_cancel_mirror_list_request (request); proz_cancel_mirror_list_request(request);
return; return;
} }
if (ping_running == TRUE) if (ping_running == TRUE)
{ {
proz_cancel_mass_ping (request); proz_cancel_mass_ping(request);
return; return;
} }
} }
void void
cb_exit_ftpsearch (void *data) cb_exit_ftpsearch(void *data)
{ {
FTPS_Window *window = (FTPS_Window *)data;
FTPS_Window *window = (FTPS_Window *) data;
window->exit_ftpsearch_button_pressed = TRUE; window->exit_ftpsearch_button_pressed = TRUE;
if (window->request_running == TRUE) if (window->request_running == TRUE)
{ {
proz_cancel_mirror_list_request (window->request); proz_cancel_mirror_list_request(window->request);
} }
if (window->ping_running == TRUE) if (window->ping_running == TRUE)
{ {
proz_cancel_mass_ping (window->request); proz_cancel_mass_ping(window->request);
} }
} }
@@ -167,37 +164,38 @@ void FTPS_Window::print_status(ftps_request_t *request, int quiet_mode)
{ {
for (int i = 0; i < request->num_mirrors; i++) for (int i = 0; i < request->num_mirrors; i++)
{ {
pthread_mutex_lock (&request->access_mutex); pthread_mutex_lock(&request->access_mutex);
ftp_mirror_stat_t status = request->mirrors[i].status; ftp_mirror_stat_t status = request->mirrors[i].status;
pthread_mutex_unlock (&request->access_mutex); pthread_mutex_unlock(&request->access_mutex);
switch (status) switch (status)
{ {
case UNTESTED: case UNTESTED:
DisplayInfo(i+1,1, "%-30.30s %s\n", DisplayInfo(i + 1, 1, "%-30.30s %s\n",
request->mirrors[i].server_name, request->mirrors[i].server_name,
"NOT TESTED"); "NOT TESTED");
break; break;
case RESPONSEOK: case RESPONSEOK:
DisplayInfo(i+1,1, "%-30.30s %dms\n", DisplayInfo(i + 1, 1, "%-30.30s %dms\n",
request->mirrors[i].server_name, request->mirrors[i].server_name,
request->mirrors[i].milli_secs); request->mirrors[i].milli_secs);
break; break;
case NORESPONSE: case NORESPONSE:
case ERROR: case ERROR:
DisplayInfo(i+1,1, "%-30.30s %s\n", DisplayInfo(i + 1, 1, "%-30.30s %s\n",
request->mirrors[i].server_name, request->mirrors[i].server_name,
"NO REPONSE"); "NO REPONSE");
break; break;
default: default:
DisplayInfo(i+1,1, "%-30.30s %s\n", DisplayInfo(i + 1, 1, "%-30.30s %s\n",
request->mirrors[i].server_name, request->mirrors[i].server_name,
"Unkown condition!!"); "Unkown condition!!");
break; break;
} }
} }
if (rt.display_mode == DISP_STDOUT) if (rt.display_mode == DISP_STDOUT)
fprintf(stdout,"\n"); fprintf(stdout, "\n");
} }
} }

View File

@@ -29,27 +29,26 @@
class FTPS_Window { class FTPS_Window {
public: public:
FTPS_Window(); FTPS_Window();
void fetch_mirror_info(urlinfo *u, off_t file_size, char *ftps_loc, void fetch_mirror_info(urlinfo *u, off_t file_size, char *ftps_loc,
ftpsearch_server_type_t server_type, ftpsearch_server_type_t server_type,
int num_req_mirrors); int num_req_mirrors);
void cleanup(); void cleanup();
uerr_t callback(); uerr_t callback();
void ping_list(); void ping_list();
void print_status(ftps_request_t * request, int quiet_mode); void print_status(ftps_request_t * request, int quiet_mode);
ftps_request_t *request; ftps_request_t *request;
boolean request_running; boolean request_running;
boolean ping_running; boolean ping_running;
boolean got_mirror_info; boolean got_mirror_info;
boolean ping_done; boolean ping_done;
boolean exit_ftpsearch_button_pressed; boolean exit_ftpsearch_button_pressed;
private: private:
}; };
#endif #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 */ /* Sets the default config */
void set_defaults() void set_defaults()
{ {
struct stat st; struct stat st;
char cwd[PATH_MAX]; char cwd[PATH_MAX];
/* /*
* Zero the structure which holds the config data * Zero the structure which holds the config data
*/ */
@@ -67,7 +67,7 @@ void set_defaults()
/*TODO what to do if the homedir is NULL */ /*TODO what to do if the homedir is NULL */
if (rt.config_dir != 0) if (rt.config_dir != 0)
free(rt.config_dir); free(rt.config_dir);
rt.config_dir = (char *) malloc(PATH_MAX); rt.config_dir = (char *)malloc(PATH_MAX);
snprintf(rt.config_dir, PATH_MAX, "%s/%s", rt.home_dir, PRZCONFDIR); snprintf(rt.config_dir, PATH_MAX, "%s/%s", rt.home_dir, PRZCONFDIR);
/* Make the ~/.prozilla directory if necessary */ /* Make the ~/.prozilla directory if necessary */
@@ -83,7 +83,8 @@ void set_defaults()
(_("unable to create the directory to store the config info in")); (_("unable to create the directory to store the config info in"));
exit(0); exit(0);
} }
} else }
else
perror(_("Error while stating the config info directory")); perror(_("Error while stating the config info directory"));
} }
@@ -135,7 +136,7 @@ void set_defaults()
rt.quiet_mode = TRUE; rt.quiet_mode = TRUE;
rt.libdebug_mode = TRUE; rt.libdebug_mode = TRUE;
rt.ftp_search = FALSE; rt.ftp_search = FALSE;
rt.min_search_size=128; rt.min_search_size = 128;
rt.max_simul_pings = 5; rt.max_simul_pings = 5;
rt.max_ping_wait = 8; rt.max_ping_wait = 8;
rt.ftps_mirror_req_n = 40; rt.ftps_mirror_req_n = 40;
@@ -145,7 +146,7 @@ void set_defaults()
if (rt.http_proxy != 0) if (rt.http_proxy != 0)
free(rt.http_proxy); free(rt.http_proxy);
rt.http_proxy = (proxy_info *) malloc(sizeof(proxy_info)); rt.http_proxy = (proxy_info *)malloc(sizeof(proxy_info));
rt.http_proxy->username = strdup(""); rt.http_proxy->username = strdup("");
rt.http_proxy->passwd = strdup(""); rt.http_proxy->passwd = strdup("");
rt.http_proxy->type = HTTPPROXY; rt.http_proxy->type = HTTPPROXY;
@@ -154,7 +155,7 @@ void set_defaults()
if (rt.ftp_proxy != 0) if (rt.ftp_proxy != 0)
free(rt.ftp_proxy); free(rt.ftp_proxy);
rt.ftp_proxy = (proxy_info *) malloc(sizeof(proxy_info)); rt.ftp_proxy = (proxy_info *)malloc(sizeof(proxy_info));
rt.ftp_proxy->username = strdup(""); rt.ftp_proxy->username = strdup("");
rt.ftp_proxy->passwd = strdup(""); rt.ftp_proxy->passwd = strdup("");
rt.ftp_proxy->type = HTTPPROXY; rt.ftp_proxy->type = HTTPPROXY;
@@ -201,7 +202,6 @@ void set_runtime_values()
void cleanuprt() void cleanuprt()
{ {
if (rt.config_dir != 0) if (rt.config_dir != 0)
free(rt.config_dir); free(rt.config_dir);
@@ -222,5 +222,4 @@ void cleanuprt()
if (rt.logfile_dir != 0) if (rt.logfile_dir != 0)
free(rt.logfile_dir); free(rt.logfile_dir);
}
}

View File

@@ -57,10 +57,10 @@
* CONREJECTED, * CONREJECTED,
* REMOTEFATAL, * REMOTEFATAL,
* LOCALFATAL * LOCALFATAL
*} dl_status; **} dl_status;
* *
* And here are the texts for the above enums. * And here are the texts for the above enums.
*/ */
const char *dl_status_txt[] = { const char *dl_status_txt[] = {
"Idle", "Idle",
"Connecting", "Connecting",
@@ -109,9 +109,9 @@ int messageCol = 0;
* my self * my self
*/ */
#define kwattr_get(win,a,p,opts) ((void)((a) != 0 && (*(a) = (win)->_attrs)), (void)((p) != 0 && (*(p) = PAIR_NUMBER((win)->_attrs))),OK) #define kwattr_get(win, a, p, opts) ((void)((a) != 0 && (*(a) = (win)->_attrs)), (void)((p) != 0 && (*(p) = PAIR_NUMBER((win)->_attrs))), OK)
#define kwattr_set(win,a,p,opts) ((win)->_attrs = (((a) & ~A_COLOR) | COLOR_PAIR(p)), OK) #define kwattr_set(win, a, p, opts) ((win)->_attrs = (((a) & ~A_COLOR) | COLOR_PAIR(p)), OK)
/* Message: prints a message to the screen */ /* Message: prints a message to the screen */
@@ -120,6 +120,7 @@ void curses_message(char *message)
short i; short i;
int x, y; int x, y;
attr_t attrs; attr_t attrs;
/* /*
* Lock the mutex * Lock the mutex
*/ */
@@ -131,11 +132,11 @@ void curses_message(char *message)
*/ */
getyx(stdscr, y, x); getyx(stdscr, y, x);
kwattr_get(stdscr, &attrs, &i, NULL); kwattr_get(stdscr, &attrs, &i, NULL);
move(messageRow-1, 0); move(messageRow - 1, 0);
clrtoeol(); clrtoeol();
move(messageRow, 0); move(messageRow, 0);
clrtoeol(); clrtoeol();
move(messageRow+1, 0); move(messageRow + 1, 0);
clrtoeol(); clrtoeol();
attrset(COLOR_PAIR(MSG_PAIR) | A_BOLD); attrset(COLOR_PAIR(MSG_PAIR) | A_BOLD);
mvprintw(messageRow, 0, "%s", message); mvprintw(messageRow, 0, "%s", message);
@@ -150,14 +151,13 @@ void curses_message(char *message)
move(y, x); move(y, x);
pthread_mutex_unlock(&curses_msg_mutex); pthread_mutex_unlock(&curses_msg_mutex);
} }
/* Displays the mesasge and gets the users input for overwriting files*/ /* Displays the mesasge and gets the users input for overwriting files*/
int curses_query_user_input(const char *args, ...) int curses_query_user_input(const char *args, ...)
{ {
char p[MAX_MSG_SIZE+1]; char p[MAX_MSG_SIZE + 1];
va_list vp; va_list vp;
attr_t attrs; attr_t attrs;
int x, y; int x, y;
@@ -165,7 +165,7 @@ int curses_query_user_input(const char *args, ...)
int i; int i;
va_start(vp, args); va_start(vp, args);
vsnprintf(p,sizeof(p) , args, vp); vsnprintf(p, sizeof(p), args, vp);
va_end(vp); va_end(vp);
getyx(stdscr, y, x); getyx(stdscr, y, x);
kwattr_get(stdscr, &attrs, &i, NULL); kwattr_get(stdscr, &attrs, &i, NULL);
@@ -184,8 +184,7 @@ int curses_query_user_input(const char *args, ...)
{ {
napms(20); napms(20);
ch = getch(); ch = getch();
} } while (ch == ERR);
while (ch == ERR);
refresh(); refresh();
noecho(); noecho();
@@ -213,16 +212,14 @@ void initCurses()
init_pair(WARN_PAIR, COLOR_RED, COLOR_BLACK); init_pair(WARN_PAIR, COLOR_RED, COLOR_BLACK);
init_pair(PROMPT_PAIR, COLOR_RED, COLOR_BLACK); init_pair(PROMPT_PAIR, COLOR_RED, COLOR_BLACK);
init_pair(SELECTED_PAIR, COLOR_WHITE, COLOR_BLUE); init_pair(SELECTED_PAIR, COLOR_WHITE, COLOR_BLUE);
getmaxyx(stdscr,maxRow,maxCol); getmaxyx(stdscr, maxRow, maxCol);
messageRow = maxRow - 2; messageRow = maxRow - 2;
messageCol = 1; messageCol = 1;
} }
void shutdownCurses() void shutdownCurses()
{ {
endwin(); endwin();
} }
@@ -232,7 +229,7 @@ void PrintMessage(const char *format, ...)
char message[MAX_MSG_SIZE + 1 + 1]; char message[MAX_MSG_SIZE + 1 + 1];
va_start(args, format); va_start(args, format);
vsnprintf((char *) &message, MAX_MSG_SIZE, format, args); vsnprintf((char *)&message, MAX_MSG_SIZE, format, args);
va_end(args); va_end(args);
if (rt.display_mode == DISP_CURSES) if (rt.display_mode == DISP_CURSES)
@@ -255,13 +252,13 @@ void DisplayInfo(int row, int col, const char *format, ...)
char message[MAX_MSG_SIZE + 1 + 1]; char message[MAX_MSG_SIZE + 1 + 1];
va_start(args, format); va_start(args, format);
vsnprintf((char *) &message, MAX_MSG_SIZE, format, args); vsnprintf((char *)&message, MAX_MSG_SIZE, format, args);
va_end(args); va_end(args);
if (rt.display_mode == DISP_CURSES) if (rt.display_mode == DISP_CURSES)
{ {
attrset(COLOR_PAIR(NULL_PAIR) | A_BOLD); attrset(COLOR_PAIR(NULL_PAIR) | A_BOLD);
mvaddstr(row,col, message); mvaddstr(row, col, message);
attrset(COLOR_PAIR(NULL_PAIR)); attrset(COLOR_PAIR(NULL_PAIR));
refresh(); refresh();
@@ -276,17 +273,18 @@ void DisplayInfo(int row, int col, const char *format, ...)
// delay_ms(300); // delay_ms(300);
} }
void DisplayCursesInfo(download_t * download ) void DisplayCursesInfo(download_t * download)
{ {
char buf[1000]; char buf[1000];
int i = 0; int i = 0;
int line = 1; int line = 1;
int secs_left; int secs_left;
// erase(); // erase();
refresh(); refresh();
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD); attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
snprintf(buf, sizeof(buf), _("Connection Server Status Received")); snprintf(buf, sizeof(buf), _("Connection Server Status Received"));
mvprintw(line++,1, buf); mvprintw(line++, 1, buf);
attrset(COLOR_PAIR(NULL_PAIR)); attrset(COLOR_PAIR(NULL_PAIR));
@@ -308,13 +306,13 @@ void DisplayCursesInfo(download_t * download )
for (i = 0; i < download->num_connections; i++) for (i = 0; i < download->num_connections; i++)
{ {
snprintf(buf,sizeof(buf), _(" %2d %-25.25s %-15.15s %10.1fK of %.1fK"), i + 1, snprintf(buf, sizeof(buf), _(" %2d %-25.25s %-15.15s %10.1fK of %.1fK"), i + 1,
download->pconnections[i]->u.host, download->pconnections[i]->u.host,
proz_connection_get_status_string(download->pconnections[i]), proz_connection_get_status_string(download->pconnections[i]),
(float)proz_connection_get_total_bytes_got(download-> (float)proz_connection_get_total_bytes_got(download->
pconnections[i])/1024, pconnections[i]) / 1024,
((float)download->pconnections[i]->main_file_size / 1024) / download->num_connections); ((float)download->pconnections[i]->main_file_size / 1024) / download->num_connections);
mvprintw(line++,1, buf); mvprintw(line++, 1, buf);
} }
line = line + 2; line = line + 2;
@@ -324,41 +322,41 @@ void DisplayCursesInfo(download_t * download )
attrset(COLOR_PAIR(HIGHLIGHT_PAIR)); attrset(COLOR_PAIR(HIGHLIGHT_PAIR));
if (download->main_file_size > 0) if (download->main_file_size > 0)
mvprintw(line++,1,_("File Size = %lldK"),download->main_file_size / 1024); mvprintw(line++, 1, _("File Size = %lldK"), download->main_file_size / 1024);
else else
mvprintw(line++,1,_("File Size = UNKNOWN")); mvprintw(line++, 1, _("File Size = UNKNOWN"));
snprintf(buf,sizeof(buf), _("Total Bytes received %lld Kb (%.2f%%)"), snprintf(buf, sizeof(buf), _("Total Bytes received %lld Kb (%.2f%%)"),
total_bytes_got, total_bytes_got,
(((float)total_bytes_got * 100) / ((float)download->main_file_size / 1024))); (((float)total_bytes_got * 100) / ((float)download->main_file_size / 1024)));
line++; line++;
mvprintw(line++,1, buf); mvprintw(line++, 1, buf);
snprintf(buf,sizeof(buf),_("Current speed = %1.2fKb/s, Average D/L speed = %1.2fKb/s"), snprintf(buf, sizeof(buf), _("Current speed = %1.2fKb/s, Average D/L speed = %1.2fKb/s"),
current_dl_speed , proz_download_get_average_speed(download) / 1024); current_dl_speed, proz_download_get_average_speed(download) / 1024);
mvprintw(line++,1, buf); mvprintw(line++, 1, buf);
clrtoeol(); clrtoeol();
if ((secs_left = proz_download_get_est_time_left(download)) != -1) if ((secs_left = proz_download_get_est_time_left(download)) != -1)
{ {
if (secs_left < 60) if (secs_left < 60)
snprintf(buf,sizeof(buf), _("Time Remaining %d Seconds"), secs_left); snprintf(buf, sizeof(buf), _("Time Remaining %d Seconds"), secs_left);
else if (secs_left < 3600) else if (secs_left < 3600)
snprintf(buf,sizeof(buf), _("Time Remaining %d Minutes %d Seconds"), secs_left / 60, snprintf(buf, sizeof(buf), _("Time Remaining %d Minutes %d Seconds"), secs_left / 60,
secs_left % 60); secs_left % 60);
else else
snprintf(buf,sizeof(buf), _("Time Remaining %d Hours %d minutes"), secs_left / 3600, snprintf(buf, sizeof(buf), _("Time Remaining %d Hours %d minutes"), secs_left / 3600,
(secs_left % 3600) / 60); (secs_left % 3600) / 60);
mvprintw(line++,1, buf); mvprintw(line++, 1, buf);
clrtoeol(); clrtoeol();
line++; line++;
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD); attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
if (download->resume_support) if (download->resume_support)
mvprintw(line++,1,_("Resume Supported")); mvprintw(line++, 1, _("Resume Supported"));
else else
mvprintw(line++,1,_("Resume NOT Supported")); mvprintw(line++, 1, _("Resume NOT Supported"));
} }
attrset(COLOR_PAIR(NULL_PAIR)); attrset(COLOR_PAIR(NULL_PAIR));
refresh(); refresh();

View File

@@ -50,36 +50,36 @@ struct option long_opts[] = {
/* /*
* { name has_arg *flag val } * { name has_arg *flag val }
*/ */
{"resume", no_argument, NULL, 'r'}, { "resume", no_argument, NULL, 'r' },
/* {"connections", required_argument, NULL, 'c'},*/ /* {"connections", required_argument, NULL, 'c'},*/
{"license", no_argument, NULL, 'L'}, { "license", no_argument, NULL, 'L' },
{"help", no_argument, NULL, 'h'}, { "help", no_argument, NULL, 'h' },
{"gtk", no_argument, NULL, 'g'}, { "gtk", no_argument, NULL, 'g' },
{"no-netrc", no_argument, NULL, 'n'}, { "no-netrc", no_argument, NULL, 'n' },
{"tries", required_argument, NULL, 't'}, { "tries", required_argument, NULL, 't' },
{"force", no_argument, NULL, 'f'}, { "force", no_argument, NULL, 'f' },
{"version", no_argument, NULL, 'v'}, { "version", no_argument, NULL, 'v' },
{"output-document", required_argument, NULL, 'O'}, { "output-document", required_argument, NULL, 'O' },
{"directory-prefix", required_argument, NULL, 'P'}, { "directory-prefix", required_argument, NULL, 'P' },
{"use-port", no_argument, NULL, 129}, { "use-port", no_argument, NULL, 129 },
{"retry-delay", required_argument, NULL, 130}, { "retry-delay", required_argument, NULL, 130 },
{"timeout", required_argument, NULL, 131}, { "timeout", required_argument, NULL, 131 },
{"no-getch", no_argument, NULL, 132}, { "no-getch", no_argument, NULL, 132 },
{"debug", no_argument, NULL, 133}, { "debug", no_argument, NULL, 133 },
{"ftpsearch", no_argument, NULL, 's'}, { "ftpsearch", no_argument, NULL, 's' },
{"no-search", no_argument, NULL, 135}, { "no-search", no_argument, NULL, 135 },
{"pt", required_argument, NULL, 136}, { "pt", required_argument, NULL, 136 },
{"pao", required_argument, NULL, 137}, { "pao", required_argument, NULL, 137 },
{"max-ftps-servers", required_argument, NULL, 138}, { "max-ftps-servers", required_argument, NULL, 138 },
{"max-bps", required_argument, NULL, 139}, { "max-bps", required_argument, NULL, 139 },
{"verbose", no_argument, NULL, 'v'}, { "verbose", no_argument, NULL, 'v' },
{"no-curses", no_argument, NULL, 140}, { "no-curses", no_argument, NULL, 140 },
{"min-size",required_argument,NULL,141}, { "min-size", required_argument, NULL, 141 },
{"ftpsid", required_argument, NULL,142}, { "ftpsid", required_argument, NULL, 142 },
{0, 0, 0, 0} { 0, 0, 0, 0 }
}; };
int open_new_dl_win (urlinfo * url_data, boolean ftpsearch); int open_new_dl_win(urlinfo * url_data, boolean ftpsearch);
DL_Window *dl_win = NULL; DL_Window *dl_win = NULL;
@@ -89,9 +89,9 @@ extern int nextchar;
/* displays the software license */ /* displays the software license */
void void
license (void) license(void)
{ {
fprintf (stderr, fprintf(stderr,
" Copyright (C) 2000 Kalum Somaratna\n" " Copyright (C) 2000 Kalum Somaratna\n"
"\n" "\n"
" This program is free software; you can redistribute it and/or modify\n" " This program is free software; you can redistribute it and/or modify\n"
@@ -113,9 +113,9 @@ license (void)
/* displays the help message */ /* displays the help message */
void void
help (void) help(void)
{ {
fprintf (stderr, fprintf(stderr,
"Usage: proz [OPTIONS] file_url\n" "Usage: proz [OPTIONS] file_url\n"
"\n" "\n"
"Ex: proz http://gnu.org/gnu.jpg\n" "Ex: proz http://gnu.org/gnu.jpg\n"
@@ -177,124 +177,135 @@ help (void)
/* Displays the version */ /* Displays the version */
void void
version (void) version(void)
{ {
fprintf (stderr, _("%s. Version: %s\n"), PACKAGE_NAME, VERSION); fprintf(stderr, _("%s. Version: %s\n"), PACKAGE_NAME, VERSION);
} }
void void
ms (const char *msg, void *cb_data) ms(const char *msg, void *cb_data)
{ {
PrintMessage("%s\n",msg); PrintMessage("%s\n", msg);
} }
int int
open_new_dl_win (urlinfo * url_data, boolean ftpsearch) open_new_dl_win(urlinfo * url_data, boolean ftpsearch)
{ {
dl_win = new DL_Window(url_data);
dl_win = new DL_Window (url_data); dl_win->dl_start(rt.num_connections, ftpsearch);
dl_win->dl_start (rt.num_connections, ftpsearch); proz_debug("calling the callback function...");
proz_debug ("calling the callback function...");
//need a timer here... //need a timer here...
while (dl_win->status != DL_DONE && dl_win->status != DL_IDLING && dl_win->status != DL_ABORTED) while (dl_win->status != DL_DONE && dl_win->status != DL_IDLING && dl_win->status != DL_ABORTED)
{ {
delay_ms (700); //wait before checking the status again... delay_ms(700); //wait before checking the status again...
dl_win->my_cb (); dl_win->my_cb();
} }
return((dl_win->status==DL_DONE) ? 1:-1); return((dl_win->status == DL_DONE) ? 1 : -1);
// delete (dl_win); // delete (dl_win);
} }
int int
main (int argc, char **argv) main(int argc, char **argv)
{ {
int c; int c;
int ret; int ret;
char *opt_file = NULL; char *opt_file = NULL;
proz_init (argc, argv); //init libprozilla
set_defaults (); //set some reasonable defaults proz_init(argc, argv); //init libprozilla
load_prefs (); //load values from the config file set_defaults(); //set some reasonable defaults
load_prefs(); //load values from the config file
while ((c = while ((c =
getopt_long (argc, argv, "?hvrfk:1Lt:VgsP:O:", long_opts, getopt_long(argc, argv, "?hvrfk:1Lt:VgsP:O:", long_opts,
NULL)) != EOF) NULL)) != EOF)
{ {
switch (c) switch (c)
{ {
case 'L': case 'L':
license (); license();
exit (0); exit(0);
case 'h': case 'h':
help (); help();
exit (0); exit(0);
case 'V': case 'V':
version (); version();
exit (0); exit(0);
case 'r': case 'r':
rt.resume_mode = RESUME; rt.resume_mode = RESUME;
break; break;
case 'f': case 'f':
rt.force_mode = TRUE; rt.force_mode = TRUE;
break; break;
case 'k': case 'k':
if (setargval (optarg, &rt.num_connections) != 1) if (setargval(optarg, &rt.num_connections) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the -k option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the -k option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
if (rt.num_connections == 0) if (rt.num_connections == 0)
{ {
printf (_("Hey! How can I download anything with 0 (Zero)" " connections!?\n" "Please type proz --help for help\n")); printf(_("Hey! How can I download anything with 0 (Zero)" " connections!?\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 't': case 't':
if (setargval (optarg, &rt.max_attempts) != 1) if (setargval(optarg, &rt.max_attempts) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the -t or --tries option(s)\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the -t or --tries option(s)\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 'n': case 'n':
/* /*
* Don't use ~/.netrc" * Don't use ~/.netrc"
*/ */
rt.use_netrc = FALSE; rt.use_netrc = FALSE;
break; break;
case 'O': case 'O':
/* /*
* Output file name * Output file name
*/ */
opt_file = kstrdup(optarg); opt_file = kstrdup(optarg);
break; break;
case 'P': case 'P':
/* /*
* Save the downloaded file to DIR * Save the downloaded file to DIR
*/ */
rt.output_dir = kstrdup (optarg); rt.output_dir = kstrdup(optarg);
break; break;
case '?': case '?':
help (); help();
exit (0); exit(0);
break; break;
case '1': case '1':
rt.num_connections = 1; rt.num_connections = 1;
break; break;
@@ -303,9 +314,9 @@ main (int argc, char **argv)
/* /*
* TODO solve this soon * TODO solve this soon
*/ */
printf ("Error: GTK interface is not supported in " printf("Error: GTK interface is not supported in "
"the development version currently\n"); "the development version currently\n");
exit (0); exit(0);
break; break;
case 129: case 129:
@@ -314,30 +325,33 @@ main (int argc, char **argv)
*/ */
rt.ftp_use_pasv = FALSE; rt.ftp_use_pasv = FALSE;
break; break;
case 130: case 130:
/* /*
* retry-delay option * retry-delay option
*/ */
if (setargval (optarg, &rt.retry_delay) != 1) if (setargval(optarg, &rt.retry_delay) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the --retry-delay option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the --retry-delay option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 131: case 131:
/*--timout option */ /*--timout option */
if (setargval (optarg, &rt.itimeout) != 1) if (setargval(optarg, &rt.itimeout) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the --timeout option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the --timeout option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 132: case 132:
/* --no-getch option */ /* --no-getch option */
rt.dont_prompt = TRUE; rt.dont_prompt = TRUE;
@@ -346,7 +360,7 @@ main (int argc, char **argv)
case 133: case 133:
/* --debug option */ /* --debug option */
rt.debug_mode = TRUE; rt.debug_mode = TRUE;
rt.libdebug_mode=TRUE; rt.libdebug_mode = TRUE;
break; break;
case 'v': case 'v':
@@ -366,101 +380,105 @@ main (int argc, char **argv)
case 136: case 136:
/* --pt option */ /* --pt option */
if (setargval (optarg, &rt.max_ping_wait) != 1) if (setargval(optarg, &rt.max_ping_wait) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the --pt option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the --pt option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
if (rt.max_ping_wait == 0) if (rt.max_ping_wait == 0)
{ {
printf (_("Hey! Does waiting for a server response for Zero(0)" " seconds make and sense to you!?\n" "Please type proz --help for help\n")); printf(_("Hey! Does waiting for a server response for Zero(0)" " seconds make and sense to you!?\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 137: case 137:
/* --pao option */ /* --pao option */
if (setargval (optarg, &rt.max_simul_pings) != 1) if (setargval(optarg, &rt.max_simul_pings) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the --pao option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the --pao option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
if (rt.max_simul_pings == 0) if (rt.max_simul_pings == 0)
{ {
printf (_("Hey you! Will pinging Zero(0) servers at once" " achive anything for me!?\n" "Please type proz --help for help\n")); printf(_("Hey you! Will pinging Zero(0) servers at once" " achive anything for me!?\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 138: case 138:
/* --max-ftp-servers option */ /* --max-ftp-servers option */
if (setargval (optarg, &rt.ftps_mirror_req_n) != 1) if (setargval(optarg, &rt.ftps_mirror_req_n) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the --pao option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the --pao option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
if (rt.ftps_mirror_req_n == 0) if (rt.ftps_mirror_req_n == 0)
{ {
printf (_("Hey! Will requesting Zero(0) servers at once" "from the ftpearch achive anything!?\n" "Please type proz --help for help\n")); printf(_("Hey! Will requesting Zero(0) servers at once" "from the ftpearch achive anything!?\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 139: case 139:
/* --max-bps */ /* --max-bps */
if (setlongargval (optarg, &rt.max_bps_per_dl) != 1) if (setlongargval(optarg, &rt.max_bps_per_dl) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the --max-bps option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the --max-bps option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 140: case 140:
rt.display_mode = DISP_STDOUT; rt.display_mode = DISP_STDOUT;
break; break;
case 141: case 141:
/* --min-size */ /* --min-size */
if (setlongargval (optarg, &rt.min_search_size) != 1) if (setlongargval(optarg, &rt.min_search_size) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the --min-size option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the --min-size option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
case 142: case 142:
/* --ftpsid */ /* --ftpsid */
if (setargval (optarg, &rt.ftpsearch_server_id) != 1) if (setargval(optarg, &rt.ftpsearch_server_id) != 1)
{ {
/* /*
* The call failed due to a invalid arg * The call failed due to a invalid arg
*/ */
printf (_("Error: Invalid arguments for the --ftpsid option\n" "Please type proz --help for help\n")); printf(_("Error: Invalid arguments for the --ftpsid option\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
if (rt.ftpsearch_server_id < 0 || rt.ftpsearch_server_id >1) if (rt.ftpsearch_server_id < 0 || rt.ftpsearch_server_id > 1)
{ {
printf (_("The available servers are (0) filesearching.com and (1) ftpsearch.elmundo.es\n" "Please type proz --help for help\n")); printf(_("The available servers are (0) filesearching.com and (1) ftpsearch.elmundo.es\n" "Please type proz --help for help\n"));
exit (0); exit(0);
} }
break; break;
@@ -468,26 +486,26 @@ main (int argc, char **argv)
default: default:
printf (_("Error: Invalid option\n")); printf(_("Error: Invalid option\n"));
exit (0); exit(0);
} }
} }
set_runtime_values (); //tell libprozilla about any changed settings set_runtime_values(); //tell libprozilla about any changed settings
if (optind == argc) if (optind == argc)
{ {
help (); help();
} }
else else
{ {
/* Gettext stuff */ /* Gettext stuff */
setlocale (LC_ALL, ""); setlocale(LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain (PACKAGE); textdomain(PACKAGE);
/*delete the ~/.prozilla/debug.log file if present at the start of each run */ /*delete the ~/.prozilla/debug.log file if present at the start of each run */
proz_debug_delete_log (); proz_debug_delete_log();
if (rt.display_mode == DISP_CURSES) if (rt.display_mode == DISP_CURSES)
initCurses(); initCurses();
@@ -497,61 +515,58 @@ main (int argc, char **argv)
{ {
uerr_t err; uerr_t err;
urlinfo *url_data; urlinfo *url_data;
url_data = (urlinfo *) malloc (sizeof (urlinfo)); url_data = (urlinfo *)malloc(sizeof(urlinfo));
memset (url_data, 0, sizeof (urlinfo)); memset(url_data, 0, sizeof(urlinfo));
//parses and validates the command-line parm //parses and validates the command-line parm
err = proz_parse_url (argv[i], url_data, 0); err = proz_parse_url(argv[i], url_data, 0);
if (err != URLOK) if (err != URLOK)
{ {
PrintMessage (_ PrintMessage(_
("%s does not seem to be a valid URL"), ("%s does not seem to be a valid URL"),
argv[optind]); argv[optind]);
proz_debug proz_debug
("%s does not seem to be a valid URL", ("%s does not seem to be a valid URL",
argv[optind]); argv[optind]);
if(url_data) if (url_data)
free(url_data); free(url_data);
shutdown(); shutdown();
exit (0); exit(0);
} }
if (opt_file) if (opt_file)
url_data->file=opt_file; url_data->file = opt_file;
PrintMessage("Starting....."); PrintMessage("Starting.....");
//In to %s\n",url_data->host); //In to %s\n",url_data->host);
// start the download // start the download
ret=open_new_dl_win (url_data, rt.ftp_search); ret = open_new_dl_win(url_data, rt.ftp_search);
/*If the download failed the return -1 */ /*If the download failed the return -1 */
if(ret==-1) if (ret == -1)
{ {
if(url_data) if (url_data)
free(url_data); free(url_data);
if(dl_win) if (dl_win)
delete(dl_win); delete (dl_win);
shutdown(); shutdown();
return -1; return -1;
} }
if(dl_win) if (dl_win)
delete(dl_win); delete (dl_win);
if(url_data) if (url_data)
free (url_data); free(url_data);
} }
} }
shutdown(); shutdown();
} }
void shutdown(void) void shutdown(void)
{ {
cleanuprt();
cleanuprt ();
if (rt.display_mode == DISP_CURSES) if (rt.display_mode == DISP_CURSES)
shutdownCurses(); shutdownCurses();
proz_shutdown (); proz_shutdown();
} }

View File

@@ -10,7 +10,7 @@
//#define _(String) dgettext (PACKAGE,String) //#define _(String) dgettext (PACKAGE,String)
#define gettext_noop(String) (String) #define gettext_noop(String) (String)
#ifndef HAVE_GNOME #ifndef HAVE_GNOME
#define N_(String) gettext_noop (String) #define N_(String) gettext_noop(String)
#endif #endif
/* Gettext */ /* Gettext */
@@ -19,14 +19,14 @@
#define PRZCONFDIR ".prozilla" #define PRZCONFDIR ".prozilla"
typedef enum { typedef enum {
RESUME RESUME
} rto; } rto;
typedef enum { typedef enum {
DISP_CURSES, DISP_CURSES,
DISP_STDOUT DISP_STDOUT
} DISPLAYMODE; } DISPLAYMODE;
struct runtime { struct runtime {
int num_connections; int num_connections;

View File

@@ -29,12 +29,11 @@ char *kstrdup(const char *s)
// die("Not enough memory to continue: strdup failed"); // die("Not enough memory to continue: strdup failed");
} }
return s1; return s1;
} }
/* Extracts a numurical argument from a option, /* Extracts a numurical argument from a option,
when it has been specified for example as -l=3 or, -l3 when it has been specified for example as -l=3 or, -l3
returns 1 on success or 0 on a error (non nemrical argument etc returns 1 on success or 0 on a error (non nemrical argument etc
*/ */
int setargval(char *optstr, int *num) int setargval(char *optstr, int *num)
{ {
@@ -44,23 +43,24 @@ int setargval(char *optstr, int *num)
{ {
*num = atoi(optstr + 1); *num = atoi(optstr + 1);
return 1; return 1;
} else }
else
{ {
return 0; return 0;
} }
} else }
else
{ {
if (is_number(optstr) == 1) if (is_number(optstr) == 1)
{ {
*num = atoi(optstr); *num = atoi(optstr);
return 1; return 1;
}
} else else
{ {
return 0; return 0;
} }
} }
} }
int setlongargval(char *optstr, long *num) int setlongargval(char *optstr, long *num)
@@ -71,23 +71,24 @@ int setlongargval(char *optstr, long *num)
{ {
*num = atol(optstr + 1); *num = atol(optstr + 1);
return 1; return 1;
} else }
else
{ {
return 0; return 0;
} }
} else }
else
{ {
if (is_number(optstr) == 1) if (is_number(optstr) == 1)
{ {
*num = atol(optstr); *num = atol(optstr);
return 1; return 1;
}
} else else
{ {
return 0; return 0;
} }
} }
} }
void delay_ms(int ms) void delay_ms(int ms)
@@ -99,7 +100,7 @@ void delay_ms(int ms)
tv_delay.tv_sec = ms / 1000; tv_delay.tv_sec = ms / 1000;
tv_delay.tv_usec = (ms * 1000) % 1000000; tv_delay.tv_usec = (ms * 1000) % 1000000;
if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &tv_delay) < 0) if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv_delay) < 0)
{ {
proz_debug("Warning Unable to delay\n"); proz_debug("Warning Unable to delay\n");
} }

View File

@@ -31,7 +31,7 @@
#include "prefs.h" #include "prefs.h"
typedef void (*prefproc) (int i, const char *const, FILE * const fp); typedef void (*prefproc)(int i, const char *const, FILE * const fp);
typedef struct prefopt_t { typedef struct prefopt_t {
const char *varname; const char *varname;
@@ -75,43 +75,43 @@ void set_search_size(int i, const char *const val, FILE * const fp);
prefopt_t pref_opts[] = { prefopt_t pref_opts[] = {
{"threads", set_num_threads, 1}, { "threads", set_num_threads, 1 },
{"tries", set_max_attempts, 1}, { "tries", set_max_attempts, 1 },
{"pasv", set_use_pasv, 1}, { "pasv", set_use_pasv, 1 },
{"retrydelay", set_retry_delay, 1}, { "retrydelay", set_retry_delay, 1 },
{"conntimeout", set_conn_timeout, 1}, { "conntimeout", set_conn_timeout, 1 },
{"maxbpsperdl", set_max_bps_per_dl, 1}, { "maxbpsperdl", set_max_bps_per_dl, 1 },
{"debug", set_debug_mode, 1}, { "debug", set_debug_mode, 1 },
{"libdebug", set_libdebug_mode, 1}, { "libdebug", set_libdebug_mode, 1 },
{"pragmanocache", set_http_no_cache, 1}, { "pragmanocache", set_http_no_cache, 1 },
// {"outputdir", set_output_dir, 1}, // {"outputdir", set_output_dir, 1},
{"httpproxy", set_http_proxy, 1}, { "httpproxy", set_http_proxy, 1 },
{"httpproxyuser", set_http_proxy_username, 1}, { "httpproxyuser", set_http_proxy_username, 1 },
{"httpproxypassword", set_http_proxy_passwd, 1}, { "httpproxypassword", set_http_proxy_passwd, 1 },
{"httpproxytype", set_http_proxy_type, 1}, { "httpproxytype", set_http_proxy_type, 1 },
{"usehttpproxy", set_http_use_proxy, 1}, { "usehttpproxy", set_http_use_proxy, 1 },
{"ftpproxy", set_ftp_proxy, 1}, { "ftpproxy", set_ftp_proxy, 1 },
{"ftpproxyuser", set_ftp_proxy_username, 1}, { "ftpproxyuser", set_ftp_proxy_username, 1 },
{"ftpproxypassword", set_ftp_proxy_passwd, 1}, { "ftpproxypassword", set_ftp_proxy_passwd, 1 },
{"ftpproxytype", set_ftp_proxy_type, 1}, { "ftpproxytype", set_ftp_proxy_type, 1 },
{"useftpproxy", set_ftp_use_proxy, 1}, { "useftpproxy", set_ftp_use_proxy, 1 },
{"mirrorsreq", set_mirrors_req, 1}, { "mirrorsreq", set_mirrors_req, 1 },
{"maxsimulpings", set_max_simul_pings, 1}, { "maxsimulpings", set_max_simul_pings, 1 },
{"maxpingwait", set_max_ping_wait, 1}, { "maxpingwait", set_max_ping_wait, 1 },
{"defaultftpsearch", set_use_ftpsearch, 1}, { "defaultftpsearch", set_use_ftpsearch, 1 },
{"ftpsearchserverid", set_ftpsearch_server_id, 1}, { "ftpsearchserverid", set_ftpsearch_server_id, 1 },
{"displaymode",set_display_mode, 1}, { "displaymode", set_display_mode, 1 },
{"minsearchsize",set_search_size, 1}, { "minsearchsize", set_search_size, 1 },
{NULL, 0, 0} { NULL, 0, 0 }
}; };
void set_num_threads(int i, const char *const val, FILE * const fp) void set_num_threads(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.num_connections); fprintf(fp, "%d", rt.num_connections);
} else }
else
{ {
rt.num_connections = atoi(val); rt.num_connections = atoi(val);
if (rt.num_connections <= 0 || rt.num_connections > 30) 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) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.max_attempts); fprintf(fp, "%d", rt.max_attempts);
} else }
else
{ {
rt.max_attempts = atoi(val); rt.max_attempts = atoi(val);
if (rt.max_attempts < 0) 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) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.retry_delay); fprintf(fp, "%d", rt.retry_delay);
} else }
else
{ {
rt.retry_delay = atoi(val); rt.retry_delay = atoi(val);
if (rt.retry_delay < 0) if (rt.retry_delay < 0)
@@ -151,8 +153,9 @@ void set_conn_timeout(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", (int) rt.timeout.tv_sec); fprintf(fp, "%d", (int)rt.timeout.tv_sec);
} else }
else
{ {
rt.timeout.tv_sec = atoi(val); rt.timeout.tv_sec = atoi(val);
rt.timeout.tv_usec = 0; rt.timeout.tv_usec = 0;
@@ -167,38 +170,37 @@ void set_max_bps_per_dl(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", (int) rt.max_bps_per_dl); fprintf(fp, "%d", (int)rt.max_bps_per_dl);
} else }
else
{ {
rt.max_bps_per_dl = atoi(val); rt.max_bps_per_dl = atoi(val);
if (rt.max_bps_per_dl < 0) if (rt.max_bps_per_dl < 0)
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) void set_use_pasv(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.ftp_use_pasv); fprintf(fp, "%d", rt.ftp_use_pasv);
} else }
else
{ {
rt.ftp_use_pasv = atoi(val); rt.ftp_use_pasv = atoi(val);
} }
} }
void set_debug_mode(int i, const char *const val, FILE * const fp) void set_debug_mode(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.debug_mode); fprintf(fp, "%d", rt.debug_mode);
} else }
else
{ {
rt.debug_mode = atoi(val); 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) void set_libdebug_mode(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.libdebug_mode); fprintf(fp, "%d", rt.libdebug_mode);
} else }
else
{ {
rt.libdebug_mode = atoi(val); 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) void set_http_no_cache(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.http_no_cache); fprintf(fp, "%d", rt.http_no_cache);
} else }
else
{ {
rt.http_no_cache = atoi(val); 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) if (fp != NULL)
{ {
fprintf(fp, "%s", rt.output_dir); fprintf(fp, "%s", rt.output_dir);
} else }
else
{ {
free(rt.output_dir); free(rt.output_dir);
rt.output_dir = strdup(val); rt.output_dir = strdup(val);
} }
} }
void set_http_proxy(int i, const char *const val, FILE * const fp) void set_http_proxy(int i, const char *const val, FILE * const fp)
{ {
uerr_t err; uerr_t err;
urlinfo url_data; 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, fprintf(fp, "%s:%d", rt.http_proxy->proxy_url.host,
rt.http_proxy->proxy_url.port); rt.http_proxy->proxy_url.port);
} else }
else
{ {
err = proz_parse_url(val, &url_data, 0); err = proz_parse_url(val, &url_data, 0);
if (err != URLOK) 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) void set_http_proxy_username(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%s", rt.http_proxy->username); fprintf(fp, "%s", rt.http_proxy->username);
} else }
else
{ {
free(rt.http_proxy->username); free(rt.http_proxy->username);
rt.http_proxy->username = strdup(val); 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) void set_http_proxy_passwd(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%s", rt.http_proxy->passwd); fprintf(fp, "%s", rt.http_proxy->passwd);
} else }
else
{ {
free(rt.http_proxy->passwd); free(rt.http_proxy->passwd);
rt.http_proxy->passwd = strdup(val); rt.http_proxy->passwd = strdup(val);
@@ -296,13 +298,13 @@ 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) void set_http_proxy_type(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", (int) rt.http_proxy->type); fprintf(fp, "%d", (int)rt.http_proxy->type);
} else }
else
{ {
rt.http_proxy->type = (proxy_type) atoi(val); 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) void set_http_use_proxy(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.use_http_proxy); fprintf(fp, "%d", rt.use_http_proxy);
} else }
else
{ {
rt.use_http_proxy = atoi(val); 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) void set_ftp_proxy(int i, const char *const val, FILE * const fp)
{ {
uerr_t err; uerr_t err;
urlinfo url_data; 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, fprintf(fp, "%s:%d", rt.ftp_proxy->proxy_url.host,
rt.ftp_proxy->proxy_url.port); rt.ftp_proxy->proxy_url.port);
} else }
else
{ {
err = proz_parse_url(val, &url_data, 0); err = proz_parse_url(val, &url_data, 0);
if (err != URLOK) 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) void set_ftp_proxy_username(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%s", rt.ftp_proxy->username); fprintf(fp, "%s", rt.ftp_proxy->username);
} else }
else
{ {
free(rt.ftp_proxy->username); free(rt.ftp_proxy->username);
rt.ftp_proxy->username = strdup(val); 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) void set_ftp_proxy_passwd(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%s", rt.ftp_proxy->passwd); fprintf(fp, "%s", rt.ftp_proxy->passwd);
} else }
else
{ {
free(rt.ftp_proxy->passwd); free(rt.ftp_proxy->passwd);
rt.ftp_proxy->passwd = strdup(val); rt.ftp_proxy->passwd = strdup(val);
@@ -375,23 +377,23 @@ 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) void set_ftp_proxy_type(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", (int) rt.ftp_proxy->type); fprintf(fp, "%d", (int)rt.ftp_proxy->type);
} else }
else
{ {
rt.ftp_proxy->type = (proxy_type) atoi(val); rt.ftp_proxy->type = (proxy_type)atoi(val);
} }
} }
void set_ftp_use_proxy(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) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.use_ftp_proxy); fprintf(fp, "%d", rt.use_ftp_proxy);
} else }
else
{ {
rt.use_ftp_proxy = atoi(val); rt.use_ftp_proxy = atoi(val);
} }
@@ -400,29 +402,29 @@ 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) void set_mirrors_req(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.ftps_mirror_req_n); fprintf(fp, "%d", rt.ftps_mirror_req_n);
} else }
else
{ {
rt.ftps_mirror_req_n = atoi(val); rt.ftps_mirror_req_n = atoi(val);
if (rt.ftps_mirror_req_n <= 0 || rt.ftps_mirror_req_n> 1000) if (rt.ftps_mirror_req_n <= 0 || rt.ftps_mirror_req_n > 1000)
rt.ftps_mirror_req_n = 40; rt.ftps_mirror_req_n = 40;
} }
} }
void set_max_simul_pings(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) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.max_simul_pings); fprintf(fp, "%d", rt.max_simul_pings);
} else }
else
{ {
rt.max_simul_pings= atoi(val); rt.max_simul_pings = atoi(val);
if (rt.max_simul_pings <= 0 || rt.max_simul_pings> 30) if (rt.max_simul_pings <= 0 || rt.max_simul_pings > 30)
rt.max_simul_pings=5; rt.max_simul_pings = 5;
} }
} }
@@ -430,30 +432,29 @@ 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) void set_max_ping_wait(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.max_ping_wait); fprintf(fp, "%d", rt.max_ping_wait);
} else }
else
{ {
rt.max_ping_wait= atoi(val); rt.max_ping_wait = atoi(val);
if (rt.max_ping_wait <= 0 || rt.max_ping_wait> 30) if (rt.max_ping_wait <= 0 || rt.max_ping_wait > 30)
rt.max_ping_wait=5; rt.max_ping_wait = 5;
} }
} }
void set_use_ftpsearch(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) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.ftp_search); fprintf(fp, "%d", rt.ftp_search);
} else }
else
{ {
rt.ftp_search = atoi(val); rt.ftp_search = atoi(val);
} }
} }
void set_ftpsearch_server_id(int i, const char *const val, FILE * const fp) 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) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.ftpsearch_server_id); fprintf(fp, "%d", rt.ftpsearch_server_id);
} else }
else
{ {
rt.ftpsearch_server_id = atoi(val); rt.ftpsearch_server_id = atoi(val);
if (rt.ftpsearch_server_id < 0) if (rt.ftpsearch_server_id < 0)
rt.ftpsearch_server_id = 0; rt.ftpsearch_server_id = 0;
else if (rt.ftpsearch_server_id > 1) else if (rt.ftpsearch_server_id > 1)
rt.ftpsearch_server_id = 1; rt.ftpsearch_server_id = 1;
} }
} }
void set_display_mode(int i, const char *const val, FILE * const fp) void set_display_mode(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%d", rt.display_mode); fprintf(fp, "%d", rt.display_mode);
} else }
else
{ {
rt.display_mode = atoi(val); 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) void set_search_size(int i, const char *const val, FILE * const fp)
{ {
if (fp != NULL) if (fp != NULL)
{ {
fprintf(fp, "%ld", rt.min_search_size); fprintf(fp, "%ld", rt.min_search_size);
} else }
else
{ {
rt.min_search_size = atoi(val); rt.min_search_size = atoi(val);
} }
@@ -518,7 +519,7 @@ void save_prefs()
for (i = 0; pref_opts[i].varname != NULL; i++) for (i = 0; pref_opts[i].varname != NULL; i++)
{ {
fprintf(fp, "%s=", pref_opts[i].varname); fprintf(fp, "%s=", pref_opts[i].varname);
(*pref_opts[i].proc) (i, NULL, fp); (*pref_opts[i].proc)(i, NULL, fp);
fprintf(fp, "\n"); fprintf(fp, "\n");
} }
fclose(fp); fclose(fp);
@@ -537,7 +538,6 @@ void load_prefs()
if ((fp = fopen(config_fname, "rt")) == NULL) if ((fp = fopen(config_fname, "rt")) == NULL)
{ {
if (errno == ENOENT) /*Create the file then if it doesnt exist */ if (errno == ENOENT) /*Create the file then if it doesnt exist */
{ {
save_prefs(); save_prefs();
@@ -567,7 +567,7 @@ void load_prefs()
if (strcmp(tok1, pref_opts[i].varname) == 0) if (strcmp(tok1, pref_opts[i].varname) == 0)
{ {
if (pref_opts[i].proc != NULL) if (pref_opts[i].proc != NULL)
(*pref_opts[i].proc) (i, tok2, NULL); (*pref_opts[i].proc)(i, tok2, NULL);
} }
} }
} }