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

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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,12 +170,12 @@ 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 */
#endif /* COMMON_H */ #endif /* COMMON_H */

View File

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* Connection routines. */ /* Connection routines. */
@ -30,18 +30,18 @@
/****************************************************************************** /******************************************************************************
Connect to the specified server. Connect to the specified server.
******************************************************************************/ ******************************************************************************/
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 *tout) struct timeval *tout)
{ {
int status, noblock, flags; int status, noblock, flags;
char szPort[10]; char szPort[10];
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;
assert(name != NULL); assert(name != NULL);
@ -53,17 +53,17 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(name, szPort, &hints, &res); error = getaddrinfo(name, szPort, &hints, &res);
if (error) if (error)
return HOSTERR; return HOSTERR;
/* Create a socket. */ /* Create a socket. */
if ((*sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1) if ((*sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1)
{ {
freeaddrinfo(res); freeaddrinfo(res);
return CONSOCKERR; return CONSOCKERR;
} }
/* Experimental. */ /* Experimental. */
flags = fcntl(*sock, F_GETFL, 0); flags = fcntl(*sock, F_GETFL, 0);
@ -76,60 +76,63 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
if ((status == -1) && (noblock != -1) && (errno == EINPROGRESS)) if ((status == -1) && (noblock != -1) && (errno == EINPROGRESS))
{
fd_set writefd;
FD_ZERO(&writefd);
FD_SET(*sock, &writefd);
status = select((*sock + 1), NULL, &writefd, NULL, &timeout);
/* Do we need to retry if the err is EINTR? */
if (status > 0)
{ {
socklen_t arglen = sizeof(int); fd_set writefd;
if (getsockopt(*sock, SOL_SOCKET, SO_ERROR, &status, &arglen) < 0) FD_ZERO(&writefd);
status = errno; FD_SET(*sock, &writefd);
if (status != 0) status = select((*sock + 1), NULL, &writefd, NULL, &timeout);
errno = status, status = -1;
if (errno == EINPROGRESS) /* Do we need to retry if the err is EINTR? */
errno = ETIMEDOUT;
} else if (status == 0) if (status > 0)
errno = ETIMEDOUT, status = -1; {
} socklen_t arglen = sizeof(int);
if (getsockopt(*sock, SOL_SOCKET, SO_ERROR, &status, &arglen) < 0)
status = errno;
if (status != 0)
errno = status, status = -1;
if (errno == EINPROGRESS)
errno = ETIMEDOUT;
}
else if (status == 0)
errno = ETIMEDOUT, status = -1;
}
if (status < 0) if (status < 0)
{ {
close(*sock); close(*sock);
if (errno == ECONNREFUSED) if (errno == ECONNREFUSED)
{ {
freeaddrinfo(res); freeaddrinfo(res);
return CONREFUSED; return CONREFUSED;
} else }
{ else
freeaddrinfo(res); {
return CONERROR; freeaddrinfo(res);
return CONERROR;
}
} }
} else else
{ {
flags = fcntl(*sock, F_GETFL, 0); flags = fcntl(*sock, F_GETFL, 0);
if (flags != -1) if (flags != -1)
fcntl(*sock, F_SETFL, flags & ~O_NONBLOCK); fcntl(*sock, F_SETFL, flags & ~O_NONBLOCK);
} }
/* Enable KEEPALIVE, so dead connections could be closed /* Enable KEEPALIVE, so dead connections could be closed
* earlier. Useful in conjuction with TCP kernel tuning * earlier. Useful in conjuction with TCP kernel tuning
* 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);
@ -137,7 +140,7 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
} }
/****************************************************************************** /******************************************************************************
... ...
******************************************************************************/ ******************************************************************************/
uerr_t bind_socket(int *sockfd) uerr_t bind_socket(int *sockfd)
{ {
@ -148,32 +151,32 @@ 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);
return BINDERR; return BINDERR;
} }
/* Allow only one server. */ /* Allow only one server. */
if (listen(*sockfd, 1) < 0) if (listen(*sockfd, 1) < 0)
{ {
perror("listen"); perror("listen");
close(*sockfd); close(*sockfd);
return LISTENERR; return LISTENERR;
} }
return BINDOK; return BINDOK;
} }
/****************************************************************************** /******************************************************************************
... ...
******************************************************************************/ ******************************************************************************/
int select_fd(int fd, struct timeval *timeout, int writep) int select_fd(int fd, struct timeval *timeout, int writep)
{ {
@ -186,15 +189,15 @@ 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));
} }
/****************************************************************************** /******************************************************************************
Receive size bytes from sock with a time delay. Receive size bytes from sock with a time delay.
******************************************************************************/ ******************************************************************************/
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 ret, arglen; int ret, arglen;
@ -203,40 +206,38 @@ int krecv(int sock, char *buffer, int size, int flags,
assert(size >= 0); assert(size >= 0);
do do
{
if (timeout)
{ {
do if (timeout)
{ {
ret = select_fd(sock, timeout, 0); do
} {
while ((ret == -1) && (errno == EINTR)); ret = select_fd(sock, timeout, 0);
} while ((ret == -1) && (errno == EINTR));
if (ret <= 0) if (ret <= 0)
{ {
/* proz_debug("Error after select res=%d errno=%d.", ret, errno); */ /* proz_debug("Error after select res=%d errno=%d.", ret, errno); */
/* Set errno to ETIMEDOUT on timeout. */ /* Set errno to ETIMEDOUT on timeout. */
if (ret == 0) if (ret == 0)
errno = ETIMEDOUT; errno = ETIMEDOUT;
return -1; return -1;
} }
} }
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;
} }
/****************************************************************************** /******************************************************************************
Send size bytes to sock with a time delay. Send size bytes to sock with a time delay.
******************************************************************************/ ******************************************************************************/
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)
{ {
int ret = 0; int ret = 0;
@ -246,40 +247,38 @@ int ksend(int sock, char *buffer, int size, int flags,
innermost loop deals with the same during select(). */ innermost loop deals with the same during select(). */
while (size != 0) while (size != 0)
{
do
{ {
if (timeout) do
{ {
do if (timeout)
{ {
ret = select_fd(sock, timeout, 1); do
} {
while ((ret == -1) && (errno == EINTR)); ret = select_fd(sock, timeout, 1);
} while ((ret == -1) && (errno == EINTR));
if (ret <= 0) if (ret <= 0)
{ {
/* Set errno to ETIMEDOUT on timeout. */ /* Set errno to ETIMEDOUT on timeout. */
if (ret == 0) if (ret == 0)
errno = ETIMEDOUT; errno = ETIMEDOUT;
return -1; return -1;
} }
} }
ret = send(sock, buffer, size, flags); ret = send(sock, buffer, size, flags);
} while ((ret == -1) && (errno == EINTR));
if (ret <= 0)
break;
buffer += ret;
size -= ret;
} }
while ((ret == -1) && (errno == EINTR));
if (ret <= 0)
break;
buffer += ret;
size -= ret;
}
return ret; return ret;
} }
/****************************************************************************** /******************************************************************************
Accept a connection. Accept a connection.
******************************************************************************/ ******************************************************************************/
uerr_t accept_connection(int listen_sock, int *data_sock) uerr_t accept_connection(int listen_sock, int *data_sock)
{ {
@ -287,12 +286,12 @@ 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");
return ACCEPTERR; return ACCEPTERR;
} }
*data_sock = sockfd; *data_sock = sockfd;

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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
@ -32,22 +32,22 @@
#ifdef __cplusplus #ifdef __cplusplus
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
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* CONNECT_H */ #endif /* CONNECT_H */

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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"
@ -33,7 +33,7 @@
/****************************************************************************** /******************************************************************************
... ...
******************************************************************************/ ******************************************************************************/
void init_response(connection_t * connection) void init_response(connection_t * connection)
{ {
@ -41,8 +41,8 @@ void init_response(connection_t * connection)
} }
/****************************************************************************** /******************************************************************************
This will free up the serv_ret_lines array if necessary, in order to prepare This will free up the serv_ret_lines array if necessary, in order to prepare
it for the storage of the servers response. it for the storage of the servers response.
******************************************************************************/ ******************************************************************************/
void done_with_response(connection_t * connection) void done_with_response(connection_t * connection)
{ {
@ -55,52 +55,51 @@ void done_with_response(connection_t * connection)
p1 = connection->serv_ret_lines; p1 = connection->serv_ret_lines;
do do
{ {
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;
} }
/****************************************************************************** /******************************************************************************
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));
/* Copy the proxy structs. */ /* Copy the proxy structs. */
if (libprozrtinfo.ftp_proxy) if (libprozrtinfo.ftp_proxy)
{ {
connection->ftp_proxy = kmalloc(sizeof(proxy_info)); connection->ftp_proxy = kmalloc(sizeof(proxy_info));
memcpy(connection->ftp_proxy, libprozrtinfo.ftp_proxy, memcpy(connection->ftp_proxy, libprozrtinfo.ftp_proxy,
sizeof(proxy_info)); sizeof(proxy_info));
/* /*
connection->use_ftp_proxy = libprozrtinfo.use_ftp_proxy; connection->use_ftp_proxy = libprozrtinfo.use_ftp_proxy;
*/ */
} }
if (libprozrtinfo.http_proxy) if (libprozrtinfo.http_proxy)
{ {
connection->http_proxy = kmalloc(sizeof(proxy_info)); connection->http_proxy = kmalloc(sizeof(proxy_info));
memcpy(connection->http_proxy, libprozrtinfo.http_proxy, memcpy(connection->http_proxy, libprozrtinfo.http_proxy,
sizeof(proxy_info)); sizeof(proxy_info));
/* /*
connection->use_http_proxy = libprozrtinfo.use_http_proxy; connection->use_http_proxy = libprozrtinfo.use_http_proxy;
*/ */
} }
connection->use_netrc = libprozrtinfo.use_netrc; connection->use_netrc = libprozrtinfo.use_netrc;
@ -115,13 +114,13 @@ connection_t * proz_connection_init(urlinfo *url,pthread_mutex_t * mutex)
connection->attempts = 0; connection->attempts = 0;
/* Initialise all with default timeouts */ /* Initialise all with default timeouts */
memcpy(&connection->xfer_timeout, &libprozrtinfo.conn_timeout, memcpy(&connection->xfer_timeout, &libprozrtinfo.conn_timeout,
sizeof(connection->xfer_timeout)); sizeof(connection->xfer_timeout));
memcpy(&connection->ctrl_timeout, &libprozrtinfo.conn_timeout, memcpy(&connection->ctrl_timeout, &libprozrtinfo.conn_timeout,
sizeof(connection->ctrl_timeout)); sizeof(connection->ctrl_timeout));
memcpy(&connection->conn_timeout, &libprozrtinfo.conn_timeout, memcpy(&connection->conn_timeout, &libprozrtinfo.conn_timeout,
sizeof(connection->conn_timeout)); sizeof(connection->conn_timeout));
memcpy(&connection->retry_delay, &libprozrtinfo.conn_retry_delay, memcpy(&connection->retry_delay, &libprozrtinfo.conn_retry_delay,
sizeof(&connection->retry_delay)); sizeof(&connection->retry_delay));
connection->max_attempts = libprozrtinfo.max_attempts; connection->max_attempts = libprozrtinfo.max_attempts;
connection->rate_bps = 0; connection->rate_bps = 0;
@ -130,9 +129,9 @@ connection_t * proz_connection_init(urlinfo *url,pthread_mutex_t * mutex)
pthread_cond_init(&connection->connecting_cond, NULL); pthread_cond_init(&connection->connecting_cond, NULL);
connection->status_change_mutex = mutex; connection->status_change_mutex = mutex;
if (connection->status_change_mutex != 0) if (connection->status_change_mutex != 0)
{ {
pthread_mutex_init(connection->status_change_mutex, NULL); pthread_mutex_init(connection->status_change_mutex, NULL);
} }
pthread_mutex_init(&connection->access_mutex, NULL); pthread_mutex_init(&connection->access_mutex, NULL);
return connection; return connection;
@ -142,11 +141,11 @@ connection_t * proz_connection_init(urlinfo *url,pthread_mutex_t * mutex)
void connection_change_status(connection_t * connection, dl_status status) void connection_change_status(connection_t * connection, dl_status status)
{ {
if (connection->status_change_mutex != 0) if (connection->status_change_mutex != 0)
{ {
pthread_mutex_lock(connection->status_change_mutex); pthread_mutex_lock(connection->status_change_mutex);
connection->status = status; connection->status = status;
pthread_mutex_unlock(connection->status_change_mutex); pthread_mutex_unlock(connection->status_change_mutex);
} }
} }
@ -154,11 +153,11 @@ 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,
int read_buffer_size) int read_buffer_size)
{ {
off_t bytes_read; off_t bytes_read;
@ -166,52 +165,51 @@ uerr_t connection_retr_fsize_not_known(connection_t * connection,
gettimeofday(&connection->time_begin, NULL); gettimeofday(&connection->time_begin, NULL);
do do
{
bytes_read =
krecv(connection->data_sock, read_buffer, read_buffer_size, 0,
&connection->xfer_timeout);
if (bytes_read > 0)
{ {
if (write_data_with_lock(connection, read_buffer, sizeof(char), bytes_read) < bytes_read) bytes_read =
{ krecv(connection->data_sock, read_buffer, read_buffer_size, 0,
proz_debug(_("write failed")); &connection->xfer_timeout);
connection_show_message(connection, if (bytes_read > 0)
_ {
("Unable to write to file %s: %s!"), if (write_data_with_lock(connection, read_buffer, sizeof(char), bytes_read) < bytes_read)
connection->localfile, strerror(errno)); {
connection_change_status(connection, LOCALFATAL); proz_debug(_("write failed"));
return FWRITEERR; connection_show_message(connection,
} _
pthread_mutex_lock(&connection->access_mutex); ("Unable to write to file %s: %s!"),
connection->remote_bytes_received += bytes_read; connection->localfile, strerror(errno));
pthread_mutex_unlock(&connection->access_mutex); connection_change_status(connection, LOCALFATAL);
return FWRITEERR;
}
pthread_mutex_lock(&connection->access_mutex);
connection->remote_bytes_received += bytes_read;
pthread_mutex_unlock(&connection->access_mutex);
/*TODO: caclculate and throttle connections speed here */ /*TODO: caclculate and throttle connections speed here */
/*DONE: */ /*DONE: */
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)
{
if (errno == ETIMEDOUT)
{ {
proz_debug(_("connection timed out")); if (errno == ETIMEDOUT)
connection_change_status(connection, TIMEDOUT); {
proz_debug(_("connection timed out"));
connection_change_status(connection, TIMEDOUT);
return READERR;
}
connection_change_status(connection, REMOTEFATAL);
return READERR; return READERR;
} }
connection_change_status(connection, REMOTEFATAL);
return READERR;
}
connection_change_status(connection, COMPLETED); connection_change_status(connection, COMPLETED);
connection_show_message(connection, connection_show_message(connection,
_("download for this connection completed" _("download for this connection completed"
"%s : %ld received"), connection->localfile, "%s : %ld received"), connection->localfile,
connection->remote_bytes_received); connection->remote_bytes_received);
return FILEGETOK; return FILEGETOK;
} }
@ -221,9 +219,9 @@ 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)
{ {
off_t bytes_read; off_t bytes_read;
off_t bytes_to_get; off_t bytes_to_get;
@ -236,94 +234,90 @@ uerr_t connection_retr_fsize_known(connection_t * connection,
gettimeofday(&connection->time_begin, NULL); gettimeofday(&connection->time_begin, NULL);
while (bytes_to_get > 0) while (bytes_to_get > 0)
{
bytes_read =
krecv(connection->data_sock, read_buffer,
bytes_to_get >
read_buffer_size ? read_buffer_size : bytes_to_get, 0,
&connection->xfer_timeout);
if (bytes_read == 0 && bytes_to_get > 0)
{ {
connection_show_message(connection, bytes_read =
_("Server Closed Connection Prematurely!")); krecv(connection->data_sock, read_buffer,
connection_change_status(connection, REMOTEFATAL); bytes_to_get >
return READERR; read_buffer_size ? read_buffer_size : bytes_to_get, 0,
&connection->xfer_timeout);
if (bytes_read == 0 && bytes_to_get > 0)
{
connection_show_message(connection,
_("Server Closed Connection Prematurely!"));
connection_change_status(connection, REMOTEFATAL);
return READERR;
}
if (bytes_read == -1)
{
if (errno == ETIMEDOUT)
{
proz_debug(_("connection timed out"));
connection_change_status(connection, TIMEDOUT);
return READERR;
}
connection_change_status(connection, REMOTEFATAL);
return READERR;
}
bytes_to_get -= bytes_read;
if (bytes_read > 0)
{
if (write_data_with_lock(connection, read_buffer, sizeof(char), bytes_read) < bytes_read)
{
proz_debug(_("write failed"));
connection_show_message(connection,
_
("Unable to write to file %s: %s!"),
connection->localfile, strerror(errno));
connection_change_status(connection, LOCALFATAL);
return FWRITEERR;
}
pthread_mutex_lock(&connection->access_mutex);
connection->remote_bytes_received += bytes_read;
pthread_mutex_unlock(&connection->access_mutex);
/*TODO: caclculate and throttle connections speed here */
/*DONE: */
connection_calc_ratebps(connection);
connection_throttle_bps(connection);
}
} }
if (bytes_read == -1)
{
if (errno == ETIMEDOUT)
{
proz_debug(_("connection timed out"));
connection_change_status(connection, TIMEDOUT);
return READERR;
}
connection_change_status(connection, REMOTEFATAL);
return READERR;
}
bytes_to_get -= bytes_read;
if (bytes_read > 0)
{
if (write_data_with_lock(connection, read_buffer, sizeof(char), bytes_read) < bytes_read)
{
proz_debug(_("write failed"));
connection_show_message(connection,
_
("Unable to write to file %s: %s!"),
connection->localfile, strerror(errno));
connection_change_status(connection, LOCALFATAL);
return FWRITEERR;
}
pthread_mutex_lock(&connection->access_mutex);
connection->remote_bytes_received += bytes_read;
pthread_mutex_unlock(&connection->access_mutex);
/*TODO: caclculate and throttle connections speed here */
/*DONE: */
connection_calc_ratebps(connection);
connection_throttle_bps(connection);
}
}
connection_change_status(connection, COMPLETED); connection_change_status(connection, COMPLETED);
connection_show_message(connection, connection_show_message(connection,
_("download for this connection completed" _("download for this connection completed"
"%s : %ld received"), connection->localfile, "%s : %ld received"), connection->localfile,
connection->remote_bytes_received); connection->remote_bytes_received);
return FILEGETOK; return FILEGETOK;
} }
/* 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)
{
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->orig_remote_startpos));
proz_debug("connection->remote start pos after loading %ld", connection->remote_startpos);
}
if(connection->remote_startpos-connection->orig_remote_startpos!=connection->remote_bytes_received)
{
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->orig_remote_startpos));
proz_debug("connection->remote start pos after loading %ld", connection->remote_startpos);
}
return 1; return 1;
} }
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,48 +329,50 @@ 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:
return(_("Idle"));
case IDLE: case CONNECTING:
return (_("Idle")); return(_("Connecting"));
case CONNECTING: case LOGGININ:
return (_("Connecting")); return(_("Logging in"));
case LOGGININ: case DOWNLOADING:
return (_("Logging in")); return(_("Downloading"));
break;
case DOWNLOADING: case COMPLETED:
return (_("Downloading")); return(_("Completed"));
break;
case 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:
return (_("Max attempts reached"));
default: case MAXTRYS:
return (_("Unkown Status!")); return(_("Max attempts reached"));
}
default:
return(_("Unkown Status!"));
}
} }
@ -384,7 +380,7 @@ pthread_mutex_t connection_msg_mutex = PTHREAD_MUTEX_INITIALIZER;
/*calls the msg_proc function if not null */ /*calls the msg_proc function if not null */
void connection_show_message(connection_t * connection, const char *format, void connection_show_message(connection_t * connection, const char *format,
...) ...)
{ {
va_list args; va_list args;
char message[MAX_MSG_SIZE + 1]; char message[MAX_MSG_SIZE + 1];
@ -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? */
@ -456,65 +451,66 @@ void get_url_info_loop(connection_t * connection)
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
do do
{
switch (connection->u.proto)
{ {
case URLHTTP: switch (connection->u.proto)
connection->err = http_get_url_info_loop(connection); {
break; case URLHTTP:
case URLFTP: connection->err = http_get_url_info_loop(connection);
connection->err = ftp_get_url_info_loop(connection); break;
break;
default:
proz_die(_("Error: unsupported protocol"));
}
if (connection->err == NEWLOCATION) case URLFTP:
{ connection->err = ftp_get_url_info_loop(connection);
char *constructed_newloc; break;
char *referer;
referer=kstrdup(connection->u.url);
/*DONE : handle relative urls too */
constructed_newloc =
uri_merge(connection->u.url, connection->hs.newloc);
proz_debug("Redirected to %s, merged URL = %s", default:
connection->hs.newloc, constructed_newloc); proz_die(_("Error: unsupported protocol"));
}
proz_free_url(&connection->u, 0); if (connection->err == NEWLOCATION)
connection->err = {
proz_parse_url(constructed_newloc, &connection->u, 0); char *constructed_newloc;
char *referer;
referer = kstrdup(connection->u.url);
/*DONE : handle relative urls too */
constructed_newloc =
uri_merge(connection->u.url, connection->hs.newloc);
proz_debug("Redirected to %s, merged URL = %s",
connection->hs.newloc, constructed_newloc);
proz_free_url(&connection->u, 0);
connection->err =
proz_parse_url(constructed_newloc, &connection->u, 0);
if (connection->err != URLOK) if (connection->err != URLOK)
{ {
connection_show_message(connection, connection_show_message(connection,
_ _
("The server returned location is wrong: %s!"), ("The server returned location is wrong: %s!"),
constructed_newloc); constructed_newloc);
pthread_mutex_lock(&connection->access_mutex); pthread_mutex_lock(&connection->access_mutex);
connection->running = FALSE; connection->running = FALSE;
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
kfree(constructed_newloc); kfree(constructed_newloc);
connection->err = HERR; connection->err = HERR;
return; return;
} else }
connection_show_message(connection, _("Redirected to => %s"), else
constructed_newloc); connection_show_message(connection, _("Redirected to => %s"),
connection->u.referer=referer; constructed_newloc);
kfree(constructed_newloc); connection->u.referer = referer;
connection->err = NEWLOCATION; kfree(constructed_newloc);
} connection->err = NEWLOCATION;
}
} } while (connection->err == NEWLOCATION);
while (connection->err == NEWLOCATION);
return; return;
} }
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)
{ {
assert(connection != NULL); assert(connection != NULL);
@ -535,16 +531,16 @@ 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) */
/* { */ /* { */
@ -552,21 +548,21 @@ void connection_calc_ratebps(connection_t * connection)
/* return; */ /* return; */
/* } */ /* } */
/* 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); */
/* } */ /* } */
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);
return; return;
}
else
connection->rate_bps =
((float)(connection->remote_bytes_received
- (connection->remote_startpos - connection->orig_remote_startpos)) * 10e5 / diff_us);
} }
else
connection->rate_bps =
((float) (connection->remote_bytes_received
- (connection->remote_startpos-connection->orig_remote_startpos)) * 10e5 / diff_us);
}
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
return; return;
@ -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;
@ -586,93 +581,94 @@ void connection_throttle_bps(connection_t * connection)
pthread_mutex_lock(&connection->access_mutex); pthread_mutex_lock(&connection->access_mutex);
con_timeout_usecs = con_timeout_usecs =
(connection->conn_timeout.tv_sec * 10e5) + (connection->conn_timeout.tv_sec * 10e5) +
connection->conn_timeout.tv_usec; connection->conn_timeout.tv_usec;
if (connection->rate_bps == 0 || connection->max_allowed_bps == 0) if (connection->rate_bps == 0 || connection->max_allowed_bps == 0)
{ {
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
return; return;
} }
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)
{ {
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
return; return;
} }
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)
{ {
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
return; return;
} }
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);
memset(&tv_delay, 0, sizeof(tv_delay)); memset(&tv_delay, 0, sizeof(tv_delay));
if (wtime > diff_us) if (wtime > diff_us)
{
/*too fast have to delay */
// proz_debug("wtime %f, diff_us %f", wtime, diff_us);
if ((wtime - diff_us) > con_timeout_usecs) /* problem here */
{ {
/*If we were to delay for wtime-diff_us we would cause a connection /*too fast have to delay */
timeout, so rather than doing that shall we delay for a bit lesser // proz_debug("wtime %f, diff_us %f", wtime, diff_us);
than the time for the timeout, like say 1 second less if ((wtime - diff_us) > con_timeout_usecs) /* problem here */
*/ {
const int limit_time_us = 2 * 10e5; /*If we were to delay for wtime-diff_us we would cause a connection
timeout, so rather than doing that shall we delay for a bit lesser
than the time for the timeout, like say 1 second less
*/
const int limit_time_us = 2 * 10e5;
/* Will the connection timeout - limit_time_us be less or equal to 0? /* Will the connection timeout - limit_time_us be less or equal to 0?
If so no point in delaing beacuse the connection wold timeout If so no point in delaing beacuse the connection wold timeout
*/ */
if ((con_timeout_usecs - limit_time_us) <= 0) if ((con_timeout_usecs - limit_time_us) <= 0)
{ {
proz_debug proz_debug
("Cant throttle: Connection would timeout if done so, please try increasing the timeout value"); ("Cant throttle: Connection would timeout if done so, please try increasing the timeout value");
return; return;
} }
tv_delay.tv_usec = con_timeout_usecs - limit_time_us; tv_delay.tv_usec = con_timeout_usecs - limit_time_us;
/* message /* message
("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"
proz_debug("sleeping %f secs\n", (wtime - diff_us) / 10e5); proz_debug("sleeping %f secs\n", (wtime - diff_us) / 10e5);
}
tv_delay.tv_sec = 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)
{
proz_debug("Unable to throttle Bandwith\n");
}
} }
tv_delay.tv_sec = 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)
{
proz_debug("Unable to throttle Bandwith\n");
}
}
} }
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);
@ -682,13 +678,13 @@ boolean proz_connection_running(connection_t * connection)
void proz_connection_set_url(connection_t * connection, urlinfo *url) void proz_connection_set_url(connection_t * connection, urlinfo *url)
{ {
assert(url); assert(url);
memcpy(&connection->u, memcpy(&connection->u,
proz_copy_url(url), proz_copy_url(url),
sizeof(urlinfo)); sizeof(urlinfo));
} }
void proz_connection_free_connection(connection_t * connection, void proz_connection_free_connection(connection_t * connection,
boolean complete) boolean complete)
{ {
assert(connection); assert(connection);
/*TODO what about szBuffer..also have to free the URL u */ /*TODO what about szBuffer..also have to free the URL u */
@ -707,9 +703,9 @@ void proz_connection_free_connection(connection_t * connection,
/* free the serv_ret_lines array */ /* free the serv_ret_lines array */
if (connection->serv_ret_lines != 0) if (connection->serv_ret_lines != 0)
{ {
done_with_response(connection); done_with_response(connection);
} }
if (complete == TRUE) if (complete == TRUE)
kfree(connection); kfree(connection);
@ -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

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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,29 +35,29 @@
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
} }
#endif #endif
#endif /* CONNECTION_H */ #endif /* CONNECTION_H */

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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,28 +43,28 @@ 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);
if (unlink(logfile_name) == -1) if (unlink(logfile_name) == -1)
{
/*
* if the file is not present the continue silently
*/
if (errno == ENOENT)
return;
else
{ {
proz_debug(_("unable to delete the file %s. Reason-: %s"), /*
strerror(errno)); * if the file is not present the continue silently
*/
if (errno == ENOENT)
return;
else
{
proz_debug(_("unable to delete the file %s. Reason-: %s"),
strerror(errno));
}
} }
}
} }
/****************************************************************************** /******************************************************************************
Write a message to the debug-file. Write a message to the debug-file.
******************************************************************************/ ******************************************************************************/
void proz_debug(const char *format, ...) void proz_debug(const char *format, ...)
{ {
@ -73,41 +73,42 @@ 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);
pthread_mutex_lock(&debug_mutex); pthread_mutex_lock(&debug_mutex);
if (libprozrtinfo.debug_mode == TRUE) if (libprozrtinfo.debug_mode == TRUE)
{
va_start(args, format);
vsnprintf((char *) &message, MAX_MSG_SIZE, format, args);
va_end(args);
/* Remove all newlines from the end of the string. */
while ((message[strlen(message) - 1] == '\r')
|| (message[strlen(message) - 1] == '\n'))
message[strlen(message) - 1] = '\0';
/* Append a newline. */
message[strlen(message) + 1] = '\0';
message[strlen(message)] = '\n';
if (!(fp = fopen(logfile_name, "at")))
{ {
pthread_mutex_unlock(&debug_mutex); va_start(args, format);
return; vsnprintf((char *)&message, MAX_MSG_SIZE, format, args);
} va_end(args);
/* Remove all newlines from the end of the string. */
while ((message[strlen(message) - 1] == '\r')
|| (message[strlen(message) - 1] == '\n'))
message[strlen(message) - 1] = '\0';
/* Append a newline. */
message[strlen(message) + 1] = '\0';
message[strlen(message)] = '\n';
if (!(fp = fopen(logfile_name, "at")))
{
pthread_mutex_unlock(&debug_mutex);
return;
}
if (fwrite(message, 1, strlen(message), fp) != strlen(message))
{
pthread_mutex_unlock(&debug_mutex);
fclose(fp);
return;
}
if (fwrite(message, 1, strlen(message), fp) != strlen(message))
{
pthread_mutex_unlock(&debug_mutex);
fclose(fp); fclose(fp);
return;
} }
fclose(fp);
}
pthread_mutex_unlock(&debug_mutex); pthread_mutex_unlock(&debug_mutex);
} }

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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
@ -30,4 +30,4 @@
void debug_init(); void debug_init();
#endif /* DEBUG_H */ #endif /* DEBUG_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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,17 +35,17 @@
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
#endif /* DOWNLOAD_H */ #endif /* DOWNLOAD_H */

View File

@ -1,23 +1,23 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* $Id: ftp-retr.c,v 1.18 2005/01/11 01:49:11 sean Exp $ */ /* $Id$ */
#include "common.h" #include "common.h"
@ -57,10 +57,10 @@ uerr_t proz_ftp_get_file(connection_t * connection)
/* if there is nothing to download then return */ /* if there is nothing to download then return */
if (connection->status == COMPLETED) if (connection->status == COMPLETED)
{ {
gettimeofday(&connection->time_begin, NULL); gettimeofday(&connection->time_begin, NULL);
return FTPOK; return FTPOK;
} }
init_response(connection); init_response(connection);
@ -74,34 +74,35 @@ uerr_t proz_ftp_get_file(connection_t * connection)
*/ */
if (ftp_use_proxy(connection) if (ftp_use_proxy(connection)
&& connection->ftp_proxy->type == HTTPPROXY) && connection->ftp_proxy->type == HTTPPROXY)
{ {
err = ftp_get_file_from_http_proxy(connection); err = ftp_get_file_from_http_proxy(connection);
return err; return err;
} }
if (ftp_use_proxy(connection)) if (ftp_use_proxy(connection))
{ {
/* Connect to the proxy server here. */ /* Connect to the proxy server here. */
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, {
connection->u.port); err = ftp_connect_to_server(connection, connection->u.host,
} connection->u.port);
}
if (err == FTPCONREFUSED) if (err == FTPCONREFUSED)
{ {
connection_change_status(connection, CONREJECT); connection_change_status(connection, CONREJECT);
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
return err; return err;
} }
if (err != FTPOK) if (err != FTPOK)
{ {
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
return err; return err;
} }
done_with_response(connection); done_with_response(connection);
@ -110,15 +111,15 @@ uerr_t proz_ftp_get_file(connection_t * connection)
/* Use .netrc if asked to do so. */ /* Use .netrc if asked to do so. */
if (connection->use_netrc == TRUE) if (connection->use_netrc == TRUE)
{
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
if (netrc_ent != NULL)
{ {
user = netrc_ent->account; netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
passwd = netrc_ent->password;
if (netrc_ent != NULL)
{
user = netrc_ent->account;
passwd = netrc_ent->password;
}
} }
}
user = user ? user : libprozrtinfo.ftp_default_user; user = user ? user : libprozrtinfo.ftp_default_user;
passwd = passwd ? passwd : libprozrtinfo.ftp_default_passwd; passwd = passwd ? passwd : libprozrtinfo.ftp_default_passwd;
@ -129,97 +130,100 @@ uerr_t proz_ftp_get_file(connection_t * connection)
init_response(connection); init_response(connection);
err = ftp_login(connection, user, passwd); err = ftp_login(connection, user, passwd);
if (err != FTPOK) if (err != FTPOK)
{
if (err == FTPLOGREFUSED)
{ {
connection_change_status(connection, LOGINFAIL); if (err == FTPLOGREFUSED)
} else {
{ connection_change_status(connection, LOGINFAIL);
connection_change_status(connection, REMOTEFATAL); }
else
{
connection_change_status(connection, REMOTEFATAL);
}
close_sock(&connection->ctrl_sock);
return err;
} }
close_sock(&connection->ctrl_sock);
return err;
}
done_with_response(connection); done_with_response(connection);
init_response(connection); init_response(connection);
err = ftp_binary(connection); err = ftp_binary(connection);
if (err != FTPOK) if (err != FTPOK)
{ {
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
return err; return err;
} }
done_with_response(connection); done_with_response(connection);
/* Do we need to CWD? */ /* Do we need to CWD? */
if (*connection->u.dir) if (*connection->u.dir)
{ {
init_response(connection); init_response(connection);
err = ftp_cwd(connection, connection->u.dir); err = ftp_cwd(connection, connection->u.dir);
if (err != FTPOK) if (err != FTPOK)
{ {
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
proz_debug(_("CWD failed to change to directory '%s'."), proz_debug(_("CWD failed to change to directory '%s'."),
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.")); {
done_with_response(connection); proz_debug(_("CWD ok."));
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);
if (err != FTPOK) if (err != FTPOK)
{ {
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
return err; return err;
} }
/* do we need to REST */ /* do we need to REST */
if (connection->remote_startpos > 0 if (connection->remote_startpos > 0
&& connection->resume_support == TRUE) && connection->resume_support == TRUE)
{ {
err = ftp_rest(connection, connection->remote_startpos); err = ftp_rest(connection, connection->remote_startpos);
} }
if (err != FTPOK) if (err != FTPOK)
{ {
if (err == FTPRESTFAIL) if (err == FTPRESTFAIL)
proz_debug proz_debug
(_ (_
("I have a bug in my code!!, check remote_starpos and resume_support values")); ("I have a bug in my code!!, check remote_starpos and resume_support values"));
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
return err; return err;
} }
err = ftp_retr(connection, connection->u.file); err = ftp_retr(connection, connection->u.file);
if (err != FTPOK) if (err != FTPOK)
{ {
proz_debug(_("RETR failed")); proz_debug(_("RETR failed"));
close_sock(&connection->ctrl_sock); close_sock(&connection->ctrl_sock);
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
return err; return err;
} }
err = ftp_setup_data_sock_2(connection, &passive_mode); err = ftp_setup_data_sock_2(connection, &passive_mode);
if (err != FTPOK) if (err != FTPOK)
{ {
return err; return err;
} }
/* which routine to call */ /* which routine to call */
if (connection->main_file_size == -1) if (connection->main_file_size == -1)
err = err =
connection_retr_fsize_not_known(connection, buffer, connection_retr_fsize_not_known(connection, buffer,
sizeof(buffer)); sizeof(buffer));
else else
err = connection_retr_fsize_known(connection, buffer, sizeof(buffer)); err = connection_retr_fsize_known(connection, buffer, sizeof(buffer));
@ -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)
{ {
@ -249,84 +253,82 @@ uerr_t ftp_loop(connection_t * connection)
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
do do
{
if (connection->attempts > 0)
{ {
if (connection->attempts > 0)
{
if (retrying_from_loop == TRUE)
{
connection_show_message(connection,
_("Retrying..Attempt %d in %d seconds"),
connection->attempts,
connection->retry_delay.tv_sec);
delay_ms(connection->retry_delay.tv_sec * 1000);
}
if (retrying_from_loop == TRUE) if (connection->resume_support == TRUE)
{ {
connection_show_message(connection, if (connection_load_resume_info(connection) == -1)
_("Retrying..Attempt %d in %d seconds"), {
connection->attempts, connection_show_message(connection,
connection->retry_delay.tv_sec); _
delay_ms(connection->retry_delay.tv_sec * 1000); ("Error while attemting to process download file "));
} }
}
if (connection->resume_support == TRUE) else
{ {
if (connection_load_resume_info(connection) == -1) /*If we cant resume then reset the connections bytesreceived to 0 */
{ connection->remote_bytes_received = 0;
connection_show_message(connection, }
_ }
("Error while attemting to process download file "));
}
} else
{
/*If we cant resume then reset the connections bytesreceived to 0 */
connection->remote_bytes_received = 0;
}
}
/*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);
/*pop the handler */ /*pop the handler */
pthread_cleanup_pop(0); pthread_cleanup_pop(0);
connection->attempts++; connection->attempts++;
/*Should the error be handled at this level ? */ /*Should the error be handled at this level ? */
if (!ftp_loop_handle_error(connection->err)) if (!ftp_loop_handle_error(connection->err))
{ {
return connection->err; /*If not return and the main thread will handle it */ return connection->err; /*If not return and the main thread will handle it */
} }
switch (connection->err) switch (connection->err)
{ {
case FTPOK: case FTPOK:
connection_show_message(connection, _("Successfully got download")); connection_show_message(connection, _("Successfully got download"));
return connection->err; return connection->err;
break; break;
default: default:
connection_show_message(connection, connection_show_message(connection,
_("Error occured in connection...")); _("Error occured in 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);
connection_show_message(connection, connection_show_message(connection,
_ _
("I have tried %d attempt(s) and have failed, aborting"), ("I have tried %d attempt(s) and have failed, aborting"),
connection->attempts); connection->attempts);
return connection->err; return connection->err;
} }
/*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

@ -1,23 +1,23 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* $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,12 +29,12 @@
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
} }
#endif #endif
#endif /* FTP_RETR_H */ #endif /* FTP_RETR_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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,44 +34,44 @@
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
#endif /* FTP_H */ #endif /* FTP_H */

View File

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
//Rewrite of the ftp parsing code as we needed to extract the date of //Rewrite of the ftp parsing code as we needed to extract the date of
@ -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;
@ -59,63 +60,82 @@ long getlong(char *buf,int len)
** can optionally be quoted using <"> or "<" ">" ** can optionally be quoted using <"> or "<" ">"
** Comments surrrounded by '(' ')' are filtered out ** Comments surrrounded by '(' ')' are filtered out
** **
** On exit, ** On exit,
** *pstr has been moved to the first delimiter past the ** *pstr has been moved to the first delimiter past the
** field ** field
** THE STRING HAS BEEN MUTILATED by a 0 terminator ** THE STRING HAS BEEN MUTILATED by a 0 terminator
** **
** 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) {
/* Strip white space and other delimiters */
while (*p && (isspace((int) *p) || *p==',' || *p==';' || *p=='=')) p++;
if (!*p) {
*pstr = p;
return NULL; /* No field */
}
if (*p == '"') { /* quoted field */ if (!pstr || !*pstr)
start = ++p; return NULL;
for(;*p && *p!='"'; p++) while (1)
if (*p == '\\' && *(p+1)) p++; /* Skip escaped chars */ {
break; /* kr95-10-9: needs to stop here */ /* Strip white space and other delimiters */
} else if (*p == '<') { /* quoted field */ while (*p && (isspace((int)*p) || *p == ',' || *p == ';' || *p == '='))
start = ++p; p++;
for(;*p && *p!='>'; p++) if (!*p)
if (*p == '\\' && *(p+1)) p++; /* Skip escaped chars */ {
break; /* kr95-10-9: needs to stop here */ *pstr = p;
} else if (*p == '(') { /* Comment */ return NULL; /* No field */
for(;*p && *p!=')'; p++) }
if (*p == '\\' && *(p+1)) p++; /* Skip escaped chars */
p++; if (*p == '"') /* quoted field */
} else { /* Spool field */ {
start = p; start = ++p;
while(*p && !isspace((int) *p) && *p!=',' && *p!=';' && *p!='=') for (; *p && *p != '"'; p++)
p++; if (*p == '\\' && *(p + 1))
break; /* Got it */ p++;
} /* 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;
while (*p && !isspace((int)*p) && *p != ',' && *p != ';' && *p != '=')
p++;
break; /* Got it */
}
} }
if (*p) *p++ = '\0'; if (*p)
*pstr = p; *p++ = '\0';
return start; *pstr = p;
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':
@ -142,65 +163,71 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
case 'p': case 'p':
case 's': case 's':
case '-': case '-':
/* UNIX-style listing, without inum and without blocks */ /* UNIX-style listing, without inum and without blocks */
/* "-rw-r--r-- 1 root other 531 Jan 29 03:26 README" */ /* "-rw-r--r-- 1 root other 531 Jan 29 03:26 README" */
/* "dr-xr-xr-x 2 root other 512 Apr 8 1994 etc" */ /* "dr-xr-xr-x 2 root other 512 Apr 8 1994 etc" */
/* "dr-xr-xr-x 2 root 512 Apr 8 1994 etc" */ /* "dr-xr-xr-x 2 root 512 Apr 8 1994 etc" */
/* "lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" */ /* "lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" */
/* Also produced by Microsoft's FTP servers for Windows: */ /* Also produced by Microsoft's FTP servers for Windows: */
/* "---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z" */ /* "---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z" */
/* "d--------- 1 owner group 0 May 9 19:45 Softlib" */ /* "d--------- 1 owner group 0 May 9 19:45 Softlib" */
/* Also WFTPD for MSDOS: */ /* Also WFTPD for MSDOS: */
/* "-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp" */ /* "-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp" */
/* Also NetWare: */ /* Also NetWare: */
/* "d [R----F--] supervisor 512 Jan 16 18:53 login" */ /* "d [R----F--] supervisor 512 Jan 16 18:53 login" */
/* "- [R----F--] rhesus 214059 Oct 20 15:27 cx.exe" */ /* "- [R----F--] rhesus 214059 Oct 20 15:27 cx.exe" */
/* Also NetPresenz for the Mac: */ /* Also NetPresenz for the Mac: */
/* "-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit" */ /* "-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit" */
/* "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
** next field. If this is a non-digit then this field is the size.
*/
while (*cp && isspace((int)*cp))
cp++;
if (isdigit((int)*cp))
{
token = get_nextfield(&cp);
while (*cp && isspace((int)*cp))
cp++;
}
//if it is a filename
fp->filesize = strtol(token, NULL, 10);
proz_debug("FTP file size is %ld", fp->filesize);
while (*cp && isspace((int)*cp))
cp++;
assert(cp + 12 < ptr + len);
date = cp;
cp += 12;
*cp++ = '\0';
fp->date_str = strdup(date);
proz_debug("LIST date is %s", fp->date_str);
return FTPPARSEOK;
default:
return FTPPARSEFAIL;
} }
/*
** This field can either be group or size. We find out by looking at the
** next field. If this is a non-digit then this field is the size.
*/
while (*cp && isspace((int) *cp)) cp++;
if (isdigit((int) *cp)) {
token = get_nextfield(&cp);
while (*cp && isspace((int) *cp)) cp++;
}
//if it is a filename
fp->filesize=strtol(token,NULL,10);
proz_debug("FTP file size is %ld", fp->filesize);
while (*cp && isspace((int) *cp)) cp++;
assert(cp+12<ptr+len);
date = cp;
cp += 12;
*cp++ = '\0';
fp->date_str = strdup(date);
proz_debug("LIST date is %s", fp->date_str);
return FTPPARSEOK;
default:
return FTPPARSEFAIL;
}
} }
@ -208,18 +235,16 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
time_t parse_time(const char * str) time_t parse_time(const char * str)
{ {
char * p;
struct tm tm;
time_t t;
char * p; if (!str)
struct tm tm;
time_t t;
if (!str) return 0;
if ((p = strchr(str, ',')))
{
}
return 0; return 0;
if ((p = strchr(str, ',')))
{
}
return 0;
} }

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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,13 +41,13 @@ 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
} }
#endif #endif
#endif /* FTPPARSE_H */ #endif /* FTPPARSE_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
@ -24,6 +24,6 @@
int ftpsearch_get_server_position(ftps_request_t * request, char *server); int ftpsearch_get_server_position(ftps_request_t * request, char *server);
int ftpsearch_get_path_position(ftps_request_t * request, char *server, int ftpsearch_get_path_position(ftps_request_t * request, char *server,
char *path); char *path);
#endif #endif

View File

@ -1,23 +1,23 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* $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"
@ -36,7 +36,7 @@ uerr_t proz_http_get_file(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 =
NULL, *location = NULL, *referer = NULL, *pragma_no_cache = NULL; NULL, *location = NULL, *referer = NULL, *pragma_no_cache = NULL;
char *request, *remote_port; char *request, *remote_port;
netrc_entry *netrc_ent; netrc_entry *netrc_ent;
char buffer[HTTP_BUFFER_SIZE]; char buffer[HTTP_BUFFER_SIZE];
@ -55,144 +55,148 @@ uerr_t proz_http_get_file(connection_t * connection)
/* if there is nothing to download then return */ /* if there is nothing to download then return */
if (connection->status == COMPLETED) if (connection->status == COMPLETED)
{ {
pthread_mutex_lock(&connection->access_mutex); pthread_mutex_lock(&connection->access_mutex);
gettimeofday(&connection->time_begin, NULL); gettimeofday(&connection->time_begin, NULL);
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
return HOK; return HOK;
} }
connection_change_status(connection, CONNECTING); connection_change_status(connection, CONNECTING);
if (http_use_proxy(connection)) if (http_use_proxy(connection))
{
connection_show_message(connection, _("Connecting to %s"),
connection->http_proxy->proxy_url.host);
err = connect_to_server(&connection->data_sock,
connection->http_proxy->proxy_url.host,
connection->http_proxy->proxy_url.port,
&connection->xfer_timeout);
if (err != NOCONERROR)
{ {
proz_debug(_("Error connecting to %s"), connection_show_message(connection, _("Connecting to %s"),
connection->http_proxy->proxy_url.host); connection->http_proxy->proxy_url.host);
connection_change_status(connection, REMOTEFATAL); err = connect_to_server(&connection->data_sock,
return err; connection->http_proxy->proxy_url.host,
connection->http_proxy->proxy_url.port,
&connection->xfer_timeout);
if (err != NOCONERROR)
{
proz_debug(_("Error connecting to %s"),
connection->http_proxy->proxy_url.host);
connection_change_status(connection, REMOTEFATAL);
return err;
}
} }
} else else
{ {
connection_show_message(connection, _("Connecting to %s"), connection_show_message(connection, _("Connecting to %s"),
connection->u.host); connection->u.host);
err = connect_to_server(&connection->data_sock, connection->u.host, err = connect_to_server(&connection->data_sock, connection->u.host,
connection->u.port, &connection->xfer_timeout); connection->u.port, &connection->xfer_timeout);
if (err != NOCONERROR) if (err != NOCONERROR)
{ {
proz_debug(_("Error connecting to %s"), connection->u.host); proz_debug(_("Error connecting to %s"), connection->u.host);
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
return err; return err;
}
} }
}
user = connection->u.user; user = connection->u.user;
passwd = connection->u.passwd; passwd = connection->u.passwd;
/* Use .netrc if asked to do so. */ /* Use .netrc if asked to do so. */
if (connection->use_netrc == TRUE) if (connection->use_netrc == TRUE)
{
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
if (netrc_ent != NULL)
{ {
user = netrc_ent->account; netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
passwd = netrc_ent->password;
if (netrc_ent != NULL)
{
user = netrc_ent->account;
passwd = netrc_ent->password;
}
} }
}
user = user ? user : ""; user = user ? user : "";
passwd = passwd ? passwd : ""; passwd = passwd ? passwd : "";
if (strlen(user) || strlen(passwd)) if (strlen(user) || strlen(passwd))
{ {
/* Construct the necessary header. */ /* Construct the necessary header. */
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))
{ {
if (strlen(connection->http_proxy->username) if (strlen(connection->http_proxy->username)
|| strlen(connection->http_proxy->passwd)) || strlen(connection->http_proxy->passwd))
proxy_auth = proxy_auth =
get_basic_auth_str(connection->http_proxy->username, get_basic_auth_str(connection->http_proxy->username,
connection->http_proxy->passwd, connection->http_proxy->passwd,
"Proxy-Authorization"); "Proxy-Authorization");
} }
if (connection->u.port == 80) if (connection->u.port == 80)
{ {
remote_port = NULL; remote_port = NULL;
remote_port_len = 0; remote_port_len = 0;
} else }
{ else
remote_port = (char *) alloca(64); {
remote_port_len = sprintf(remote_port, ":%d", connection->u.port); remote_port = (char *)alloca(64);
} 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); {
strcpy(location, connection->u.path); location = (char *)alloca(strlen(connection->u.path) + 1);
} strcpy(location, connection->u.path);
}
/*Use no-cache directive for proxy servers? */ /*Use no-cache directive for proxy servers? */
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)
+ (referer ? strlen(referer) : 0) + (referer ? strlen(referer) : 0)
+ (www_auth ? strlen(www_auth) : 0) + (www_auth ? strlen(www_auth) : 0)
+ (proxy_auth ? strlen(proxy_auth) : 0) + (proxy_auth ? strlen(proxy_auth) : 0)
+ 64 + 64
+ +
(pragma_no_cache ? strlen(pragma_no_cache) : (pragma_no_cache ? strlen(pragma_no_cache) :
0)); 0));
/* TODO Add referrer tag. */ /* TODO Add referrer tag. */
sprintf(request, sprintf(request,
"GET %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s%s\r\nAccept: */*\r\n%s%s%s%s%s\r\n", "GET %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s%s\r\nAccept: */*\r\n%s%s%s%s%s\r\n",
location, connection->user_agent, connection->u.host, location, connection->user_agent, connection->u.host,
remote_port ? remote_port : "", range ? range : "", remote_port ? remote_port : "", range ? range : "",
referer ? referer : "", referer ? referer : "",
www_auth ? www_auth : "", proxy_auth ? proxy_auth : "", www_auth ? www_auth : "", proxy_auth ? proxy_auth : "",
pragma_no_cache ? pragma_no_cache : ""); pragma_no_cache ? pragma_no_cache : "");
proz_debug("2 HTTP request = %s", request); proz_debug("2 HTTP request = %s", request);
@ -201,41 +205,41 @@ uerr_t proz_http_get_file(connection_t * connection)
/* What hapenned ? */ /* What hapenned ? */
if (err != HOK) if (err != HOK)
{ {
proz_debug("2 http_fetch_headers err != HOK %d", err); proz_debug("2 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)))
err = HAUTHFAIL; err = HAUTHFAIL;
/* /*
* a error occured druing the process * a error occured druing the process
*/ */
close_sock(&connection->data_sock); close_sock(&connection->data_sock);
connection_change_status(connection, REMOTEFATAL); connection_change_status(connection, REMOTEFATAL);
return err; return err;
} }
/*Check for the server lying about it being able to handle ranges */ /*Check for the server lying about it being able to handle ranges */
if (hs_after_get.contlen != -1) if (hs_after_get.contlen != -1)
{
if (connection->resume_support == TRUE)
{ {
if (hs_after_get.contlen != if (connection->resume_support == TRUE)
connection->main_file_size - connection->remote_startpos) {
{ if (hs_after_get.contlen !=
proz_debug("Error contlen does not match the requested range!"); connection->main_file_size - connection->remote_startpos)
close_sock(&connection->data_sock); {
connection_change_status(connection, REMOTEFATAL); proz_debug("Error contlen does not match the requested range!");
return CANTRESUME; close_sock(&connection->data_sock);
} connection_change_status(connection, REMOTEFATAL);
return CANTRESUME;
}
}
} }
}
/* which routine to call */ /* which routine to call */
if (connection->main_file_size == -1) if (connection->main_file_size == -1)
err = err =
connection_retr_fsize_not_known(connection, buffer, connection_retr_fsize_not_known(connection, buffer,
sizeof(buffer)); sizeof(buffer));
else else
err = connection_retr_fsize_known(connection, buffer, sizeof(buffer)); err = connection_retr_fsize_known(connection, buffer, sizeof(buffer));
@ -244,105 +248,103 @@ uerr_t proz_http_get_file(connection_t * connection)
if (err == FILEGETOK) if (err == FILEGETOK)
return HOK; return HOK;
else else
{ {
proz_debug("err != FILEGETOK %d", err); proz_debug("err != FILEGETOK %d", err);
return err; return err;
} }
} }
/* 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);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
do do
{
if (connection->attempts > 0)
{ {
if (connection->attempts > 0)
{
if (retrying_from_loop == TRUE)
{
connection_show_message(connection,
_("Retrying...Attempt %d in %d seconds"),
connection->attempts,
connection->retry_delay.tv_sec);
delay_ms(connection->retry_delay.tv_sec * 1000);
}
if (retrying_from_loop == TRUE) if (connection->resume_support == TRUE)
{ {
connection_show_message(connection, if (connection_load_resume_info(connection) == -1)
_("Retrying...Attempt %d in %d seconds"), {
connection->attempts, connection_show_message(connection,
connection->retry_delay.tv_sec); _
delay_ms(connection->retry_delay.tv_sec * 1000); ("Error while attemting to process download file "));
} }
}
else
{
/*If we cant resume then reset the connections bytesreceived to 0 */
connection->remote_bytes_received = 0;
}
}
if (connection->resume_support == TRUE) /*Push the handler which will cleanup any sockets that are left open */
{ pthread_cleanup_push(cleanup_socks, (void *)connection);
if (connection_load_resume_info(connection) == -1) connection->err = proz_http_get_file(connection);
{ /*pop the handler */
connection_show_message(connection, pthread_cleanup_pop(0);
_
("Error while attemting to process download file "));
}
} else
{
/*If we cant resume then reset the connections bytesreceived to 0 */
connection->remote_bytes_received = 0;
}
}
/*Push the handler which will cleanup any sockets that are left open */ connection->attempts++;
pthread_cleanup_push(cleanup_socks, (void *) connection);
connection->err = proz_http_get_file(connection);
/*pop the handler */
pthread_cleanup_pop(0);
connection->attempts++; /*Should the error be handled at this level ? */
if (!http_loop_handle_error(connection->err))
{
connection_show_message(connection, _("Will be handled in main "));
return connection->err; /*If not return and the main thread will handle it */
}
/*Should the error be handled at this level ? */ switch (connection->err)
if (!http_loop_handle_error(connection->err)) {
{ case HOK:
connection_show_message(connection, _("Will be handled in main ")); connection_show_message(connection, _("Successfully got download"));
return connection->err; /*If not return and the main thread will handle it */ return connection->err;
} break;
switch (connection->err) /*TODO : What should we do if the file is not found, well pass it up to the main routine */
{
case HOK:
connection_show_message(connection, _("Successfully got download"));
return connection->err;
break;
/*TODO : What should we do if the file is not found, well pass it up to the main routine */ default:
connection_show_message(connection, proz_strerror(connection->err));
break;
}
default: retrying_from_loop = TRUE;
connection_show_message(connection, proz_strerror(connection->err)); } while ((connection->attempts < connection->max_attempts)
break; || connection->max_attempts == 0);
}
retrying_from_loop = TRUE;
}
while ((connection->attempts < connection->max_attempts)
|| connection->max_attempts == 0);
connection_show_message(connection, connection_show_message(connection,
_ _
("I have tried %d attempt(s) and have failed, aborting"), ("I have tried %d attempt(s) and have failed, aborting"),
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);
@ -355,17 +357,16 @@ boolean http_loop_handle_error(uerr_t err)
/* /*
I am writing a seperate function to handle FTP proxying through HTTP, I I am writing a seperate function to handle FTP proxying through HTTP, I
MHO whoever thought of using HTTP to proxy FTP is a shithead, MHO whoever thought of using HTTP to proxy FTP is a shithead,
its such a PITA ;) its such a PITA ;)
*/ */
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 =
NULL, *pragma_no_cache = NULL; NULL, *pragma_no_cache = NULL;
char *request, *remote_port; char *request, *remote_port;
netrc_entry *netrc_ent; netrc_entry *netrc_ent;
@ -381,100 +382,101 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
/* if there is nothing to download then return */ /* if there is nothing to download then return */
if (connection->status == COMPLETED) if (connection->status == COMPLETED)
{ {
pthread_mutex_lock(&connection->access_mutex); pthread_mutex_lock(&connection->access_mutex);
gettimeofday(&connection->time_begin, NULL); gettimeofday(&connection->time_begin, NULL);
pthread_mutex_unlock(&connection->access_mutex); pthread_mutex_unlock(&connection->access_mutex);
return FTPOK; return FTPOK;
} }
err = connect_to_server(&connection->data_sock, err = connect_to_server(&connection->data_sock,
connection->ftp_proxy->proxy_url.host, connection->ftp_proxy->proxy_url.host,
connection->ftp_proxy->proxy_url.port, connection->ftp_proxy->proxy_url.port,
&connection->xfer_timeout); &connection->xfer_timeout);
if (err != NOCONERROR) if (err != NOCONERROR)
{ {
connection_show_message(connection, _("Error connecting to %s"), connection_show_message(connection, _("Error connecting to %s"),
connection->ftp_proxy->proxy_url.host); connection->ftp_proxy->proxy_url.host);
return err; return err;
} }
user = connection->u.user; user = connection->u.user;
passwd = connection->u.passwd; passwd = connection->u.passwd;
/* Use .netrc if asked to do so. */ /* Use .netrc if asked to do so. */
if (connection->use_netrc == TRUE) if (connection->use_netrc == TRUE)
{
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
if (netrc_ent != NULL)
{ {
user = netrc_ent->account; netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
passwd = netrc_ent->password;
if (netrc_ent != NULL)
{
user = netrc_ent->account;
passwd = netrc_ent->password;
}
} }
}
user = user ? user : ""; user = user ? user : "";
passwd = passwd ? passwd : ""; passwd = passwd ? passwd : "";
if (strlen(user) || strlen(passwd)) if (strlen(user) || strlen(passwd))
{ {
/* Construct the necessary header. */ /* Construct the necessary header. */
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)
|| strlen(connection->ftp_proxy->passwd)) || strlen(connection->ftp_proxy->passwd))
proxy_auth = proxy_auth =
get_basic_auth_str(connection->ftp_proxy->username, get_basic_auth_str(connection->ftp_proxy->username,
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);
} }
/*Use no-cache directive for proxy servers? */ /*Use no-cache directive for proxy servers? */
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
+ (range ? strlen(range) : 0) + (range ? strlen(range) : 0)
+ (www_auth ? strlen(www_auth) : 0) + (www_auth ? strlen(www_auth) : 0)
+ (proxy_auth ? strlen(proxy_auth) : 0) + (proxy_auth ? strlen(proxy_auth) : 0)
+ 64 + 64
+ +
(pragma_no_cache ? strlen(pragma_no_cache) : (pragma_no_cache ? strlen(pragma_no_cache) :
0)); 0));
/* TODO Add referrer tag. */ /* TODO Add referrer tag. */
sprintf(request, sprintf(request,
"GET %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s%s\r\nAccept: */*\r\n%s%s%s%s\r\n", "GET %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s%s\r\nAccept: */*\r\n%s%s%s%s\r\n",
connection->u.url, connection->user_agent, connection->u.host, connection->u.url, connection->user_agent, connection->u.host,
remote_port ? remote_port : "", range ? range : "", remote_port ? remote_port : "", range ? range : "",
www_auth ? www_auth : "", proxy_auth ? proxy_auth : "", www_auth ? www_auth : "", proxy_auth ? proxy_auth : "",
pragma_no_cache ? pragma_no_cache : ""); pragma_no_cache ? pragma_no_cache : "");
proz_debug("HTTP request = %s", request); proz_debug("HTTP request = %s", request);
@ -484,39 +486,41 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
if (err == HAUTHREQ) if (err == HAUTHREQ)
{ {
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); {
return FTPNSFOD; connection_change_status(connection, REMOTEFATAL);
} else if (err != HOK) return FTPNSFOD;
{ }
connection_change_status(connection, REMOTEFATAL); else if (err != HOK)
return FTPERR; {
} connection_change_status(connection, REMOTEFATAL);
return FTPERR;
}
/*Check for the server lying about it being able to handle ranges */ /*Check for the server lying about it being able to handle ranges */
if (hs_after_get.contlen != -1) if (hs_after_get.contlen != -1)
{
if (connection->resume_support == TRUE)
{ {
if (hs_after_get.contlen != if (connection->resume_support == TRUE)
connection->main_file_size - connection->remote_startpos) {
{ if (hs_after_get.contlen !=
proz_debug("Error contlen does not match the requested range!"); connection->main_file_size - connection->remote_startpos)
connection_change_status(connection, REMOTEFATAL); {
return CANTRESUME; proz_debug("Error contlen does not match the requested range!");
} connection_change_status(connection, REMOTEFATAL);
return CANTRESUME;
}
}
} }
}
/* which routine to call */ /* which routine to call */
if (connection->main_file_size == -1) if (connection->main_file_size == -1)
err = err =
connection_retr_fsize_not_known(connection, buffer, connection_retr_fsize_not_known(connection, buffer,
sizeof(buffer)); sizeof(buffer));
else else
err = connection_retr_fsize_known(connection, buffer, sizeof(buffer)); err = connection_retr_fsize_known(connection, buffer, sizeof(buffer));
@ -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

@ -1,23 +1,23 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* $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,10 +30,10 @@
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
#endif /* FTP_RETR_H */ #endif /* FTP_RETR_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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,27 +34,27 @@
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
#endif /* HTTP_H */ #endif /* HTTP_H */

View File

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
#include "common.h" #include "common.h"
@ -26,7 +26,7 @@
/*If download is not NULL will store info about the downloads connection allocations to it too.*/ /*If download is not NULL will store info about the downloads connection allocations to it too.*/
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)
{ {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
FILE *fp = NULL; FILE *fp = NULL;
@ -38,16 +38,15 @@ int log_create_logfile(int num_connections, int file_size, char *url,
* Compute the name of the logfile * Compute the name of the logfile
*/ */
snprintf(buffer, PATH_MAX, "%s/%s%s.log", download->log_dir, snprintf(buffer, PATH_MAX, "%s/%s%s.log", download->log_dir,
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
*/ */
download_show_message(download, download_show_message(download,
_("Error opening file %s for writing: %s"), _("Error opening file %s for writing: %s"),
buffer, strerror(errno)); buffer, strerror(errno));
return -1; return -1;
} }
@ -63,7 +62,7 @@ int log_create_logfile(int num_connections, int file_size, char *url,
if (fwrite(&lf, 1, sizeof(lf), fp) != sizeof(lf)) if (fwrite(&lf, 1, sizeof(lf), fp) != sizeof(lf))
{ {
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));
fclose(fp); fclose(fp);
return -1; return -1;
} }
@ -73,7 +72,7 @@ int log_create_logfile(int num_connections, int file_size, char *url,
if (fwrite(url, 1, strlen(url), fp) != strlen(url)) if (fwrite(url, 1, strlen(url), fp) != strlen(url))
{ {
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));
fclose(fp); fclose(fp);
return -1; return -1;
} }
@ -83,64 +82,58 @@ int log_create_logfile(int num_connections, int file_size, char *url,
if (download != NULL) if (download != NULL)
{ {
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
(&download->pconnections[i]->local_startpos, 1,
if (fwrite sizeof(download->pconnections[i]->local_startpos),
(&download->pconnections[i]->local_startpos, 1, fp) != sizeof(download->pconnections[i]->local_startpos))
sizeof(download->pconnections[i]->local_startpos),
fp) != sizeof(download->pconnections[i]->local_startpos))
{
pthread_mutex_unlock(&download->pconnections[i]->access_mutex);
download_show_message(download, _("Error writing to file %s: %s"),
buffer, strerror(errno));
fclose(fp);
return -1;
}
if (fwrite
(&download->pconnections[i]->orig_remote_startpos, 1,
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)); fclose(fp);
fclose(fp); return -1;
return -1;
} }
if (fwrite if (fwrite
(&download->pconnections[i]->remote_endpos, 1, (&download->pconnections[i]->orig_remote_startpos, 1,
sizeof(download->pconnections[i]->remote_endpos), sizeof(download->pconnections[i]->orig_remote_startpos),
fp) != sizeof(download->pconnections[i]->remote_endpos)) 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));
fclose(fp); fclose(fp);
return -1; return -1;
} }
if (fwrite if (fwrite
(&download->pconnections[i]->remote_bytes_received, 1, (&download->pconnections[i]->remote_endpos, 1,
sizeof(download->pconnections[i]->remote_bytes_received), sizeof(download->pconnections[i]->remote_endpos),
fp) != sizeof(download->pconnections[i]->remote_bytes_received)) fp) != sizeof(download->pconnections[i]->remote_endpos))
{ {
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)); fclose(fp);
fclose(fp); return -1;
return -1; }
}
pthread_mutex_unlock(&download->pconnections[i]->access_mutex);
}
if (fwrite
(&download->pconnections[i]->remote_bytes_received, 1,
sizeof(download->pconnections[i]->remote_bytes_received),
fp) != sizeof(download->pconnections[i]->remote_bytes_received))
{
pthread_mutex_unlock(&download->pconnections[i]->access_mutex);
download_show_message(download, _("Error writing to file %s: %s"),
buffer, strerror(errno));
fclose(fp);
return -1;
}
pthread_mutex_unlock(&download->pconnections[i]->access_mutex);
}
} }
fclose(fp); fclose(fp);
@ -158,16 +151,17 @@ int proz_log_logfile_exists(download_t * download)
* Compute the name of the logfile * Compute the name of the logfile
*/ */
snprintf(buffer, PATH_MAX, "%s/%s%s.log", download->log_dir, snprintf(buffer, PATH_MAX, "%s/%s%s.log", download->log_dir,
download->u.file, DEFAULT_FILE_EXT); download->u.file, DEFAULT_FILE_EXT);
ret = stat(buffer, &st_buf); ret = stat(buffer, &st_buf);
if (ret == -1) if (ret == -1)
{ {
if (errno == ENOENT) if (errno == ENOENT)
return 0; return 0;
else else
return -1; return -1;
} else }
else
return 1; return 1;
} }
@ -178,20 +172,21 @@ int proz_log_delete_logfile(download_t * download)
int ret; int ret;
snprintf(buffer, PATH_MAX, "%s/%s%s.log", download->log_dir, snprintf(buffer, PATH_MAX, "%s/%s%s.log", download->log_dir,
download->u.file, DEFAULT_FILE_EXT); download->u.file, DEFAULT_FILE_EXT);
ret = unlink(buffer); ret = unlink(buffer);
if (ret == -1) if (ret == -1)
{ {
if (errno == ENOENT) if (errno == ENOENT)
{ {
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)); {
return -1; download_show_message(download, "Error: Unable to delete the logfile: %s", strerror(errno));
} return -1;
}
} }
return 1; return 1;
@ -200,7 +195,7 @@ int proz_log_delete_logfile(download_t * download)
/* Read the logfile into the logfile structure */ /* Read the logfile into the logfile structure */
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)
{ {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
FILE *fp = NULL; FILE *fp = NULL;
@ -210,7 +205,7 @@ int proz_log_read_logfile(logfile * lf, download_t * download,
* Compute the name of the logfile * Compute the name of the logfile
*/ */
snprintf(buffer, PATH_MAX, "%s/%s%s.log", download->log_dir, snprintf(buffer, PATH_MAX, "%s/%s%s.log", download->log_dir,
download->u.file, DEFAULT_FILE_EXT); download->u.file, DEFAULT_FILE_EXT);
if (!(fp = fopen(buffer, "rb"))) if (!(fp = fopen(buffer, "rb")))
{ {
@ -218,8 +213,8 @@ int proz_log_read_logfile(logfile * lf, download_t * download,
* fixme add the error displaing to the main function * fixme add the error displaing to the main function
*/ */
download_show_message(download, download_show_message(download,
_("Error opening file %s for reading: %s"), _("Error opening file %s for reading: %s"),
buffer, strerror(errno)); buffer, strerror(errno));
return -1; return -1;
} }
@ -244,74 +239,69 @@ int proz_log_read_logfile(logfile * lf, download_t * download,
if (load_con_info == TRUE) if (load_con_info == TRUE)
{ {
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);
if (fread
(&download->pconnections[i]->local_startpos, 1,
proz_debug("value before= %d", download->pconnections[i]->local_startpos); sizeof(download->pconnections[i]->local_startpos),
fp) != sizeof(download->pconnections[i]->local_startpos))
if (fread
(&download->pconnections[i]->local_startpos, 1,
sizeof(download->pconnections[i]->local_startpos),
fp) != sizeof(download->pconnections[i]->local_startpos))
{ {
download_show_message(download, download_show_message(download,
_("Error reading from file %s: %s"), buffer, _("Error reading from file %s: %s"), buffer,
strerror(errno)); strerror(errno));
fclose(fp); fclose(fp);
return -1; return -1;
} }
proz_debug("value after= %d", download->pconnections[i]->local_startpos); proz_debug("value after= %d", download->pconnections[i]->local_startpos);
proz_debug("orig_remote_startpos before= %d", download->pconnections[i]->orig_remote_startpos); proz_debug("orig_remote_startpos before= %d", download->pconnections[i]->orig_remote_startpos);
if (fread if (fread
(&download->pconnections[i]->orig_remote_startpos, 1, (&download->pconnections[i]->orig_remote_startpos, 1,
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))
{ {
download_show_message(download, download_show_message(download,
_("Error reading from file %s: %s"), buffer, _("Error reading from file %s: %s"), buffer,
strerror(errno)); strerror(errno));
fclose(fp); fclose(fp);
return -1; return -1;
} }
proz_debug("orig_remote_startpos after= %d", download->pconnections[i]->orig_remote_startpos); proz_debug("orig_remote_startpos after= %d", download->pconnections[i]->orig_remote_startpos);
proz_debug("remote_edndpos before= %d", download->pconnections[i]->remote_endpos); proz_debug("remote_edndpos before= %d", download->pconnections[i]->remote_endpos);
if (fread if (fread
(&download->pconnections[i]->remote_endpos, 1, (&download->pconnections[i]->remote_endpos, 1,
sizeof(download->pconnections[i]->remote_endpos), sizeof(download->pconnections[i]->remote_endpos),
fp) != sizeof(download->pconnections[i]->remote_endpos)) fp) != sizeof(download->pconnections[i]->remote_endpos))
{ {
download_show_message(download, download_show_message(download,
_("Error reading from file %s: %s"), buffer, _("Error reading from file %s: %s"), buffer,
strerror(errno)); strerror(errno));
fclose(fp); fclose(fp);
return -1; return -1;
} }
proz_debug("remote_endpos after= %d", download->pconnections[i]->remote_endpos); proz_debug("remote_endpos after= %d", download->pconnections[i]->remote_endpos);
proz_debug("remote_bytes_received before= %d", download->pconnections[i]->remote_bytes_received); proz_debug("remote_bytes_received before= %d", download->pconnections[i]->remote_bytes_received);
if (fread if (fread
(&download->pconnections[i]->remote_bytes_received, 1, (&download->pconnections[i]->remote_bytes_received, 1,
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))
{ {
download_show_message(download, download_show_message(download,
_("Error reading from file %s: %s"), buffer, _("Error reading from file %s: %s"), buffer,
strerror(errno)); strerror(errno));
fclose(fp); fclose(fp);
return -1; return -1;
} }
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

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
#ifndef LOGFILE_H #ifndef LOGFILE_H
@ -30,8 +30,8 @@ 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

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* The main file. */ /* The main file. */
@ -31,18 +31,18 @@
/* static struct option long_opts[] = { /* static struct option long_opts[] = {
// { name has_arg *flag val } // { name has_arg *flag val }
{"no-netrc", no_argument, NULL, 'n'}, {"no-netrc", no_argument, NULL, 'n'},
{"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;
/****************************************************************************** /******************************************************************************
Initialize the library. Initialize the library.
******************************************************************************/ ******************************************************************************/
int proz_init(int argc, char **argv) int proz_init(int argc, char **argv)
{ {
@ -78,7 +78,7 @@ int proz_init(int argc, char **argv)
/* Parse the options and set the relevant ones for the library. */ /* Parse the options and set the relevant ones for the library. */
/* while ((c = getopt_long(argc, argv, "", long_opts, NULL)) != EOF) /* while ((c = getopt_long(argc, argv, "", long_opts, NULL)) != EOF)
{ {
switch (c) switch (c)
{ {
case 129: case 129:
@ -87,24 +87,26 @@ int proz_init(int argc, char **argv)
default: default:
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();
if (libprozrtinfo.home_dir != NULL) if (libprozrtinfo.home_dir != NULL)
{ {
char *netrc_file = kmalloc(strlen(libprozrtinfo.home_dir) char *netrc_file = kmalloc(strlen(libprozrtinfo.home_dir)
+ strlen(".netrc") + 2); + strlen(".netrc") + 2);
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 { }
/* Make sure home dir is never NULL */ else
libprozrtinfo.home_dir = kstrdup("."); {
} /* Make sure home dir is never NULL */
libprozrtinfo.home_dir = kstrdup(".");
}
libprozrtinfo.dl_dir = kstrdup("."); libprozrtinfo.dl_dir = kstrdup(".");
libprozrtinfo.output_dir = kstrdup("."); libprozrtinfo.output_dir = kstrdup(".");
@ -114,7 +116,7 @@ int proz_init(int argc, char **argv)
} }
/****************************************************************************** /******************************************************************************
... ...
******************************************************************************/ ******************************************************************************/
void proz_shutdown(void) void proz_shutdown(void)
{ {
@ -126,7 +128,7 @@ void proz_shutdown(void)
} }
/****************************************************************************** /******************************************************************************
Abort with an error message. Abort with an error message.
******************************************************************************/ ******************************************************************************/
void proz_die(const char *format, ...) void proz_die(const char *format, ...)
{ {
@ -144,7 +146,7 @@ void proz_die(const char *format, ...)
} }
/****************************************************************************** /******************************************************************************
... ...
******************************************************************************/ ******************************************************************************/
void proz_set_http_proxy(proxy_info * proxy) void proz_set_http_proxy(proxy_info * proxy)
{ {
@ -155,7 +157,7 @@ void proz_set_http_proxy(proxy_info * proxy)
} }
/****************************************************************************** /******************************************************************************
... ...
******************************************************************************/ ******************************************************************************/
void proz_set_ftp_proxy(proxy_info * proxy) void proz_set_ftp_proxy(proxy_info * proxy)
{ {
@ -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

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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"
@ -32,8 +32,8 @@ void cleanup_httpsocks(connection_t * connection);
void cleanup_ftpsocks(connection_t * connection); void cleanup_ftpsocks(connection_t * connection);
/****************************************************************************** /******************************************************************************
Allocates size bytes of memory. If size is 0 it returns NULL. If there is Allocates size bytes of memory. If size is 0 it returns NULL. If there is
not enough memory the program quits with an error message. not enough memory the program quits with an error message.
******************************************************************************/ ******************************************************************************/
void *kmalloc(size_t size) void *kmalloc(size_t size)
{ {
@ -51,7 +51,7 @@ void *kmalloc(size_t size)
} }
/****************************************************************************** /******************************************************************************
A wrapper for realloc() which aborts if not enough memory is present. A wrapper for realloc() which aborts if not enough memory is present.
******************************************************************************/ ******************************************************************************/
void *krealloc(void *ptr, size_t new_size) void *krealloc(void *ptr, size_t new_size)
{ {
@ -66,7 +66,7 @@ void *krealloc(void *ptr, size_t new_size)
} }
/****************************************************************************** /******************************************************************************
A wrapper for free() which handles NULL pointers. A wrapper for free() which handles NULL pointers.
******************************************************************************/ ******************************************************************************/
void kfree(void *ptr) void kfree(void *ptr)
{ {
@ -75,7 +75,7 @@ void kfree(void *ptr)
} }
/****************************************************************************** /******************************************************************************
A wrapper for strdup() which aborts if not enough memory is present. A wrapper for strdup() which aborts if not enough memory is present.
******************************************************************************/ ******************************************************************************/
char *kstrdup(const char *str) char *kstrdup(const char *str)
{ {
@ -88,7 +88,7 @@ char *kstrdup(const char *str)
} }
/****************************************************************************** /******************************************************************************
Checks whether the specified string is a number or digit. Checks whether the specified string is a number or digit.
******************************************************************************/ ******************************************************************************/
boolean is_number(const char *str) boolean is_number(const char *str)
{ {
@ -98,16 +98,16 @@ boolean is_number(const char *str)
return FALSE; return FALSE;
while (str[i] != '\0') while (str[i] != '\0')
{ {
if (!isdigit(str[i])) if (!isdigit(str[i]))
return FALSE; return FALSE;
i++; i++;
} }
return TRUE; return TRUE;
} }
/****************************************************************************** /******************************************************************************
How many digits are in a long integer? How many digits are in a long integer?
******************************************************************************/ ******************************************************************************/
int numdigit(long a) int numdigit(long a)
{ {
@ -120,8 +120,8 @@ int numdigit(long a)
} }
/****************************************************************************** /******************************************************************************
Copy the string formed by two pointers (one on the beginning, other on the Copy the string formed by two pointers (one on the beginning, other on the
char after the last char) to a new, malloc()-ed location. 0-terminate it. char after the last char) to a new, malloc()-ed location. 0-terminate it.
******************************************************************************/ ******************************************************************************/
char *strdupdelim(const char *beg, const char *end) char *strdupdelim(const char *beg, const char *end)
{ {
@ -134,8 +134,8 @@ char *strdupdelim(const char *beg, const char *end)
} }
/****************************************************************************** /******************************************************************************
Print a long integer to the string buffer. The digits are first written in Print a long integer to the string buffer. The digits are first written in
reverse order (the least significant digit first), and are then reversed. reverse order (the least significant digit first), and are then reversed.
******************************************************************************/ ******************************************************************************/
void prnum(char *where, long num) void prnum(char *where, long num)
{ {
@ -144,63 +144,64 @@ void prnum(char *where, long num)
char c; char c;
if (num < 0) if (num < 0)
{ {
*where++ = '-'; *where++ = '-';
num = -num; num = -num;
} }
p = where; p = where;
/* Print the digits to the string. */ /* Print the digits to the string. */
do do
{ {
*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;
for (i = l / 2; i >= 0; i--) for (i = l / 2; i >= 0; i--)
{ {
c = where[i]; c = where[i];
where[i] = where[l - i]; where[i] = where[l - i];
where[l - i] = c; where[l - i] = c;
} }
where[l + 1] = '\0'; where[l + 1] = '\0';
} }
/****************************************************************************** /******************************************************************************
Extracts a numurical argument from an option, when it has been specified for Extracts a numurical argument from an option, when it has been specified for
example as -l=3 or -l3. Returns 1 on success or 0 on error (non numerical example as -l=3 or -l3. Returns 1 on success or 0 on error (non numerical
argument etc). argument etc).
******************************************************************************/ ******************************************************************************/
int setargval(char *optstr, int *num) int setargval(char *optstr, int *num)
{ {
if (*optstr == '=') if (*optstr == '=')
{
if (is_number(optstr + 1))
{ {
*num = atoi(optstr + 1); if (is_number(optstr + 1))
return 1; {
} else *num = atoi(optstr + 1);
return 0; return 1;
} else }
{ else
if (is_number(optstr)) return 0;
}
else
{ {
*num = atoi(optstr); if (is_number(optstr))
return 1; {
} else *num = atoi(optstr);
return 0; return 1;
} }
else
return 0;
}
} }
/****************************************************************************** /******************************************************************************
Encode the given string to base64 format and place it into store. store will Encode the given string to base64 format and place it into store. store will
be 0-terminated, and must point to a writable buffer of at least be 0-terminated, and must point to a writable buffer of at least
1+BASE64_LENGTH(length) bytes. Note: Routine stolen from wget (grendel). 1+BASE64_LENGTH(length) bytes. Note: Routine stolen from wget (grendel).
******************************************************************************/ ******************************************************************************/
void base64_encode(const char *s, char *store, int length) void base64_encode(const char *s, char *store, int length)
{ {
@ -217,17 +218,17 @@ 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)
{ {
*p++ = tbl[s[0] >> 2]; *p++ = tbl[s[0] >> 2];
*p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)]; *p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];
*p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)]; *p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];
*p++ = tbl[s[2] & 0x3f]; *p++ = tbl[s[2] & 0x3f];
s += 3; s += 3;
} }
/* Pad the result if necessary... */ /* Pad the result if necessary... */
if (i == length + 1) if (i == length + 1)
@ -239,46 +240,45 @@ void base64_encode(const char *s, char *store, int length)
} }
/****************************************************************************** /******************************************************************************
Return the user's home directory (strdup-ed), or NULL if none is found. Return the user's home directory (strdup-ed), or NULL if none is found.
******************************************************************************/ ******************************************************************************/
char *home_dir(void) char *home_dir(void)
{ {
char *home = getenv("HOME"); char *home = getenv("HOME");
if (home == NULL) if (home == NULL)
{ {
/* If $HOME is not defined, try getting it from the passwd file. */ /* If $HOME is not defined, try getting it from the passwd file. */
struct passwd *pwd = getpwuid(getuid()); struct passwd *pwd = getpwuid(getuid());
if (!pwd || !pwd->pw_dir) if (!pwd || !pwd->pw_dir)
return NULL; return NULL;
home = pwd->pw_dir; home = pwd->pw_dir;
} }
return home ? kstrdup(home) : NULL; return home ? kstrdup(home) : NULL;
} }
/****************************************************************************** /******************************************************************************
Subtract the `struct timeval' values X and Y, storing the result in RESULT. Subtract the `struct timeval' values X and Y, storing the result in RESULT.
Return 1 if the difference is negative, otherwise 0. Return 1 if the difference is negative, otherwise 0.
******************************************************************************/ ******************************************************************************/
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)
{ {
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec; y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec; y->tv_sec += nsec;
} }
if (x->tv_usec - y->tv_usec > 1000000) if (x->tv_usec - y->tv_usec > 1000000)
{ {
int nsec = (x->tv_usec - y->tv_usec) / 1000000; int nsec = (x->tv_usec - y->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec; y->tv_usec += 1000000 * nsec;
y->tv_sec -= nsec; y->tv_sec -= nsec;
} }
/* Compute the time remaining to wait. `tv_usec' is certainly positive. */ /* Compute the time remaining to wait. `tv_usec' is certainly positive. */
result->tv_sec = x->tv_sec - y->tv_sec; result->tv_sec = x->tv_sec - y->tv_sec;
@ -289,7 +289,7 @@ int proz_timeval_subtract(struct timeval *result, struct timeval *x,
} }
/****************************************************************************** /******************************************************************************
Wait for 'ms' milliseconds. Wait for 'ms' milliseconds.
******************************************************************************/ ******************************************************************************/
void delay_ms(int ms) void delay_ms(int ms)
{ {
@ -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,158 +318,198 @@ int close_sock(int *sock)
char *proz_strerror(uerr_t error) char *proz_strerror(uerr_t error)
{ {
switch (error) switch (error)
{ {
case HOSTERR:
return _("Unable to lookup hostname");
case HOSTERR: case CONSOCKERR:
return _("Unable to lookup hostname"); return _("Unable to create socket");
case CONSOCKERR:
return _("Unable to create socket");
case CONERROR:
return _("Error occured while connecting");
case CONREFUSED:
return _("The connection attempt was refused");
case ACCEPTERR:
return _("Error while accepting the connection");
case BINDERR:
return _("Error while Binding socket");
case LISTENERR:
return _("Error while listening");
case SERVERCLOSECONERR:
return _("The connection was reset/closed by the peer");
case URLUNKNOWN:
return _("The URL Protocol was unknown");
case URLBADPORT:
return _("The port specified in the URL is not valid!");
case URLBADHOST:
return _("The Hostname specified in the URL is not valid!");
case URLBADPATTERN:
return _("The Pattern specified in the URL does not look valid!");
case HEOF:
return _("End of file reached in HTTP connection");
case HERR:
return _("Error occured in HTTP data transfer");
case HAUTHREQ:
return _("Authentification is required to access this resource");
case HAUTHFAIL:
return _("Failed to Authenticate with host!");
case HTTPNSFOD:
return _("The URL was not found on the host!");
case FTPLOGREFUSED:
return _("The host disallowed the login attempt");
case FTPPORTERR:
return _("The PORT request was rejected by the server");
case FTPNSFOD:
return _("The object file/dir was not found on the host!");
case FTPUNKNOWNTYPE:
return _("The TYPE specified in not known by the FTP server!");
case FTPUNKNOWNCMD:
return _("The command is not known by the FTP server!");
case FTPSIZEFAIL:
return _("The SIZE command failed");
case FTPERR:
return _("Error occured in FTP data transfer");
case FTPRESTFAIL:
return _("The REST command failed");
case FTPACCDENIED:
return _("The peer did not allow access");
case FTPPWDERR:
return _("The host rejected the password");
case FTPPWDFAIL:
return _("The host rejected the password");
case FTPINVPASV:
return _("The PASV (passive mode) was not supported the host");
case FTPNOPASV:
return _("The host does not support PASV (passive mode) transfers");
case FTPCONREFUSED:
return _("The connection attempt was refused");
case FTPCWDFAIL:
return _("Failed to (CWD)change to the directory");
case FTPSERVCLOSEDATLOGIN:
return
_
("The host said the requested service was unavailable and closed the control connection");
case CONPORTERR:
return _("getsockname failed!");
case GATEWAYTIMEOUT: case CONERROR:
return return _("Error occured while connecting");
_
("The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request");
case SERVICEUNAVAIL: case CONREFUSED:
return return _("The connection attempt was refused");
_
("The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.");
case BADGATEWAY: case ACCEPTERR:
return return _("Error while accepting the connection");
_
("The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request");
case INTERNALSERVERR: case BINDERR:
return return _("Error while Binding socket");
_
("The server encountered an unexpected condition which prevented it from fulfilling the request.");
case UNKNOWNREQ: case LISTENERR:
return return _("Error while listening");
_
("The server does not support the functionality required to fulfill the request.");
case FOPENERR: case SERVERCLOSECONERR:
return _("Error while opening file"); return _("The connection was reset/closed by the peer");
case FWRITEERR:
return _("Error while writing to file");
case DLABORTED: case URLUNKNOWN:
return _("The Download was aborted"); return _("The URL Protocol was unknown");
case DLLOCALFATAL:
return _("The Download encountered a local fatal error");
case CANTRESUME:
return _("Error: Resuming this connection is not possible");
case READERR:
return _("Error while reading data from socket");
case WRITEERR:
return _("Error while writing data to socket");
case PROXERR:
return _("Error while Proxying");
case FILEISDIR:
return _("The location is a directory");
default: case URLBADPORT:
return _("Unknown/Unsupported error code"); return _("The port specified in the URL is not valid!");
}
case URLBADHOST:
return _("The Hostname specified in the URL is not valid!");
case URLBADPATTERN:
return _("The Pattern specified in the URL does not look valid!");
case HEOF:
return _("End of file reached in HTTP connection");
case HERR:
return _("Error occured in HTTP data transfer");
case HAUTHREQ:
return _("Authentification is required to access this resource");
case HAUTHFAIL:
return _("Failed to Authenticate with host!");
case HTTPNSFOD:
return _("The URL was not found on the host!");
case FTPLOGREFUSED:
return _("The host disallowed the login attempt");
case FTPPORTERR:
return _("The PORT request was rejected by the server");
case FTPNSFOD:
return _("The object file/dir was not found on the host!");
case FTPUNKNOWNTYPE:
return _("The TYPE specified in not known by the FTP server!");
case FTPUNKNOWNCMD:
return _("The command is not known by the FTP server!");
case FTPSIZEFAIL:
return _("The SIZE command failed");
case FTPERR:
return _("Error occured in FTP data transfer");
case FTPRESTFAIL:
return _("The REST command failed");
case FTPACCDENIED:
return _("The peer did not allow access");
case FTPPWDERR:
return _("The host rejected the password");
case FTPPWDFAIL:
return _("The host rejected the password");
case FTPINVPASV:
return _("The PASV (passive mode) was not supported the host");
case FTPNOPASV:
return _("The host does not support PASV (passive mode) transfers");
case FTPCONREFUSED:
return _("The connection attempt was refused");
case FTPCWDFAIL:
return _("Failed to (CWD)change to the directory");
case FTPSERVCLOSEDATLOGIN:
return
_
("The host said the requested service was unavailable and closed the control connection");
case CONPORTERR:
return _("getsockname failed!");
case GATEWAYTIMEOUT:
return
_
("The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request");
case SERVICEUNAVAIL:
return
_
("The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.");
case BADGATEWAY:
return
_
("The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request");
case INTERNALSERVERR:
return
_
("The server encountered an unexpected condition which prevented it from fulfilling the request.");
case UNKNOWNREQ:
return
_
("The server does not support the functionality required to fulfill the request.");
case FOPENERR:
return _("Error while opening file");
case FWRITEERR:
return _("Error while writing to file");
case DLABORTED:
return _("The Download was aborted");
case DLLOCALFATAL:
return _("The Download encountered a local fatal error");
case CANTRESUME:
return _("Error: Resuming this connection is not possible");
case READERR:
return _("Error while reading data from socket");
case WRITEERR:
return _("Error while writing data to socket");
case PROXERR:
return _("Error while Proxying");
case FILEISDIR:
return _("The location is a directory");
default:
return _("Unknown/Unsupported error code");
}
} }
/* Cleanup handler which will be popped and which will be called when the thread is cancelled, it make sure that there will be no sockets left open if the thread is cancelled prematurely /* 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:
cleanup_httpsocks(connection);
break;
case URLFTP:
if (ftp_use_proxy(connection)
&& connection->ftp_proxy->type == HTTPPROXY)
{ {
/* We have to cleanup the http socks instead case URLHTTP:
if we are going through a http proxy */
cleanup_httpsocks(connection); cleanup_httpsocks(connection);
} else break;
cleanup_ftpsocks(connection);
break; case URLFTP:
default: if (ftp_use_proxy(connection)
proz_die(_("Error: unsupported protocol")); && connection->ftp_proxy->type == HTTPPROXY)
} {
/* We have to cleanup the http socks instead
if we are going through a http proxy */
cleanup_httpsocks(connection);
}
else
cleanup_ftpsocks(connection);
break;
default:
proz_die(_("Error: unsupported protocol"));
}
} }
@ -482,25 +522,26 @@ void cleanup_ftpsocks(connection_t * connection)
if (connection->data_sock > 0) if (connection->data_sock > 0)
{
flags = fcntl(connection->data_sock, F_GETFD, 0);
if (flags == -1)
{ {
proz_debug("data sock invalid\n"); flags = fcntl(connection->data_sock, F_GETFD, 0);
} else if (flags == -1)
close_sock(&connection->data_sock); {
} proz_debug("data sock invalid\n");
}
else
close_sock(&connection->data_sock);
}
if (connection->ctrl_sock > 0) if (connection->ctrl_sock > 0)
{
flags = fcntl(connection->ctrl_sock, F_GETFD, 0);
if (flags == -1)
{ {
proz_debug("control sock invalid\n"); flags = fcntl(connection->ctrl_sock, F_GETFD, 0);
} else if (flags == -1)
close_sock(&connection->ctrl_sock); {
} proz_debug("control sock invalid\n");
}
else
close_sock(&connection->ctrl_sock);
}
} }
@ -511,15 +552,15 @@ void cleanup_httpsocks(connection_t * connection)
proz_debug("in clean http sock\n"); proz_debug("in clean http sock\n");
if (connection->data_sock > 0) if (connection->data_sock > 0)
{
flags = fcntl(connection->data_sock, F_GETFD, 0);
if (flags == -1)
{ {
proz_debug("sock invalid\n"); flags = fcntl(connection->data_sock, F_GETFD, 0);
} else if (flags == -1)
close(connection->data_sock); {
} proz_debug("sock invalid\n");
}
else
close(connection->data_sock);
}
} }

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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
@ -46,4 +46,4 @@ char *home_dir(void);
void delay_ms(int ms); void delay_ms(int ms);
int close_sock(int *sock); int close_sock(int *sock);
void cleanup_socks(void *cdata); void cleanup_socks(void *cdata);
#endif /* MISC_H */ #endif /* 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"
@ -29,35 +29,37 @@
#define POPBUFSIZE BUFSIZ #define POPBUFSIZE BUFSIZ
/****************************************************************************** /******************************************************************************
Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is
set to a ready-to-use netrc_entry, in any event. set to a ready-to-use netrc_entry, in any event.
******************************************************************************/ ******************************************************************************/
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;
/* We need an account name in order to add the entry to the list. */ /* We need an account name in order to add the entry to the list. */
if (a && !a->account) if (a && !a->account)
{
/* Free any allocated space. */
if (a->host)
kfree(a->host);
if (a->password)
kfree(a->password);
} else
{
if (a)
{ {
/* Add the current machine into our list. */ /* Free any allocated space. */
a->next = l; if (a->host)
l = a; kfree(a->host);
if (a->password)
kfree(a->password);
} }
else
{
if (a)
{
/* Add the current machine into our list. */
a->next = l;
l = a;
}
/* Allocate a new netrc_entry structure. */ /* Allocate a new netrc_entry structure. */
a = kmalloc(sizeof(netrc_entry)); a = kmalloc(sizeof(netrc_entry));
} }
/* Zero the structure, so that it is ready to use. */ /* Zero the structure, so that it is ready to use. */
memset(a, 0, sizeof(*a)); memset(a, 0, sizeof(*a));
@ -69,8 +71,8 @@ static void maybe_add_to_list(netrc_entry ** newentry, netrc_entry ** list)
} }
/****************************************************************************** /******************************************************************************
Parse FILE as a .netrc file (as described in ftp(1)), and return a list of Parse FILE as a .netrc file (as described in ftp(1)), and return a list of
entries. NULL is returned if the file could not be parsed. entries. NULL is returned if the file could not be parsed.
******************************************************************************/ ******************************************************************************/
netrc_entry *parse_netrc(char *file) netrc_entry *parse_netrc(char *file)
{ {
@ -90,10 +92,10 @@ netrc_entry *parse_netrc(char *file)
fp = fopen(file, "r"); fp = fopen(file, "r");
if (!fp) if (!fp)
{ {
/* Just return NULL if we can't open the file. */ /* Just return NULL if we can't open the file. */
return NULL; return NULL;
} }
/* Initialize the file data. */ /* Initialize the file data. */
ln = 0; ln = 0;
@ -101,151 +103,153 @@ netrc_entry *parse_netrc(char *file)
/* While there are lines in the file... */ /* While there are lines in the file... */
while (fgets(buf, POPBUFSIZE, fp)) while (fgets(buf, POPBUFSIZE, fp))
{
ln++;
/* Strip trailing CRLF. */
for (p = buf + strlen(buf) - 1; (p >= buf) && isspace((unsigned) *p);
p--)
*p = '\0';
/* Parse the line. */
p = buf;
/* If the line is empty... */
if (!*p)
{ {
if (last_token == tok_macdef) ln++;
last_token = tok_nothing; /* End of macro. */
else /* Strip trailing CRLF. */
continue; /* Otherwise ignore it. */ for (p = buf + strlen(buf) - 1; (p >= buf) && isspace((unsigned)*p);
p--)
*p = '\0';
/* Parse the line. */
p = buf;
/* If the line is empty... */
if (!*p)
{
if (last_token == tok_macdef)
last_token = tok_nothing; /* End of macro. */
else
continue; /* Otherwise ignore it. */
}
/* If we are defining macros, then skip parsing the line. */
while (*p && last_token != tok_macdef)
{
char quote_char = 0;
char *pp;
/* Skip any whitespace. */
while (*p && isspace((unsigned)*p))
p++;
/* Discard end-of-line comments. */
if (*p == '#')
break;
tok = pp = p;
/* Find the end of the token. */
while (*p && (quote_char || !isspace((unsigned)*p)))
{
if (quote_char)
{
if (quote_char == *p)
{
quote_char = 0;
p++;
}
else
{
*pp = *p;
p++;
pp++;
}
}
else
{
if (*p == '"' || *p == '\'')
quote_char = *p;
else
{
*pp = *p;
pp++;
}
p++;
}
}
/* Null-terminate the token, if it isn't already. */
if (*p)
*p++ = '\0';
*pp = 0;
switch (last_token)
{
case tok_login:
if (current)
current->account = kstrdup(tok);
else
premature_token = "login";
break;
case tok_machine:
/* Start a new machine entry. */
maybe_add_to_list(&current, &retval);
current->host = kstrdup(tok);
break;
case tok_password:
if (current)
current->password = kstrdup(tok);
else
premature_token = "password";
break;
/* We handle most of tok_macdef above. */
case tok_macdef:
if (!current)
premature_token = "macdef";
break;
/* We don't handle the account keyword at all. */
case tok_account:
if (!current)
premature_token = "account";
break;
/* We handle tok_nothing below this switch. */
case tok_nothing:
break;
}
if (premature_token)
{
fprintf(stderr,
_("%s:%d: warning: found \"%s\" before any host names\n"),
file, ln, premature_token);
premature_token = NULL;
}
if (last_token != tok_nothing)
/* We got a value, so reset the token state. */
last_token = tok_nothing;
else
{
/* Fetch the next token. */
if (!strcmp(tok, "default"))
maybe_add_to_list(&current, &retval);
else if (!strcmp(tok, "login"))
last_token = tok_login;
else if (!strcmp(tok, "user"))
last_token = tok_login;
else if (!strcmp(tok, "macdef"))
last_token = tok_macdef;
else if (!strcmp(tok, "machine"))
last_token = tok_machine;
else if (!strcmp(tok, "password"))
last_token = tok_password;
else if (!strcmp(tok, "passwd"))
last_token = tok_password;
else if (!strcmp(tok, "account"))
last_token = tok_account;
else
fprintf(stderr, _("%s:%d: warning: unknown token \"%s\"\n"),
file, ln, tok);
}
}
} }
/* If we are defining macros, then skip parsing the line. */
while (*p && last_token != tok_macdef)
{
char quote_char = 0;
char *pp;
/* Skip any whitespace. */
while (*p && isspace((unsigned) *p))
p++;
/* Discard end-of-line comments. */
if (*p == '#')
break;
tok = pp = p;
/* Find the end of the token. */
while (*p && (quote_char || !isspace((unsigned) *p)))
{
if (quote_char)
{
if (quote_char == *p)
{
quote_char = 0;
p++;
} else
{
*pp = *p;
p++;
pp++;
}
} else
{
if (*p == '"' || *p == '\'')
quote_char = *p;
else
{
*pp = *p;
pp++;
}
p++;
}
}
/* Null-terminate the token, if it isn't already. */
if (*p)
*p++ = '\0';
*pp = 0;
switch (last_token)
{
case tok_login:
if (current)
current->account = kstrdup(tok);
else
premature_token = "login";
break;
case tok_machine:
/* Start a new machine entry. */
maybe_add_to_list(&current, &retval);
current->host = kstrdup(tok);
break;
case tok_password:
if (current)
current->password = kstrdup(tok);
else
premature_token = "password";
break;
/* We handle most of tok_macdef above. */
case tok_macdef:
if (!current)
premature_token = "macdef";
break;
/* We don't handle the account keyword at all. */
case tok_account:
if (!current)
premature_token = "account";
break;
/* We handle tok_nothing below this switch. */
case tok_nothing:
break;
}
if (premature_token)
{
fprintf(stderr,
_("%s:%d: warning: found \"%s\" before any host names\n"),
file, ln, premature_token);
premature_token = NULL;
}
if (last_token != tok_nothing)
/* We got a value, so reset the token state. */
last_token = tok_nothing;
else
{
/* Fetch the next token. */
if (!strcmp(tok, "default"))
maybe_add_to_list(&current, &retval);
else if (!strcmp(tok, "login"))
last_token = tok_login;
else if (!strcmp(tok, "user"))
last_token = tok_login;
else if (!strcmp(tok, "macdef"))
last_token = tok_macdef;
else if (!strcmp(tok, "machine"))
last_token = tok_machine;
else if (!strcmp(tok, "password"))
last_token = tok_password;
else if (!strcmp(tok, "passwd"))
last_token = tok_password;
else if (!strcmp(tok, "account"))
last_token = tok_account;
else
fprintf(stderr, _("%s:%d: warning: unknown token \"%s\"\n"),
file, ln, tok);
}
}
}
fclose(fp); fclose(fp);
/* Finalize the last machine entry we found. */ /* Finalize the last machine entry we found. */
@ -256,37 +260,37 @@ netrc_entry *parse_netrc(char *file)
current = retval; current = retval;
retval = NULL; retval = NULL;
while (current) while (current)
{ {
netrc_entry *saved_reference; netrc_entry *saved_reference;
/* Change the direction of the pointers. */ /* Change the direction of the pointers. */
saved_reference = current->next; saved_reference = current->next;
current->next = retval; current->next = retval;
/* Advance to the next node. */ /* Advance to the next node. */
retval = current; retval = current;
current = saved_reference; current = saved_reference;
} }
return retval; return retval;
} }
/****************************************************************************** /******************************************************************************
Return the netrc entry from LIST corresponding to HOST. NULL is returned if Return the netrc entry from LIST corresponding to HOST. NULL is returned if
no such entry exists. no such entry exists.
******************************************************************************/ ******************************************************************************/
netrc_entry *search_netrc(netrc_entry * list, const char *host) netrc_entry *search_netrc(netrc_entry * list, const char *host)
{ {
/* Look for the HOST in LIST. */ /* Look for the HOST in LIST. */
while (list) while (list)
{ {
if (!list->host) if (!list->host)
break; /* We hit the default entry. */ break; /* We hit the default entry. */
else if (!strcmp(list->host, host)) else if (!strcmp(list->host, host))
break; /* We found a matching entry. */ break; /* We found a matching entry. */
list = list->next; list = list->next;
} }
/* Return the matching entry, or NULL. */ /* Return the matching entry, or NULL. */
return list; return list;

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
@ -33,8 +33,8 @@
# define __BEGIN_DECLS extern "C" { # define __BEGIN_DECLS extern "C" {
# define __END_DECLS } # define __END_DECLS }
#else #else
# define __BEGIN_DECLS /* Empty. */ # define __BEGIN_DECLS /* Empty. */
# define __END_DECLS /* Empty. */ # define __END_DECLS /* Empty. */
#endif #endif
#undef __P #undef __P
@ -63,4 +63,4 @@ __BEGIN_DECLS netrc_entry *parse_netrc __P((char *file));
netrc_entry *search_netrc __P((netrc_entry * list, const char *host)); netrc_entry *search_netrc __P((netrc_entry * list, const char *host));
__END_DECLS __END_DECLS
#endif /* NETRC_H */ #endif /* NETRC_H */

View File

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
@ -40,9 +40,9 @@ 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;
assert(ping_data->host); assert(ping_data->host);
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
@ -51,16 +51,17 @@ uerr_t tcp_ping(ping_t * ping_data)
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
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;
} }
if ((ping_data->sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1) if ((ping_data->sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1)
{ {
free(res); free(res);
return ping_data->err = CONSOCKERR; return ping_data->err = CONSOCKERR;
} }
/* Experimental. */ /* Experimental. */
flags = fcntl(ping_data->sock, F_GETFL, 0); flags = fcntl(ping_data->sock, F_GETFL, 0);
@ -73,62 +74,66 @@ uerr_t tcp_ping(ping_t * ping_data)
gettimeofday(&start_time, 0); gettimeofday(&start_time, 0);
status = status =
connect(ping_data->sock, res->ai_addr, res->ai_addrlen); connect(ping_data->sock, res->ai_addr, res->ai_addrlen);
if ((status == -1) && (noblock != -1) && (errno == EINPROGRESS)) if ((status == -1) && (noblock != -1) && (errno == EINPROGRESS))
{
fd_set writefd;
FD_ZERO(&writefd);
FD_SET(ping_data->sock, &writefd);
status =
select((ping_data->sock + 1), NULL, &writefd, NULL,
&ping_data->timeout);
/* Do we need to retry if the err is EINTR? */
if (status > 0)
{ {
socklen_t arglen = sizeof(int); fd_set writefd;
if (getsockopt FD_ZERO(&writefd);
(ping_data->sock, SOL_SOCKET, SO_ERROR, &status, &arglen) < 0) FD_SET(ping_data->sock, &writefd);
status = errno;
if (status != 0) status =
errno = status, status = -1; select((ping_data->sock + 1), NULL, &writefd, NULL,
&ping_data->timeout);
if (errno == EINPROGRESS) /* Do we need to retry if the err is EINTR? */
errno = ETIMEDOUT;
} else if (status == 0) if (status > 0)
errno = ETIMEDOUT, status = -1; {
} socklen_t arglen = sizeof(int);
if (getsockopt
(ping_data->sock, SOL_SOCKET, SO_ERROR, &status, &arglen) < 0)
status = errno;
if (status != 0)
errno = status, status = -1;
if (errno == EINPROGRESS)
errno = ETIMEDOUT;
}
else if (status == 0)
errno = ETIMEDOUT, status = -1;
}
if (status < 0) if (status < 0)
{ {
close_sock(&ping_data->sock); close_sock(&ping_data->sock);
if (errno == ECONNREFUSED) if (errno == ECONNREFUSED)
{ {
free(res); free(res);
return ping_data->err = CONREFUSED; return ping_data->err = CONREFUSED;
} else if (errno == ETIMEDOUT) }
{ else if (errno == ETIMEDOUT)
free(res); {
return ping_data->err = PINGTIMEOUT; free(res);
} else return ping_data->err = PINGTIMEOUT;
{ }
free(res); else
return ping_data->err = CONERROR; {
free(res);
return ping_data->err = CONERROR;
}
} }
} else else
{ {
flags = fcntl(ping_data->sock, F_GETFL, 0); flags = fcntl(ping_data->sock, F_GETFL, 0);
if (flags != -1) if (flags != -1)
fcntl(ping_data->sock, F_SETFL, flags & ~O_NONBLOCK); fcntl(ping_data->sock, F_SETFL, flags & ~O_NONBLOCK);
} }
/* setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&opt, /* setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&opt,
(int) sizeof(opt)); */ (int) sizeof(opt)); */
@ -139,18 +144,18 @@ uerr_t tcp_ping(ping_t * ping_data)
/*So far so good connection established */ /*So far so good connection established */
bytes_read = bytes_read =
krecv(ping_data->sock, ping_buf, TCP_PING_PACKSIZE, 0, krecv(ping_data->sock, ping_buf, TCP_PING_PACKSIZE, 0,
&ping_data->timeout); &ping_data->timeout);
close_sock(&ping_data->sock); close_sock(&ping_data->sock);
proz_debug("bytes read = %d", bytes_read); proz_debug("bytes read = %d", bytes_read);
if (bytes_read == -1) if (bytes_read == -1)
{ {
if (errno == ETIMEDOUT) if (errno == ETIMEDOUT)
return ping_data->err = PINGTIMEOUT; return ping_data->err = PINGTIMEOUT;
else else
return ping_data->err = READERR; return ping_data->err = READERR;
} }
if (bytes_read == 0 || bytes_read < TCP_PING_PACKSIZE) if (bytes_read == 0 || bytes_read < TCP_PING_PACKSIZE)
return ping_data->err = READERR; return ping_data->err = READERR;
@ -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;
@ -214,95 +217,97 @@ void mass_ping(ftps_request_t * request)
k = 0; k = 0;
for (i = 0; i < num_iter; i++) for (i = 0; i < num_iter; i++)
{ {
for (j = 0; j < simul_pings; j++) for (j = 0; j < simul_pings; j++)
{
ping_t ping_request;
memset(ping_requests + k, 0, sizeof(ping_request));
/*FIXME */
ping_requests[k].timeout.tv_sec = request->ping_timeout.tv_sec;
ping_requests[k].timeout.tv_usec = request->ping_timeout.tv_usec;
ping_requests[k].host = strdup(request->mirrors[k].server_name);
ping_requests[k].port = 21;
if (pthread_create(&ping_threads[j], NULL,
(void *)&tcp_ping,
(void *)(ping_requests + k)) != 0)
proz_die("Error: Not enough system resources"
"to create thread!\n");
k++;
}
k -= simul_pings;
for (j = 0; j < simul_pings; j++)
{
/*Wait till the end of each thread. */
pthread_join(ping_threads[j], NULL);
if (ping_requests[k].err == PINGOK)
{
pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].milli_secs =
(ping_requests[k].ping_time.tv_sec * 1000) +
(ping_requests[k].ping_time.tv_usec / 1000);
request->mirrors[k].status = RESPONSEOK;
pthread_mutex_unlock(&request->access_mutex);
}
else
{
pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].status = NORESPONSE;
pthread_mutex_unlock(&request->access_mutex);
}
k++;
}
}
for (j = 0; j < num_left; j++)
{ {
ping_t ping_request; ping_t ping_request;
memset(ping_requests + k, 0, sizeof(ping_request)); memset(ping_requests + k, 0, sizeof(ping_request));
/*FIXME */ /*FIXME */
ping_requests[k].timeout.tv_sec = request->ping_timeout.tv_sec; ping_requests[k].timeout.tv_sec = request->ping_timeout.tv_sec;
ping_requests[k].timeout.tv_usec = request->ping_timeout.tv_usec; ping_requests[k].timeout.tv_usec = 0;
ping_requests[k].host = strdup(request->mirrors[k].server_name); ping_requests[k].host = strdup(request->mirrors[k].server_name);
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++;
} }
k -= simul_pings;
for (j = 0; j < simul_pings; j++)
{
/*Wait till the end of each thread. */
pthread_join(ping_threads[j], NULL);
if (ping_requests[k].err == PINGOK)
{
pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].milli_secs =
(ping_requests[k].ping_time.tv_sec * 1000) +
(ping_requests[k].ping_time.tv_usec / 1000);
request->mirrors[k].status = RESPONSEOK;
pthread_mutex_unlock(&request->access_mutex);
} else
{
pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].status = NORESPONSE;
pthread_mutex_unlock(&request->access_mutex);
}
k++;
}
}
for (j = 0; j < num_left; j++)
{
ping_t ping_request;
memset(ping_requests + k, 0, sizeof(ping_request));
/*FIXME */
ping_requests[k].timeout.tv_sec = request->ping_timeout.tv_sec;
ping_requests[k].timeout.tv_usec = 0;
ping_requests[k].host = strdup(request->mirrors[k].server_name);
ping_requests[k].port = 21;
if (pthread_create(&ping_threads[j], NULL,
(void *) &tcp_ping,
(void *) (&ping_requests[k])) != 0)
proz_die("Error: Not enough system resources" "to create thread!\n");
k++;
}
k -= num_left; k -= num_left;
for (j = 0; j < num_left; j++) for (j = 0; j < num_left; j++)
{ {
/*Wait till the end of each thread. */ /*Wait till the end of each thread. */
pthread_join(ping_threads[j], NULL); pthread_join(ping_threads[j], NULL);
/*Wait till the end of each thread. */ /*Wait till the end of each thread. */
pthread_join(ping_threads[j], NULL); pthread_join(ping_threads[j], NULL);
if (ping_requests[k].err == PINGOK) if (ping_requests[k].err == PINGOK)
{ {
pthread_mutex_lock(&request->access_mutex); pthread_mutex_lock(&request->access_mutex);
request->mirrors[k].milli_secs = request->mirrors[k].milli_secs =
(ping_requests[k].ping_time.tv_sec * 1000) + (ping_requests[k].ping_time.tv_sec * 1000) +
(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); {
request->mirrors[k].status = NORESPONSE; pthread_mutex_lock(&request->access_mutex);
pthread_mutex_unlock(&request->access_mutex); request->mirrors[k].status = NORESPONSE;
pthread_mutex_unlock(&request->access_mutex);
}
k++;
} }
k++;
}
proz_debug("mass_ping complete."); proz_debug("mass_ping complete.");
pthread_mutex_lock(&request->access_mutex); pthread_mutex_lock(&request->access_mutex);

View File

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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,55 +34,55 @@
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,
SERVERCLOSECONERR, CONPORTERR, SERVERCLOSECONERR, CONPORTERR,
/* URL handling related value */ /* URL handling related value */
URLOK, URLHTTP, URLFTP, URLFILE, URLUNKNOWN, URLBADPORT, URLOK, URLHTTP, URLFTP, URLFILE, URLUNKNOWN, URLBADPORT,
URLBADHOST, URLBADPATTERN, URLBADHOST, URLBADPATTERN,
/* HTTP related values */ /* HTTP related values */
NEWLOCATION, HOK, HEOF, HERR, HAUTHREQ, HAUTHFAIL, NEWLOCATION, HOK, HEOF, HERR, HAUTHREQ, HAUTHFAIL,
HTTPNSFOD, HTTPNSFOD,
/*FTP related value */ /*FTP related value */
FTPOK, FTPLOGINC, FTPLOGREFUSED, FTPPORTERR, FTPOK, FTPLOGINC, FTPLOGREFUSED, FTPPORTERR,
FTPNSFOD, FTPRETROK, FTPUNKNOWNTYPE, FTPUNKNOWNCMD, FTPSIZEFAIL, FTPNSFOD, FTPRETROK, FTPUNKNOWNTYPE, FTPUNKNOWNCMD, FTPSIZEFAIL,
FTPERR, FTPRESTFAIL, FTPACCDENIED, FTPERR, FTPRESTFAIL, FTPACCDENIED,
FTPPWDERR, FTPPWDERR,
FTPINVPASV, FTPNOPASV, FTPCONREFUSED, FTPCWDFAIL, FTPPWDFAIL, FTPINVPASV, FTPNOPASV, FTPCONREFUSED, FTPCWDFAIL, FTPPWDFAIL,
FTPSERVCLOSEDATLOGIN, FTPSERVCLOSEDATLOGIN,
/*FTP parsing related values */ /*FTP parsing related values */
FTPPARSEOK, FTPPARSENOTEXIST, FTPPARSEFAIL, FTPPARSEOK, FTPPARSENOTEXIST, FTPPARSEFAIL,
/*Error values that can happen due to failed proxie request */ /*Error values that can happen due to failed proxie request */
GATEWAYTIMEOUT, SERVICEUNAVAIL, BADGATEWAY, INTERNALSERVERR, GATEWAYTIMEOUT, SERVICEUNAVAIL, BADGATEWAY, INTERNALSERVERR,
UNKNOWNREQ, UNKNOWNREQ,
/*File handling related return values. */ /*File handling related return values. */
FOPENERR, FWRITEERR, FOPENERR, FWRITEERR,
RETROK, RETROK,
/*Download related retrn values. */ /*Download related retrn values. */
DLINPROGRESS, DLABORTED, DLDONE, CANTRESUME, DLLOCALFATAL, DLINPROGRESS, DLABORTED, DLDONE, CANTRESUME, DLLOCALFATAL,
DLREMOTEFATAL, DLREMOTEFATAL,
/*FTPSEARCH+ping related return values. */ /*FTPSEARCH+ping related return values. */
FTPSINPROGRESS, MASSPINGINPROGRESS, FTPSFAIL, MASSPINGDONE, FTPSINPROGRESS, MASSPINGINPROGRESS, FTPSFAIL, MASSPINGDONE,
/*PING related values */ /*PING related values */
PINGOK, PINGTIMEOUT, PINGOK, PINGTIMEOUT,
/*Misc Value */ /*Misc Value */
RETRFINISHED, READERR, RETRFINISHED, READERR,
PROXERR, WRITEERR, PROXERR, WRITEERR,
FILEISDIR, FILEISDIR,
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,467 +105,466 @@ 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. */
unsigned short port; unsigned short port;
char ftp_type; char ftp_type;
char *path, *dir, *file; /* Path, dir and file (properly decoded). */ char *path, *dir, *file; /* Path, dir and file (properly decoded). */
char *user, *passwd; /* For FTP. */ char *user, *passwd; /* For FTP. */
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,
PROXYUSERatSITE, PROXYUSERatSITE,
LOGINthenUSERatSITE, LOGINthenUSERatSITE,
OPENSITE, OPENSITE,
SITESITE, SITESITE,
HTTPPROXY, HTTPPROXY,
FTPGATE, FTPGATE,
WINGATE WINGATE
} proxy_type; } proxy_type;
typedef enum { typedef enum {
IDLE = 0, IDLE = 0,
CONNECTING, CONNECTING,
LOGGININ, LOGGININ,
DOWNLOADING, DOWNLOADING,
COMPLETED, COMPLETED,
LOGINFAIL, LOGINFAIL,
CONREJECT, CONREJECT,
REMOTEFATAL, REMOTEFATAL,
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. */
/* -1 = Accept ranges not found. /* -1 = Accept ranges not found.
0 = Accepts range is none. 0 = Accepts range is none.
1 = Accepts ranges. */ 1 = Accepts ranges. */
int accept_ranges; int accept_ranges;
char *newloc; /* New location (redirection). */ char *newloc; /* New location (redirection). */
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;
/* For netrc. */ /* For netrc. */
netrc_entry *netrc_list; netrc_entry *netrc_list;
boolean use_netrc; boolean use_netrc;
char *home_dir; char *home_dir;
char *ftp_default_user; char *ftp_default_user;
char *ftp_default_passwd; char *ftp_default_passwd;
char *dl_dir; char *dl_dir;
char *output_dir; char *output_dir;
char *log_dir; char *log_dir;
boolean ftp_use_pasv; boolean ftp_use_pasv;
proxy_info *ftp_proxy; proxy_info *ftp_proxy;
proxy_info *http_proxy; proxy_info *http_proxy;
boolean http_no_cache; boolean http_no_cache;
/* the default timeout for all the connection types (ctrl, data etc) */ /* the default timeout for all the connection types (ctrl, data etc) */
struct timeval conn_timeout; struct timeval conn_timeout;
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,
path,protocol etc. */
urlinfo u;
/* struct which contains the parsed url info. It includes the remote file, /* The error status of the connection. */
path,protocol etc. */ uerr_t err;
urlinfo u;
/* The error status of the connection. */ /* Proxy specific info. */
uerr_t err;
/* Proxy specific info. */ proxy_info *ftp_proxy;
proxy_info *http_proxy;
proxy_info *ftp_proxy; /* Netrc. */
proxy_info *http_proxy; boolean use_netrc;
/* Netrc. */ /* FTP specific info. */
boolean use_netrc; boolean ftp_use_pasv;
struct timeval xfer_timeout;
struct timeval conn_timeout;
struct timeval ctrl_timeout;
unsigned char pasv_addr[6];
int ctrl_sock;
int data_sock;
int listen_sock;
/* FTP specific info. */ /* Additional info about what this URL is. */
boolean ftp_use_pasv; /* FIXME Should this be in the url_info struct? */
struct timeval xfer_timeout; file_type_t file_type;
struct timeval conn_timeout;
struct timeval ctrl_timeout;
unsigned char pasv_addr[6];
int ctrl_sock;
int data_sock;
int listen_sock;
/* Additional info about what this URL is. */ /* The lines that the server returned. */
/* FIXME Should this be in the url_info struct? */ response_line *serv_ret_lines;
file_type_t file_type;
/* The lines that the server returned. */ /* Does the server support resume? */
response_line *serv_ret_lines; boolean resume_support;
/* Does the server support resume? */ /* The file name to save the data to locally. */
boolean resume_support; char *localfile;
/* The file name to save the data to locally. */ /* Pointer to file that we will be saving the data to locally. */
char *localfile; FILE *fp;
/* Pointer to file that we will be saving the data to locally. */ /* Tells whether to open the file for appending or for writing etc.
FILE *fp; Used for adding resume support. */
char *file_mode;
/* Tells whether to open the file for appending or for writing etc. /* FIXME Add an enum here to say whether run mode is resume or normal etc.
Used for adding resume support. */ and remove the file mode. */
char *file_mode;
/* FIXME Add an enum here to say whether run mode is resume or normal etc. off_t remote_startpos;
and remove the file mode. */ off_t orig_remote_startpos;
off_t remote_endpos;
off_t remote_bytes_received;
off_t remote_startpos; off_t main_file_size;
off_t orig_remote_startpos;
off_t remote_endpos;
off_t remote_bytes_received;
off_t main_file_size; /* The permanent base offset from the beginning of the file, put in
anticipation of making the threads download to a single file. */
off_t local_base_offset;
/* The permanent base offset from the beginning of the file, put in /* Indicates the startpos of the localfile. It is always 0 in normal mode
anticipation of making the threads download to a single file. */ and can be any positive value in resume mode. */
off_t local_base_offset; off_t local_startpos;
/* Indicates the startpos of the localfile. It is always 0 in normal mode /* The start position at the beginning of the download. */
and can be any positive value in resume mode. */ off_t orig_local_startpos;
off_t local_startpos; /* long bytes_xferred; */
dl_status status;
char *szBuffer;
/* The start position at the beginning of the download. */ /* Tells the download thread whether to abort the download or not. */
off_t orig_local_startpos; boolean abort;
/* long bytes_xferred; */
dl_status status;
char *szBuffer;
/* Tells the download thread whether to abort the download or not. */ /* Information about the connection's start and end time. */
boolean abort; struct timeval time_begin;
struct timeval time_end;
/* Information about the connection's start and end time. */ /* Info about whether to retry the thread or not. */
struct timeval time_begin; boolean retry;
struct timeval time_end;
/* Info about whether to retry the thread or not. */ /* The number of attempts to try to complete a connection. 0 means unlimited
boolean retry; connection attempts. */
int max_attempts;
/* The number of attempts that this connection has been tried */
int attempts;
/* The number of attempts to try to complete a connection. 0 means unlimited /* The time when to try to restart the connection. */
connection attempts. */ struct timeval retry_delay;
int max_attempts;
/* The number of attempts that this connection has been tried */
int attempts;
/* The time when to try to restart the connection. */ /* Each connection will acquire this mutex before changing state. */
struct timeval retry_delay; pthread_mutex_t *status_change_mutex;
/*This will be broadcast when the connection starts connecting */
pthread_cond_t connecting_cond;
/* Each connection will acquire this mutex before changing state. */ /* User agent for HTTP. */
pthread_mutex_t *status_change_mutex; char *user_agent;
/*This will be broadcast when the connection starts connecting */
pthread_cond_t connecting_cond;
/* User agent for HTTP. */ http_stat_t hs;
char *user_agent; message_proc msg_proc;
/*additional callback data whcih is specified by the user
http_stat_t hs; that is passed to msg_proc */
message_proc msg_proc; void *cb_data;
/*additional callback data whcih is specified by the user /* Indicates whether a conenction is running or not */
that is passed to msg_proc */ int running;
void *cb_data; /*Mutex used to lock acesss to data in this struct
/* Indicates whether a conenction is running or not */ that is accesed/written by other threads */
int running; pthread_mutex_t access_mutex;
/*Mutex used to lock acesss to data in this struct /*This indicates that we should use the pragma no-cache directive for http proxies */
that is accesed/written by other threads */ boolean http_no_cache;
pthread_mutex_t access_mutex; /*The rate of this connection whcih is calcualted */
/*This indicates that we should use the pragma no-cache directive for http proxies */ long rate_bps;
boolean http_no_cache; /*We limit the connections speed to this */
/*The rate of this connection whcih is calcualted */ long max_allowed_bps;
long rate_bps; } connection_t;
/*We limit the connections speed to this */
long max_allowed_bps;
} 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;
char *full_name; char *full_name;
char *file_size; char *file_size;
struct timeval tv; struct timeval tv;
int milli_secs; int milli_secs;
int num_paths; int num_paths;
ftp_mirror_stat_t status; ftp_mirror_stat_t status;
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;
ftpsearch_server_type_t server_type; ftpsearch_server_type_t server_type;
ftp_mirror_t *mirrors; ftp_mirror_t *mirrors;
int num_mirrors; int num_mirrors;
uerr_t err; uerr_t err;
boolean info_running; boolean info_running;
boolean mass_ping_running; boolean mass_ping_running;
pthread_mutex_t access_mutex; pthread_mutex_t access_mutex;
pthread_t info_thread; pthread_t info_thread;
pthread_t mass_ping_thread; pthread_t mass_ping_thread;
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;
char *output_dir; char *output_dir;
connection_t **pconnections; connection_t **pconnections;
pthread_t *threads; pthread_t *threads;
pthread_mutex_t status_change_mutex; pthread_mutex_t status_change_mutex;
int num_connections; int num_connections;
/* Optional will be called back with info about download. */ /* Optional will be called back with info about download. */
message_proc msg_proc; message_proc msg_proc;
/*additional callback data which is specified by the user /*additional callback data which is specified by the user
that is passed to msg_proc */ that is passed to msg_proc */
void *cb_data; void *cb_data;
off_t main_file_size; off_t main_file_size;
boolean resume_mode; boolean resume_mode;
struct timeval start_time; struct timeval start_time;
/*Does this DL support resume? */ /*Does this DL support resume? */
boolean resume_support; boolean resume_support;
/*This contains the building status, 1 = building,0 build finished, -1 error occured */ /*This contains the building status, 1 = building,0 build finished, -1 error occured */
int building; int building;
/*This is the percentage of the file that is been built currently */ /*This is the percentage of the file that is been built currently */
float file_build_percentage; float file_build_percentage;
int max_simul_connections; int max_simul_connections;
/*Mutex used to lock acesss to data in this struct /*Mutex used to lock acesss to data in this struct
that is accesed/written by other threads */ that is accesed/written by other threads */
pthread_mutex_t access_mutex; pthread_mutex_t access_mutex;
/* The message that is returned when the file build process is finished /* The message that is returned when the file build process is finished
*/ */
char *file_build_msg; char *file_build_msg;
/*Max mps for this download */ /*Max mps for this download */
long max_allowed_bps; long max_allowed_bps;
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 */
int version; /*The version of this logfile */ int version; /*The version of this logfile */
/*Indicates whether we have got info about the files size, final URL etc */ /*Indicates whether we have got info about the files size, final URL etc */
boolean got_info; boolean got_info;
off_t file_size; off_t file_size;
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
} }
#endif #endif
#endif /* PROZILLA_H */ #endif /* PROZILLA_H */

View File

@ -1,25 +1,25 @@
/****************************************************************************** /******************************************************************************
libprozilla - a download accelerator library libprozilla - 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
******************************************************************************/ ******************************************************************************/
/* 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"
@ -35,7 +35,7 @@
/****************************************************************************** /******************************************************************************
The main function. The main function.
******************************************************************************/ ******************************************************************************/
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -49,18 +49,18 @@ int main(int argc, char **argv)
libprozrtinfo.conn_timeout.tv_sec = 100; libprozrtinfo.conn_timeout.tv_sec = 100;
proz_prepare_ftps_request(&request, "ddd-3.3.tar.bz2", 4811576, proz_prepare_ftps_request(&request, "ddd-3.3.tar.bz2", 4811576,
"http://ftpsearch.uniovi.es:8000/ftpsearch", "http://ftpsearch.uniovi.es:8000/ftpsearch",
LYCOS, 40); LYCOS, 40);
proz_get_complete_mirror_list(&request); proz_get_complete_mirror_list(&request);
for (i = 0; i < request.num_mirrors; i++) for (i = 0; i < request.num_mirrors; i++)
{ {
printf("%s\n", request.mirrors[i].server_name); printf("%s\n", request.mirrors[i].server_name);
printf("\t%d\n", request.mirrors[i].num_paths); printf("\t%d\n", request.mirrors[i].num_paths);
for (j = 0; j < request.mirrors[i].num_paths; j++) for (j = 0; j < request.mirrors[i].num_paths; j++)
printf("\t\t%s\n", request.mirrors[i].paths[j].path); printf("\t\t%s\n", request.mirrors[i].paths[j].path);
} }
timeout.tv_sec = 5; timeout.tv_sec = 5;
timeout.tv_usec = 0; timeout.tv_usec = 0;

File diff suppressed because it is too large Load Diff

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,44 +31,44 @@ 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
#endif /* URL_H */ #endif /* URL_H */

File diff suppressed because it is too large Load Diff

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

@ -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
@ -32,30 +32,30 @@
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;
got_mirror_info = FALSE; got_mirror_info = FALSE;
} }
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,138 +66,136 @@ 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 (proz_request_info_running(request) == FALSE)
{
pthread_join(request->info_thread, NULL);
if (request->err != MIRINFOK)
{
request_running = FALSE;
got_mirror_info = FALSE;
return FTPSFAIL;
}
else
{
print_status(request, rt.quiet_mode);
}
if (request_running == TRUE) request_running = FALSE;
{ got_mirror_info = TRUE;
if (proz_request_info_running (request) == FALSE)
{
pthread_join (request->info_thread, NULL);
if (request->err != MIRINFOK)
{
request_running = FALSE;
got_mirror_info = FALSE;
return FTPSFAIL;
}
else
{
print_status(request, rt.quiet_mode);
}
request_running = FALSE; request->max_simul_pings = rt.max_simul_pings;
got_mirror_info = TRUE; request->ping_timeout.tv_sec = rt.max_ping_wait;
request->ping_timeout.tv_usec = 0;
request->max_simul_pings = rt.max_simul_pings; //Launch the pinging thread
request->ping_timeout.tv_sec = rt.max_ping_wait; PrintMessage("Got mirror info, %d server(s) found\n", request->num_mirrors);
request->ping_timeout.tv_usec = 0; proz_mass_ping(request);
ping_running = TRUE;
return MASSPINGINPROGRESS;
}
return FTPSINPROGRESS;
}
//Launch the pinging thread if (ping_running == TRUE)
PrintMessage("Got mirror info, %d server(s) found\n", request->num_mirrors); {
proz_mass_ping (request); print_status(request, rt.quiet_mode);
ping_running = TRUE;
return MASSPINGINPROGRESS;
}
return FTPSINPROGRESS;
}
if (ping_running == TRUE) if (proz_request_mass_ping_running(request) == FALSE)
{ {
ping_done = TRUE;
ping_running = FALSE;
proz_sort_mirror_list(request->mirrors,
request->num_mirrors);
print_status(request, rt.quiet_mode); // We have a seprate func to display this
print_status(request, FALSE);
if (proz_request_mass_ping_running (request) == FALSE) return MASSPINGDONE;
{ }
ping_done = TRUE; return MASSPINGINPROGRESS;
ping_running = FALSE; }
proz_sort_mirror_list (request->mirrors, return MASSPINGINPROGRESS;
request->num_mirrors);
// We have a seprate func to display this
print_status(request, FALSE);
return MASSPINGDONE;
}
return MASSPINGINPROGRESS;
}
return MASSPINGINPROGRESS;
} }
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)
{
proz_cancel_mirror_list_request(window->request);
}
if (window->request_running == TRUE) if (window->ping_running == TRUE)
{ {
proz_cancel_mirror_list_request (window->request); proz_cancel_mass_ping(window->request);
} }
if (window->ping_running == TRUE)
{
proz_cancel_mass_ping (window->request);
}
} }
void FTPS_Window::print_status(ftps_request_t *request, int quiet_mode) void FTPS_Window::print_status(ftps_request_t *request, int quiet_mode)
{ {
if (quiet_mode == FALSE || rt.display_mode == DISP_CURSES) if (quiet_mode == FALSE || rt.display_mode == DISP_CURSES)
{ {
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:
DisplayInfo(i+1,1, "%-30.30s %dms\n",
request->mirrors[i].server_name,
request->mirrors[i].milli_secs);
break;
case NORESPONSE:
case ERROR:
DisplayInfo(i+1,1, "%-30.30s %s\n",
request->mirrors[i].server_name,
"NO REPONSE");
break;
default:
DisplayInfo(i+1,1, "%-30.30s %s\n",
request->mirrors[i].server_name,
"Unkown condition!!");
break;
}
}
if (rt.display_mode == DISP_STDOUT)
fprintf(stdout,"\n");
} case RESPONSEOK:
DisplayInfo(i + 1, 1, "%-30.30s %dms\n",
request->mirrors[i].server_name,
request->mirrors[i].milli_secs);
break;
case NORESPONSE:
case ERROR:
DisplayInfo(i + 1, 1, "%-30.30s %s\n",
request->mirrors[i].server_name,
"NO REPONSE");
break;
default:
DisplayInfo(i + 1, 1, "%-30.30s %s\n",
request->mirrors[i].server_name,
"Unkown condition!!");
break;
}
}
if (rt.display_mode == DISP_STDOUT)
fprintf(stdout, "\n");
}
} }

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
******************************************************************************/ ******************************************************************************/
#ifndef FTPSEARCH_WIN_H #ifndef FTPSEARCH_WIN_H
@ -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

@ -1,27 +1,27 @@
/****************************************************************************** /******************************************************************************
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
******************************************************************************/ ******************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include <config.h>
#endif /* #endif /*
* HAVE_CONFIG_H * HAVE_CONFIG_H
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -46,19 +46,19 @@ 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
*/ */
memset(&rt, 0, sizeof(rt)); memset(&rt, 0, sizeof(rt));
if (getcwd(cwd, sizeof(cwd)) == NULL) if (getcwd(cwd, sizeof(cwd)) == NULL)
{ {
proz_debug("Failed to get the current working directory"); proz_debug("Failed to get the current working directory");
strcpy(cwd, "."); strcpy(cwd, ".");
} }
if (rt.home_dir != 0) if (rt.home_dir != 0)
free(rt.home_dir); free(rt.home_dir);
@ -67,25 +67,26 @@ 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 */
if (stat(rt.config_dir, &st) == -1) if (stat(rt.config_dir, &st) == -1)
{
/*error has hapenned */
if (errno == ENOENT)
{ {
/*Create the dir then */ /*error has hapenned */
if (mkdir(rt.config_dir, S_IRWXU) != 0) if (errno == ENOENT)
{ {
perror /*Create the dir then */
(_("unable to create the directory to store the config info in")); if (mkdir(rt.config_dir, S_IRWXU) != 0)
exit(0); {
} perror
} else (_("unable to create the directory to store the config info in"));
perror(_("Error while stating the config info directory")); exit(0);
} }
}
else
perror(_("Error while stating the config info directory"));
}
/*Output the file to the directory , cwd by default */ /*Output the file to the directory , cwd by default */
@ -125,27 +126,27 @@ void set_defaults()
/* /*
* The max number of trys and the delay between each * The max number of trys and the delay between each
*/ */
rt.max_attempts = 0; /*TODO it is currently UNLIMITED */ rt.max_attempts = 0; /*TODO it is currently UNLIMITED */
rt.retry_delay = 15; /* rt.retry_delay = 15; /*
* delay in seconds * delay in seconds
*/ */
/*Default is to not log any debug info */ /*Default is to not log any debug info */
rt.debug_mode = FALSE; rt.debug_mode = FALSE;
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;
rt.max_bps_per_dl = 0; /* 0= No throttling */ rt.max_bps_per_dl = 0; /* 0= No throttling */
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

@ -17,9 +17,9 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include <config.h>
#endif /* #endif /*
* HAVE_CONFIG_H * HAVE_CONFIG_H
*/ */
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
@ -31,9 +31,9 @@
#include <ncurses.h> #include <ncurses.h>
#else #else
#include <curses.h> #include <curses.h>
#endif /* #endif /*
* HAVE_CURSES * HAVE_CURSES
*/ */
#include <ctype.h> #include <ctype.h>
#include <assert.h> #include <assert.h>
@ -47,7 +47,7 @@
/* This is used to convert the connection.status enums to a user /* This is used to convert the connection.status enums to a user
* friendly text message */ * friendly text message */
/* the enums are defined in connection.h and are as belor /* the enums are defined in connection.h and are as belor
*typedef enum { *typedef enum {
* IDLE = 0, * IDLE = 0,
* CONNECTING, * CONNECTING,
* LOGGININ, * LOGGININ,
@ -57,26 +57,26 @@
* 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",
"Logging in", "Logging in",
"Downloading", "Downloading",
"Completed", "Completed",
/* I have decided to change the login failed message /* I have decided to change the login failed message
* to something else like "login rejected" because people * to something else like "login rejected" because people
* might get alarmed and abort the download rather than * might get alarmed and abort the download rather than
* letting prozilla handle it */ * letting prozilla handle it */
"Login Denied", "Login Denied",
"Connect Refused", "Connect Refused",
"Remote Fatal", "Remote Fatal",
"Local Fatal", "Local Fatal",
"Timed Out", "Timed Out",
"Max attempts reached", "Max attempts reached",
}; };
#define CTRL(x) ((x) & 0x1F) #define CTRL(x) ((x) & 0x1F)
@ -109,120 +109,117 @@ 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 */
void curses_message(char *message) 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
pthread_mutex_lock(&curses_msg_mutex); */
pthread_mutex_lock(&curses_msg_mutex);
/* /*
* get the cursor position * get the cursor position
*/ */
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);
attrset(COLOR_PAIR(NULL_PAIR)); attrset(COLOR_PAIR(NULL_PAIR));
/* /*
* Unlock the mutex * Unlock the mutex
*/ */
refresh(); refresh();
kwattr_set(stdscr, attrs, i, NULL); kwattr_set(stdscr, attrs, i, NULL);
/* /*
* set the cursor to whhere it was */ * set the cursor to whhere it was */
move(y, x);
pthread_mutex_unlock(&curses_msg_mutex);
move(y, x);
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;
int ch; int ch;
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);
attrset(COLOR_PAIR(PROMPT_PAIR) | A_BOLD); attrset(COLOR_PAIR(PROMPT_PAIR) | A_BOLD);
move(19, 0); move(19, 0);
clrtoeol(); clrtoeol();
move(20, 0); move(20, 0);
clrtoeol(); clrtoeol();
move(21, 0); move(21, 0);
clrtoeol(); clrtoeol();
mvprintw(19, 0, "%s", p); mvprintw(19, 0, "%s", p);
echo(); echo();
refresh(); refresh();
do do
{ {
napms(20); napms(20);
ch = getch(); ch = getch();
} } while (ch == ERR);
while (ch == ERR);
refresh(); refresh();
noecho(); noecho();
kwattr_set(stdscr, attrs, i, NULL); kwattr_set(stdscr, attrs, i, NULL);
/* /*
* set the cursor to where it was * set the cursor to where it was
*/ */
move(y, x); move(y, x);
/* /*
* the following strange line is for compatibility * the following strange line is for compatibility
*/ */
return islower(ch) ? toupper(ch) : ch; return islower(ch) ? toupper(ch) : ch;
} }
void initCurses() void initCurses()
{ {
initscr(); initscr();
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
start_color(); start_color();
noecho(); noecho();
nodelay(stdscr, TRUE); nodelay(stdscr, TRUE);
init_pair(HIGHLIGHT_PAIR, COLOR_GREEN, COLOR_BLACK); init_pair(HIGHLIGHT_PAIR, COLOR_GREEN, COLOR_BLACK);
init_pair(MSG_PAIR, COLOR_YELLOW, COLOR_BLUE); init_pair(MSG_PAIR, COLOR_YELLOW, COLOR_BLUE);
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();
} }
@ -231,22 +228,22 @@ void PrintMessage(const char *format, ...)
va_list args; va_list args;
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)
{ {
curses_message(message); curses_message(message);
} }
else else
{ {
if (fwrite(message, 1, strlen(message), stdout) != strlen(message)) if (fwrite(message, 1, strlen(message), stdout) != strlen(message))
{ {
return; return;
} }
} }
delay_ms(500); delay_ms(500);
} }
void DisplayInfo(int row, int col, const char *format, ...) void DisplayInfo(int row, int col, const char *format, ...)
@ -254,52 +251,53 @@ void DisplayInfo(int row, int col, const char *format, ...)
va_list args; va_list args;
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();
} }
else else
{ {
if (fwrite(message, 1, strlen(message), stdout) != strlen(message)) if (fwrite(message, 1, strlen(message), stdout) != strlen(message))
{ {
return; return;
} }
} }
// 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));
total_bytes_got = proz_download_get_total_bytes_got(download) / 1024; total_bytes_got = proz_download_get_total_bytes_got(download) / 1024;
if (start == 1) if (start == 1)
{ {
time_stamp = time(NULL); time_stamp = time(NULL);
bytes_got_last_time = total_bytes_got; bytes_got_last_time = total_bytes_got;
start = 0; start = 0;
} }
if (time_stamp + 1 == time(NULL)) if (time_stamp + 1 == time(NULL))
{ {
current_dl_speed = total_bytes_got - bytes_got_last_time; current_dl_speed = total_bytes_got - bytes_got_last_time;
time_stamp = time(NULL); time_stamp = time(NULL);
@ -308,57 +306,57 @@ 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;
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD); attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
mvprintw(line++, 1, "%s", download->u.url); mvprintw(line++, 1, "%s", download->u.url);
line++; line++;
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

@ -26,12 +26,12 @@ extern "C" {
/*definnitions about the ncurse colors that the app will use*/ /*definnitions about the ncurse colors that the app will use*/
enum { enum {
NULL_PAIR = 0, NULL_PAIR = 0,
HIGHLIGHT_PAIR, HIGHLIGHT_PAIR,
MSG_PAIR, MSG_PAIR,
WARN_PAIR, WARN_PAIR,
PROMPT_PAIR, PROMPT_PAIR,
SELECTED_PAIR SELECTED_PAIR
}; };
void initCurses(); void initCurses();

View File

@ -1,20 +1,20 @@
/****************************************************************************** /******************************************************************************
prozilla - a front end for prozilla, a download accelerator library 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
# include <config.h> # include <config.h>
@ -47,39 +47,39 @@ struct runtime rt;
// structure for options parsing, // structure for options parsing,
struct option long_opts[] = { 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,87 +89,87 @@ 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"
" it under the terms of the GNU General Public License as published by\n" " it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 2, or (at your option)\n" " the Free Software Foundation; either version 2, or (at your option)\n"
" any later version.\n" " any later version.\n"
"\n" "\n"
" This program is distributed in the hope that it will be useful,\n" " This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n" " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" GNU General Public License for more details.\n" " GNU General Public License for more details.\n"
"\n" "\n"
" You should have received a copy of the GNU General Public License\n" " You should have received a copy of the GNU General Public License\n"
" along with this program; if not, write to the Free Software\n" " along with this program; if not, write to the Free Software\n"
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"); " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n");
} }
/* 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"
"\n" "\n"
"Options:\n" "Options:\n"
" -h, --help Give this help\n" " -h, --help Give this help\n"
" -r, --resume Resume an interrupted download\n" " -r, --resume Resume an interrupted download\n"
" -f, --force Never prompt the user when overwriting files\n" " -f, --force Never prompt the user when overwriting files\n"
" -1 Force a single connection only\n" " -1 Force a single connection only\n"
" -n, --no-netrc Don't use .netrc, get the user/password\n" " -n, --no-netrc Don't use .netrc, get the user/password\n"
" from the command line,otherwise use the\n" " from the command line,otherwise use the\n"
" anonymous login for FTP sessions\n" " anonymous login for FTP sessions\n"
" --no-getch Instead of waiting for the user pressing a key,\n" " --no-getch Instead of waiting for the user pressing a key,\n"
" print the error to stdout and quit\n" " print the error to stdout and quit\n"
" --debug Log debugging info to a file (default is debug.log)\n" " --debug Log debugging info to a file (default is debug.log)\n"
" -v,--verbose Increase the amount of information sent to stdout\n" " -v,--verbose Increase the amount of information sent to stdout\n"
" --no-curses Don't use Curses, plain text to stdout\n" " --no-curses Don't use Curses, plain text to stdout\n"
"\n" "\n"
"Files:\n" "Files:\n"
" -O, --output-document=FILE write documents to FILE\n" " -O, --output-document=FILE write documents to FILE\n"
"\n" "\n"
"Directories:\n" "Directories:\n"
" -P, --directory-prefix=DIR save the generated file to DIR/\n" " -P, --directory-prefix=DIR save the generated file to DIR/\n"
"\n" "\n"
"FTP Options:\n" "FTP Options:\n"
" --use-port Force usage of PORT insted of PASV (default)\n" " --use-port Force usage of PORT insted of PASV (default)\n"
" for ftp transactions\n" " for ftp transactions\n"
"\n" "\n"
"Download Options:\n" "Download Options:\n"
" -s, --ftpsearch Do a ftpsearch for faster mirrors\n" " -s, --ftpsearch Do a ftpsearch for faster mirrors\n"
" --no-search Do a direct download (no ftpsearch)\n" " --no-search Do a direct download (no ftpsearch)\n"
" -k=n Use n connections instead of the default(4)\n" " -k=n Use n connections instead of the default(4)\n"
" --timeout=n Set the timeout for connections to n seconds\n" " --timeout=n Set the timeout for connections to n seconds\n"
" (default 180)\n" " (default 180)\n"
" -t, --tries=n Set number of attempts to n (default(200), 0=unlimited)\n" " -t, --tries=n Set number of attempts to n (default(200), 0=unlimited)\n"
" --retry-delay=n Set the time between retrys to n seconds\n" " --retry-delay=n Set the time between retrys to n seconds\n"
" (default 15 seconds)\n" " (default 15 seconds)\n"
" --max-bps=n Limit bandwith consumed to n bps (0=unlimited)\n" " --max-bps=n Limit bandwith consumed to n bps (0=unlimited)\n"
"\n" "\n"
"FTP Search Options:\n" "FTP Search Options:\n"
" --pt=n Wait 2*n seconds for a server response (default 2*4)\n" " --pt=n Wait 2*n seconds for a server response (default 2*4)\n"
" --pao=n Ping n servers at once(default 5 servers at once)\n" " --pao=n Ping n servers at once(default 5 servers at once)\n"
" --max-ftps-servers=n Request a max of n servers from ftpsearch (default 40)\n" " --max-ftps-servers=n Request a max of n servers from ftpsearch (default 40)\n"
" --min-size=n If a file is smaller than 'n'Kb, don't search, just download it\n" " --min-size=n If a file is smaller than 'n'Kb, don't search, just download it\n"
" --ftpsid=n The ftpsearch server to use\n" " --ftpsid=n The ftpsearch server to use\n"
" (0=filesearching.com\n" " (0=filesearching.com\n"
" 1=ftpsearch.elmundo.es\n" " 1=ftpsearch.elmundo.es\n"
"\n" "\n"
"Information Options:\n" "Information Options:\n"
" -L, --license Display software license\n" " -L, --license Display software license\n"
" -V, --version Display version number\n" " -V, --version Display version number\n"
"\n" "\n"
"ProZilla homepage: http://prozilla.genesys.ro\n" "ProZilla homepage: http://prozilla.genesys.ro\n"
"Please report bugs to <prozilla@genesys.ro>\n"); "Please report bugs to <prozilla@genesys.ro>\n");
} }
@ -177,381 +177,396 @@ 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...
while (dl_win->status != DL_DONE && dl_win->status != DL_IDLING && dl_win->status != DL_ABORTED)
//need a timer here... {
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...
{ dl_win->my_cb();
delay_ms (700); //wait before checking the status again... }
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
load_prefs (); //load values from the config file
while ((c = proz_init(argc, argv); //init libprozilla
getopt_long (argc, argv, "?hvrfk:1Lt:VgsP:O:", long_opts, set_defaults(); //set some reasonable defaults
NULL)) != EOF) load_prefs(); //load values from the config file
{
switch (c)
{
case 'L':
license ();
exit (0);
case 'h':
help ();
exit (0);
case 'V':
version ();
exit (0);
case 'r':
rt.resume_mode = RESUME;
break;
case 'f':
rt.force_mode = TRUE;
break;
case 'k':
if (setargval (optarg, &rt.num_connections) != 1)
{
/*
* The call failed due to a invalid arg
*/
printf (_("Error: Invalid arguments for the -k option\n" "Please type proz --help for help\n"));
exit (0);
}
if (rt.num_connections == 0) while ((c =
{ getopt_long(argc, argv, "?hvrfk:1Lt:VgsP:O:", long_opts,
printf (_("Hey! How can I download anything with 0 (Zero)" " connections!?\n" "Please type proz --help for help\n")); NULL)) != EOF)
exit (0); {
} switch (c)
{
case 'L':
license();
exit(0);
break; case 'h':
case 't': help();
if (setargval (optarg, &rt.max_attempts) != 1) exit(0);
{
/*
* 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"));
exit (0);
}
break;
case 'n':
/*
* Don't use ~/.netrc"
*/
rt.use_netrc = FALSE;
break;
case 'O':
/*
* Output file name
*/
opt_file = kstrdup(optarg);
break;
case 'P':
/*
* Save the downloaded file to DIR
*/
rt.output_dir = kstrdup (optarg);
break;
case '?':
help ();
exit (0);
break;
case '1':
rt.num_connections = 1;
break;
case 'g': case 'V':
/* version();
* TODO solve this soon exit(0);
*/
printf ("Error: GTK interface is not supported in "
"the development version currently\n");
exit (0);
break;
case 129: case 'r':
/* rt.resume_mode = RESUME;
* lets use PORT as the default then break;
*/
rt.ftp_use_pasv = FALSE;
break;
case 130:
/*
* retry-delay option
*/
if (setargval (optarg, &rt.retry_delay) != 1)
{
/*
* 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"));
exit (0);
}
break;
case 131:
/*--timout option */
if (setargval (optarg, &rt.itimeout) != 1)
{
/*
* The call failed due to a invalid arg
*/
printf (_("Error: Invalid arguments for the --timeout option\n" "Please type proz --help for help\n"));
exit (0);
}
break;
case 132:
/* --no-getch option */
rt.dont_prompt = TRUE;
break;
case 133: case 'f':
/* --debug option */ rt.force_mode = TRUE;
rt.debug_mode = TRUE; break;
rt.libdebug_mode=TRUE;
break;
case 'v': case 'k':
/* --verbose option */ if (setargval(optarg, &rt.num_connections) != 1)
rt.quiet_mode = FALSE; {
break; /*
* The call failed due to a invalid arg
*/
printf(_("Error: Invalid arguments for the -k option\n" "Please type proz --help for help\n"));
exit(0);
}
case 's': if (rt.num_connections == 0)
/* --ftpsearch option */ {
rt.ftp_search = TRUE; printf(_("Hey! How can I download anything with 0 (Zero)" " connections!?\n" "Please type proz --help for help\n"));
break; exit(0);
}
case 135: break;
/* --no-search option */
rt.ftp_search = FALSE;
break;
case 136: case 't':
/* --pt option */ if (setargval(optarg, &rt.max_attempts) != 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 -t or --tries option(s)\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); }
} break;
if (rt.max_ping_wait == 0) case '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")); * Don't use ~/.netrc"
exit (0); */
} rt.use_netrc = FALSE;
break;
break; case 'O':
case 137: /*
/* --pao option */ * Output file name
if (setargval (optarg, &rt.max_simul_pings) != 1) */
{ opt_file = kstrdup(optarg);
/* break;
* The call failed due to a invalid arg
*/
printf (_("Error: Invalid arguments for the --pao option\n" "Please type proz --help for help\n"));
exit (0);
}
if (rt.max_simul_pings == 0) case 'P':
{ /*
printf (_("Hey you! Will pinging Zero(0) servers at once" " achive anything for me!?\n" "Please type proz --help for help\n")); * Save the downloaded file to DIR
exit (0); */
} rt.output_dir = kstrdup(optarg);
break;
break; case '?':
help();
exit(0);
break;
case 138: case '1':
/* --max-ftp-servers option */ rt.num_connections = 1;
if (setargval (optarg, &rt.ftps_mirror_req_n) != 1) break;
{
/*
* The call failed due to a invalid arg
*/
printf (_("Error: Invalid arguments for the --pao option\n" "Please type proz --help for help\n"));
exit (0);
}
if (rt.ftps_mirror_req_n == 0) case 'g':
{ /*
printf (_("Hey! Will requesting Zero(0) servers at once" "from the ftpearch achive anything!?\n" "Please type proz --help for help\n")); * TODO solve this soon
exit (0); */
} printf("Error: GTK interface is not supported in "
"the development version currently\n");
exit(0);
break;
break; case 129:
case 139: /*
/* --max-bps */ * lets use PORT as the default then
if (setlongargval (optarg, &rt.max_bps_per_dl) != 1) */
{ rt.ftp_use_pasv = FALSE;
/* break;
* The call failed due to a invalid arg
*/
printf (_("Error: Invalid arguments for the --max-bps option\n" "Please type proz --help for help\n"));
exit (0);
}
break;
case 140:
rt.display_mode = DISP_STDOUT;
break;
case 141:
/* --min-size */
if (setlongargval (optarg, &rt.min_search_size) != 1)
{
/*
* 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"));
exit (0);
}
break;
case 142: case 130:
/* --ftpsid */ /*
* retry-delay option
*/
if (setargval(optarg, &rt.retry_delay) != 1)
{
/*
* 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"));
exit(0);
}
break;
if (setargval (optarg, &rt.ftpsearch_server_id) != 1) case 131:
{ /*--timout option */
/* if (setargval(optarg, &rt.itimeout) != 1)
* The call failed due to a invalid arg {
*/ /*
printf (_("Error: Invalid arguments for the --ftpsid option\n" "Please type proz --help for help\n")); * The call failed due to a invalid arg
exit (0); */
} printf(_("Error: Invalid arguments for the --timeout option\n" "Please type proz --help for help\n"));
exit(0);
}
break;
if (rt.ftpsearch_server_id < 0 || rt.ftpsearch_server_id >1) case 132:
{ /* --no-getch option */
printf (_("The available servers are (0) filesearching.com and (1) ftpsearch.elmundo.es\n" "Please type proz --help for help\n")); rt.dont_prompt = TRUE;
exit (0); break;
}
break; case 133:
/* --debug option */
rt.debug_mode = TRUE;
rt.libdebug_mode = TRUE;
break;
case 'v':
/* --verbose option */
rt.quiet_mode = FALSE;
break;
case 's':
/* --ftpsearch option */
rt.ftp_search = TRUE;
break;
case 135:
/* --no-search option */
rt.ftp_search = FALSE;
break;
case 136:
/* --pt option */
if (setargval(optarg, &rt.max_ping_wait) != 1)
{
/*
* The call failed due to a invalid arg
*/
printf(_("Error: Invalid arguments for the --pt option\n" "Please type proz --help for help\n"));
exit(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"));
exit(0);
}
break;
case 137:
/* --pao option */
if (setargval(optarg, &rt.max_simul_pings) != 1)
{
/*
* The call failed due to a invalid arg
*/
printf(_("Error: Invalid arguments for the --pao option\n" "Please type proz --help for help\n"));
exit(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"));
exit(0);
}
break;
case 138:
/* --max-ftp-servers option */
if (setargval(optarg, &rt.ftps_mirror_req_n) != 1)
{
/*
* The call failed due to a invalid arg
*/
printf(_("Error: Invalid arguments for the --pao option\n" "Please type proz --help for help\n"));
exit(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"));
exit(0);
}
break;
case 139:
/* --max-bps */
if (setlongargval(optarg, &rt.max_bps_per_dl) != 1)
{
/*
* The call failed due to a invalid arg
*/
printf(_("Error: Invalid arguments for the --max-bps option\n" "Please type proz --help for help\n"));
exit(0);
}
break;
case 140:
rt.display_mode = DISP_STDOUT;
break;
case 141:
/* --min-size */
if (setlongargval(optarg, &rt.min_search_size) != 1)
{
/*
* 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"));
exit(0);
}
break;
case 142:
/* --ftpsid */
if (setargval(optarg, &rt.ftpsearch_server_id) != 1)
{
/*
* The call failed due to a invalid arg
*/
printf(_("Error: Invalid arguments for the --ftpsid option\n" "Please type proz --help for help\n"));
exit(0);
}
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"));
exit(0);
}
break;
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();
/* we will now see whether the user has specfied any urls in the command line and add them */ /* we will now see whether the user has specfied any urls in the command line and add them */
for (int i = optind; i < argc; i++) for (int i = optind; i < argc; i++)
{ {
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;
@ -37,7 +37,7 @@ struct runtime {
int use_netrc; int use_netrc;
int ftp_use_pasv; int ftp_use_pasv;
int max_attempts; int max_attempts;
int retry_delay; /*delay in seconds */ int retry_delay; /*delay in seconds */
/* /*
* The timeout period for the connections * The timeout period for the connections
*/ */
@ -71,8 +71,8 @@ struct runtime {
//int use_ftpsearch; //int use_ftpsearch;
int ftpsearch_server_id; int ftpsearch_server_id;
//new options //new options
int resume_mode; // int resume_mode; //
int dont_prompt; //don't prompt user, display message and die int dont_prompt; //don't prompt user, display message and die
int display_mode; //curses, bare terminal, others... int display_mode; //curses, bare terminal, others...
long min_search_size; //size in K long min_search_size; //size in K
}; };

View File

@ -4,103 +4,104 @@
int is_number(char *str) int is_number(char *str)
{ {
int i = 0; int i = 0;
while (str[i]) while (str[i])
{ {
if (isdigit(str[i]) == 0) if (isdigit(str[i]) == 0)
{ {
return 0; return 0;
} }
i++; i++;
} }
return 1; return 1;
} }
/* TODO port these functions */ /* TODO port these functions */
char *kstrdup(const char *s) char *kstrdup(const char *s)
{ {
char *s1; char *s1;
s1 = strdup(s); s1 = strdup(s);
if (!s1) if (!s1)
{ {
// 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)
{ {
if (*optstr == '=') if (*optstr == '=')
{ {
if (is_number(optstr + 1) == 1) if (is_number(optstr + 1) == 1)
{ {
*num = atoi(optstr + 1); *num = atoi(optstr + 1);
return 1; return 1;
} else }
{ else
return 0; {
} return 0;
} else }
{ }
if (is_number(optstr) == 1) else
{ {
*num = atoi(optstr); if (is_number(optstr) == 1)
return 1; {
*num = atoi(optstr);
} else return 1;
{ }
return 0; else
} {
return 0;
}
} }
} }
int setlongargval(char *optstr, long *num) int setlongargval(char *optstr, long *num)
{ {
if (*optstr == '=') if (*optstr == '=')
{ {
if (is_number(optstr + 1) == 1) if (is_number(optstr + 1) == 1)
{ {
*num = atol(optstr + 1); *num = atol(optstr + 1);
return 1; return 1;
} else }
{ else
return 0; {
} return 0;
} else }
{ }
if (is_number(optstr) == 1) else
{ {
*num = atol(optstr); if (is_number(optstr) == 1)
return 1; {
*num = atol(optstr);
} else return 1;
{ }
return 0; else
} {
return 0;
}
} }
} }
void delay_ms(int ms) void delay_ms(int ms)
{ {
struct timeval tv_delay; struct timeval tv_delay;
memset(&tv_delay, 0, sizeof(tv_delay)); memset(&tv_delay, 0, sizeof(tv_delay));
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

@ -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
@ -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;
@ -54,7 +54,7 @@ void set_output_dir(int i, const char *const val, FILE * const fp);
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);
void set_http_proxy_username(int i, const char *const val, void set_http_proxy_username(int i, const char *const val,
FILE * const fp); 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);
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);
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);
@ -75,249 +75,251 @@ 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); {
if (rt.num_connections <= 0 || rt.num_connections > 30) rt.num_connections = atoi(val);
rt.num_connections = 4; if (rt.num_connections <= 0 || rt.num_connections > 30)
} rt.num_connections = 4;
}
} }
void set_max_attempts(int i, const char *const val, FILE * const fp) 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); {
if (rt.max_attempts < 0) rt.max_attempts = atoi(val);
rt.max_attempts = 0; if (rt.max_attempts < 0)
} rt.max_attempts = 0;
}
} }
void set_retry_delay(int i, const char *const val, FILE * const fp) 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); {
if (rt.retry_delay < 0) rt.retry_delay = atoi(val);
rt.retry_delay = 15; if (rt.retry_delay < 0)
} rt.retry_delay = 15;
}
} }
void set_conn_timeout(int i, const char *const val, FILE * const fp) 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_usec = 0; rt.timeout.tv_sec = atoi(val);
rt.timeout.tv_usec = 0;
if (rt.timeout.tv_sec < 0) if (rt.timeout.tv_sec < 0)
rt.timeout.tv_sec = 90; rt.timeout.tv_sec = 90;
} }
} }
void set_max_bps_per_dl(int i, const char *const val, FILE * const fp) 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)
rt.max_bps_per_dl = 0;
}
if (rt.max_bps_per_dl < 0)
rt.max_bps_per_dl = 0;
}
} }
void set_use_pasv(int i, const char *const val, FILE * const fp) 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);
}
} }
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);
}
} }
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);
}
} }
void set_output_dir(int i, const char *const val, FILE * const fp) 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); {
rt.output_dir = strdup(val); free(rt.output_dir);
} 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;
if (fp != NULL) if (fp != NULL)
{
fprintf(fp, "%s:%d", rt.http_proxy->proxy_url.host,
rt.http_proxy->proxy_url.port);
} else
{
err = proz_parse_url(val, &url_data, 0);
if (err != URLOK)
{ {
proz_debug("%s does not seem to be a valid proxy value", val); fprintf(fp, "%s:%d", rt.http_proxy->proxy_url.host,
return; rt.http_proxy->proxy_url.port);
}
else
{
err = proz_parse_url(val, &url_data, 0);
if (err != URLOK)
{
proz_debug("%s does not seem to be a valid proxy value", val);
return;
}
proz_free_url(&rt.http_proxy->proxy_url, 0);
memcpy(&rt.http_proxy->proxy_url, &url_data, sizeof(url_data));
} }
proz_free_url(&rt.http_proxy->proxy_url, 0);
memcpy(&rt.http_proxy->proxy_url, &url_data, sizeof(url_data));
}
} }
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); {
rt.http_proxy->username = strdup(val); free(rt.http_proxy->username);
} rt.http_proxy->username = strdup(val);
}
} }
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); {
rt.http_proxy->passwd = strdup(val); free(rt.http_proxy->passwd);
} rt.http_proxy->passwd = strdup(val);
}
} }
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);
}
} }
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,175 +327,174 @@ 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;
if (fp != NULL) if (fp != NULL)
{
fprintf(fp, "%s:%d", rt.ftp_proxy->proxy_url.host,
rt.ftp_proxy->proxy_url.port);
} else
{
err = proz_parse_url(val, &url_data, 0);
if (err != URLOK)
{ {
proz_debug("%s does not seem to be a valid proxy value", val); fprintf(fp, "%s:%d", rt.ftp_proxy->proxy_url.host,
return; rt.ftp_proxy->proxy_url.port);
}
else
{
err = proz_parse_url(val, &url_data, 0);
if (err != URLOK)
{
proz_debug("%s does not seem to be a valid proxy value", val);
return;
}
proz_free_url(&rt.ftp_proxy->proxy_url, 0);
memcpy(&rt.ftp_proxy->proxy_url, &url_data, sizeof(url_data));
} }
proz_free_url(&rt.ftp_proxy->proxy_url, 0);
memcpy(&rt.ftp_proxy->proxy_url, &url_data, sizeof(url_data));
}
} }
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); {
rt.ftp_proxy->username = strdup(val); free(rt.ftp_proxy->username);
} rt.ftp_proxy->username = strdup(val);
}
} }
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); {
rt.ftp_proxy->passwd = strdup(val); free(rt.ftp_proxy->passwd);
} rt.ftp_proxy->passwd = strdup(val);
}
} }
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);
}
} }
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); {
if (rt.ftps_mirror_req_n <= 0 || rt.ftps_mirror_req_n> 1000) rt.ftps_mirror_req_n = atoi(val);
rt.ftps_mirror_req_n = 40; if (rt.ftps_mirror_req_n <= 0 || rt.ftps_mirror_req_n > 1000)
} 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); {
if (rt.max_simul_pings <= 0 || rt.max_simul_pings> 30) rt.max_simul_pings = atoi(val);
rt.max_simul_pings=5; if (rt.max_simul_pings <= 0 || rt.max_simul_pings > 30)
} rt.max_simul_pings = 5;
}
} }
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); {
if (rt.max_ping_wait <= 0 || rt.max_ping_wait> 30) rt.max_ping_wait = atoi(val);
rt.max_ping_wait=5; if (rt.max_ping_wait <= 0 || rt.max_ping_wait > 30)
} 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)
{ {
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); {
if (rt.ftpsearch_server_id < 0) rt.ftpsearch_server_id = atoi(val);
rt.ftpsearch_server_id = 0; if (rt.ftpsearch_server_id < 0)
else if (rt.ftpsearch_server_id > 1) rt.ftpsearch_server_id = 0;
rt.ftpsearch_server_id = 1; else if (rt.ftpsearch_server_id > 1)
rt.ftpsearch_server_id = 1;
} }
} }
void set_display_mode(int i, const char *const val, FILE * const fp) 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);
}
} }
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);
}
} }
void save_prefs() void save_prefs()
@ -503,24 +504,24 @@ void save_prefs()
int i; int i;
snprintf(config_fname, PATH_MAX, "%s/.prozilla/%s", rt.home_dir, snprintf(config_fname, PATH_MAX, "%s/.prozilla/%s", rt.home_dir,
"prozconfig"); "prozconfig");
if ((fp = fopen(config_fname, "wt")) == NULL) if ((fp = fopen(config_fname, "wt")) == NULL)
{ {
perror("could not save preferences file"); perror("could not save preferences file");
proz_debug("could not save preferences file :- %s", strerror(errno)); proz_debug("could not save preferences file :- %s", strerror(errno));
return; return;
} }
fprintf(fp, "%s", fprintf(fp, "%s",
"# ProZilla preferences file\n# This file is loaded and OVERWRITTEN each time ProZilla is run.\n# Please try to avoid writing to this file.\n#\n"); "# ProZilla preferences file\n# This file is loaded and OVERWRITTEN each time ProZilla is run.\n# Please try to avoid writing to this file.\n#\n");
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);
} }
@ -533,44 +534,43 @@ void load_prefs()
char *tok1, *tok2; char *tok1, *tok2;
snprintf(config_fname, PATH_MAX, "%s/.prozilla/%s", rt.home_dir, snprintf(config_fname, PATH_MAX, "%s/.prozilla/%s", rt.home_dir,
"prozconfig"); "prozconfig");
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 */
{ {
save_prefs(); if (errno == ENOENT) /*Create the file then if it doesnt exist */
return; {
} save_prefs();
return;
}
else else
{ {
perror(_("could not open preferences file for reading")); perror(_("could not open preferences file for reading"));
proz_debug("could not open preferences file :- %s", strerror(errno)); proz_debug("could not open preferences file :- %s", strerror(errno));
return; return;
}
} }
}
line[sizeof(line) - 1] = '\0'; line[sizeof(line) - 1] = '\0';
while (fgets(line, sizeof(line) - 1, fp) != NULL) while (fgets(line, sizeof(line) - 1, fp) != NULL)
{
tok1 = strtok(line, " =\t\r\n");
if ((tok1 == NULL) || (tok1[0] == '#'))
continue;
tok2 = strtok(NULL, "\r\n");
if (tok2 == NULL)
continue;
for (i = 0; pref_opts[i].varname != NULL; i++)
{ {
if (strcmp(tok1, pref_opts[i].varname) == 0) tok1 = strtok(line, " =\t\r\n");
{ if ((tok1 == NULL) || (tok1[0] == '#'))
if (pref_opts[i].proc != NULL) continue;
(*pref_opts[i].proc) (i, tok2, NULL); tok2 = strtok(NULL, "\r\n");
} if (tok2 == NULL)
continue;
for (i = 0; pref_opts[i].varname != NULL; i++)
{
if (strcmp(tok1, pref_opts[i].varname) == 0)
{
if (pref_opts[i].proc != NULL)
(*pref_opts[i].proc)(i, tok2, NULL);
}
}
} }
}
fclose(fp); fclose(fp);
} }

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
******************************************************************************/ ******************************************************************************/
#ifndef PREFS_H #ifndef PREFS_H
#define PREFS_H #define PREFS_H