uncrustify sources
This commit is contained in:
parent
ef090ed65d
commit
8fe8503cbd
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Common #includes and #defines. */
|
||||
|
||||
/* $Id: common.h,v 1.7 2001/10/27 23:20:24 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef COMMON_H
|
||||
@ -170,12 +170,12 @@ typedef int boolean;
|
||||
|
||||
/* Gettext */
|
||||
#include <libintl.h>
|
||||
#define _(String) dgettext (PACKAGE, String)
|
||||
#define _(String) dgettext(PACKAGE, String)
|
||||
#define gettext_noop(String) (String)
|
||||
#ifndef HAVE_GNOME
|
||||
#define N_(String) gettext_noop (String)
|
||||
#define N_(String) gettext_noop(String)
|
||||
#endif
|
||||
/* Gettext */
|
||||
|
||||
|
||||
#endif /* COMMON_H */
|
||||
#endif /* COMMON_H */
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* 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,
|
||||
struct timeval *tout)
|
||||
struct timeval *tout)
|
||||
{
|
||||
int status, noblock, flags;
|
||||
char szPort[10];
|
||||
extern int h_errno;
|
||||
int opt;
|
||||
struct timeval timeout;
|
||||
struct addrinfo hints, *res=NULL;
|
||||
int error;
|
||||
int opt;
|
||||
struct timeval timeout;
|
||||
struct addrinfo hints, *res = NULL;
|
||||
int error;
|
||||
|
||||
|
||||
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_socktype = SOCK_STREAM;
|
||||
|
||||
error = getaddrinfo(name, szPort, &hints, &res);
|
||||
if (error)
|
||||
return HOSTERR;
|
||||
error = getaddrinfo(name, szPort, &hints, &res);
|
||||
if (error)
|
||||
return HOSTERR;
|
||||
|
||||
|
||||
/* Create a socket. */
|
||||
if ((*sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1)
|
||||
{
|
||||
freeaddrinfo(res);
|
||||
return CONSOCKERR;
|
||||
}
|
||||
{
|
||||
freeaddrinfo(res);
|
||||
return CONSOCKERR;
|
||||
}
|
||||
|
||||
/* Experimental. */
|
||||
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))
|
||||
{
|
||||
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)
|
||||
status = errno;
|
||||
FD_ZERO(&writefd);
|
||||
FD_SET(*sock, &writefd);
|
||||
|
||||
if (status != 0)
|
||||
errno = status, status = -1;
|
||||
status = select((*sock + 1), NULL, &writefd, NULL, &timeout);
|
||||
|
||||
if (errno == EINPROGRESS)
|
||||
errno = ETIMEDOUT;
|
||||
} else if (status == 0)
|
||||
errno = ETIMEDOUT, status = -1;
|
||||
}
|
||||
/* Do we need to retry if the err is EINTR? */
|
||||
|
||||
if (status > 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
close(*sock);
|
||||
{
|
||||
close(*sock);
|
||||
|
||||
if (errno == ECONNREFUSED)
|
||||
{
|
||||
freeaddrinfo(res);
|
||||
return CONREFUSED;
|
||||
} else
|
||||
{
|
||||
freeaddrinfo(res);
|
||||
return CONERROR;
|
||||
if (errno == ECONNREFUSED)
|
||||
{
|
||||
freeaddrinfo(res);
|
||||
return CONREFUSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
freeaddrinfo(res);
|
||||
return CONERROR;
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
flags = fcntl(*sock, F_GETFL, 0);
|
||||
else
|
||||
{
|
||||
flags = fcntl(*sock, F_GETFL, 0);
|
||||
|
||||
if (flags != -1)
|
||||
fcntl(*sock, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
if (flags != -1)
|
||||
fcntl(*sock, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
|
||||
|
||||
/* Enable KEEPALIVE, so dead connections could be closed
|
||||
* earlier. Useful in conjuction with TCP kernel tuning
|
||||
* in /proc/sys/net/ipv4/tcp_* files. */
|
||||
opt = 1;
|
||||
setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(char *) &opt, (int) sizeof(opt));
|
||||
/* Enable KEEPALIVE, so dead connections could be closed
|
||||
* earlier. Useful in conjuction with TCP kernel tuning
|
||||
* in /proc/sys/net/ipv4/tcp_* files. */
|
||||
opt = 1;
|
||||
setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(char *)&opt, (int)sizeof(opt));
|
||||
|
||||
freeaddrinfo(res);
|
||||
|
||||
@ -137,7 +140,7 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
...
|
||||
...
|
||||
******************************************************************************/
|
||||
uerr_t bind_socket(int *sockfd)
|
||||
{
|
||||
@ -148,32 +151,32 @@ uerr_t bind_socket(int *sockfd)
|
||||
return CONSOCKERR;
|
||||
|
||||
/* 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_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. */
|
||||
if (bind(*sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
|
||||
{
|
||||
perror("bind");
|
||||
close(*sockfd);
|
||||
return BINDERR;
|
||||
}
|
||||
if (bind(*sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
|
||||
{
|
||||
perror("bind");
|
||||
close(*sockfd);
|
||||
return BINDERR;
|
||||
}
|
||||
|
||||
/* Allow only one server. */
|
||||
if (listen(*sockfd, 1) < 0)
|
||||
{
|
||||
perror("listen");
|
||||
close(*sockfd);
|
||||
return LISTENERR;
|
||||
}
|
||||
{
|
||||
perror("listen");
|
||||
close(*sockfd);
|
||||
return LISTENERR;
|
||||
}
|
||||
|
||||
return BINDOK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
...
|
||||
...
|
||||
******************************************************************************/
|
||||
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);
|
||||
memcpy(&to, timeout, sizeof(struct timeval));
|
||||
|
||||
return (select(fd + 1, writep ? NULL : &fds, writep ? &fds : NULL,
|
||||
&exceptfds, &to));
|
||||
return(select(fd + 1, writep ? NULL : &fds, writep ? &fds : NULL,
|
||||
&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,
|
||||
struct timeval *timeout)
|
||||
struct timeval *timeout)
|
||||
{
|
||||
int ret, arglen;
|
||||
|
||||
@ -203,40 +206,38 @@ int krecv(int sock, char *buffer, int size, int flags,
|
||||
assert(size >= 0);
|
||||
|
||||
do
|
||||
{
|
||||
if (timeout)
|
||||
{
|
||||
do
|
||||
{
|
||||
ret = select_fd(sock, timeout, 0);
|
||||
}
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (timeout)
|
||||
{
|
||||
do
|
||||
{
|
||||
ret = select_fd(sock, timeout, 0);
|
||||
} while ((ret == -1) && (errno == EINTR));
|
||||
|
||||
|
||||
if (ret <= 0)
|
||||
{
|
||||
/* proz_debug("Error after select res=%d errno=%d.", ret, errno); */
|
||||
if (ret <= 0)
|
||||
{
|
||||
/* proz_debug("Error after select res=%d errno=%d.", ret, errno); */
|
||||
|
||||
/* Set errno to ETIMEDOUT on timeout. */
|
||||
if (ret == 0)
|
||||
errno = ETIMEDOUT;
|
||||
/* Set errno to ETIMEDOUT on timeout. */
|
||||
if (ret == 0)
|
||||
errno = ETIMEDOUT;
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = recv(sock, buffer, size, flags);
|
||||
}
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
ret = recv(sock, buffer, size, flags);
|
||||
} while ((ret == -1) && (errno == EINTR));
|
||||
|
||||
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,
|
||||
struct timeval *timeout)
|
||||
struct timeval *timeout)
|
||||
{
|
||||
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(). */
|
||||
|
||||
while (size != 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (timeout)
|
||||
{
|
||||
do
|
||||
{
|
||||
ret = select_fd(sock, timeout, 1);
|
||||
}
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
do
|
||||
{
|
||||
if (timeout)
|
||||
{
|
||||
do
|
||||
{
|
||||
ret = select_fd(sock, timeout, 1);
|
||||
} while ((ret == -1) && (errno == EINTR));
|
||||
|
||||
if (ret <= 0)
|
||||
{
|
||||
/* Set errno to ETIMEDOUT on timeout. */
|
||||
if (ret == 0)
|
||||
errno = ETIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
ret = send(sock, buffer, size, flags);
|
||||
if (ret <= 0)
|
||||
{
|
||||
/* Set errno to ETIMEDOUT on timeout. */
|
||||
if (ret == 0)
|
||||
errno = ETIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
Accept a connection.
|
||||
Accept a connection.
|
||||
******************************************************************************/
|
||||
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);
|
||||
int sockfd;
|
||||
|
||||
sockfd = accept(listen_sock, (struct sockaddr *) &cli_addr, &clilen);
|
||||
sockfd = accept(listen_sock, (struct sockaddr *)&cli_addr, &clilen);
|
||||
if (sockfd < 0)
|
||||
{
|
||||
perror("accept");
|
||||
return ACCEPTERR;
|
||||
}
|
||||
{
|
||||
perror("accept");
|
||||
return ACCEPTERR;
|
||||
}
|
||||
|
||||
*data_sock = sockfd;
|
||||
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Connection routines. */
|
||||
|
||||
/* $Id: connect.h,v 1.17 2001/05/09 22:58:00 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef CONNECT_H
|
||||
@ -32,22 +32,22 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
uerr_t connect_to_server(int *sock, const char *name, int port,
|
||||
struct timeval *timeout);
|
||||
uerr_t connect_to_server(int *sock, const char *name, int port,
|
||||
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,
|
||||
struct timeval *timeout);
|
||||
int ksend(int sock, char *buffer, int size, int flags,
|
||||
struct timeval *timeout);
|
||||
uerr_t accept_connection(int listen_sock, int *data_sock);
|
||||
int krecv(int sock, char *buffer, int size, int flags,
|
||||
struct timeval *timeout);
|
||||
int ksend(int sock, char *buffer, int size, int flags,
|
||||
struct timeval *timeout);
|
||||
uerr_t accept_connection(int listen_sock, int *data_sock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* CONNECT_H */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* CONNECT_H */
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Several connection-related routines. */
|
||||
|
||||
/* $Id: connection.c,v 1.48 2005/09/19 16:18:02 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
...
|
||||
...
|
||||
******************************************************************************/
|
||||
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
|
||||
it for the storage of the servers response.
|
||||
This will free up the serv_ret_lines array if necessary, in order to prepare
|
||||
it for the storage of the servers response.
|
||||
******************************************************************************/
|
||||
void done_with_response(connection_t * connection)
|
||||
{
|
||||
@ -55,52 +55,51 @@ void done_with_response(connection_t * connection)
|
||||
p1 = connection->serv_ret_lines;
|
||||
|
||||
do
|
||||
{
|
||||
p = p1;
|
||||
p1 = p->next;
|
||||
kfree(p);
|
||||
}
|
||||
while (p1 != 0);
|
||||
{
|
||||
p = p1;
|
||||
p1 = p->next;
|
||||
kfree(p);
|
||||
} while (p1 != 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));
|
||||
|
||||
/* memcpy(&connection->u, url, sizeof(urlinfo));*/
|
||||
if(url)
|
||||
if (url)
|
||||
memcpy(&connection->u,
|
||||
proz_copy_url(url),
|
||||
sizeof(urlinfo));
|
||||
proz_copy_url(url),
|
||||
sizeof(urlinfo));
|
||||
|
||||
/* Copy the proxy structs. */
|
||||
if (libprozrtinfo.ftp_proxy)
|
||||
{
|
||||
connection->ftp_proxy = kmalloc(sizeof(proxy_info));
|
||||
memcpy(connection->ftp_proxy, libprozrtinfo.ftp_proxy,
|
||||
sizeof(proxy_info));
|
||||
/*
|
||||
connection->use_ftp_proxy = libprozrtinfo.use_ftp_proxy;
|
||||
*/
|
||||
}
|
||||
{
|
||||
connection->ftp_proxy = kmalloc(sizeof(proxy_info));
|
||||
memcpy(connection->ftp_proxy, libprozrtinfo.ftp_proxy,
|
||||
sizeof(proxy_info));
|
||||
/*
|
||||
connection->use_ftp_proxy = libprozrtinfo.use_ftp_proxy;
|
||||
*/
|
||||
}
|
||||
|
||||
if (libprozrtinfo.http_proxy)
|
||||
{
|
||||
connection->http_proxy = kmalloc(sizeof(proxy_info));
|
||||
memcpy(connection->http_proxy, libprozrtinfo.http_proxy,
|
||||
sizeof(proxy_info));
|
||||
/*
|
||||
connection->use_http_proxy = libprozrtinfo.use_http_proxy;
|
||||
*/
|
||||
}
|
||||
{
|
||||
connection->http_proxy = kmalloc(sizeof(proxy_info));
|
||||
memcpy(connection->http_proxy, libprozrtinfo.http_proxy,
|
||||
sizeof(proxy_info));
|
||||
/*
|
||||
connection->use_http_proxy = libprozrtinfo.use_http_proxy;
|
||||
*/
|
||||
}
|
||||
|
||||
connection->use_netrc = libprozrtinfo.use_netrc;
|
||||
|
||||
@ -115,13 +114,13 @@ connection_t * proz_connection_init(urlinfo *url,pthread_mutex_t * mutex)
|
||||
connection->attempts = 0;
|
||||
/* Initialise all with default timeouts */
|
||||
memcpy(&connection->xfer_timeout, &libprozrtinfo.conn_timeout,
|
||||
sizeof(connection->xfer_timeout));
|
||||
sizeof(connection->xfer_timeout));
|
||||
memcpy(&connection->ctrl_timeout, &libprozrtinfo.conn_timeout,
|
||||
sizeof(connection->ctrl_timeout));
|
||||
sizeof(connection->ctrl_timeout));
|
||||
memcpy(&connection->conn_timeout, &libprozrtinfo.conn_timeout,
|
||||
sizeof(connection->conn_timeout));
|
||||
sizeof(connection->conn_timeout));
|
||||
memcpy(&connection->retry_delay, &libprozrtinfo.conn_retry_delay,
|
||||
sizeof(&connection->retry_delay));
|
||||
sizeof(&connection->retry_delay));
|
||||
connection->max_attempts = libprozrtinfo.max_attempts;
|
||||
|
||||
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);
|
||||
connection->status_change_mutex = mutex;
|
||||
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);
|
||||
|
||||
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)
|
||||
{
|
||||
if (connection->status_change_mutex != 0)
|
||||
{
|
||||
pthread_mutex_lock(connection->status_change_mutex);
|
||||
connection->status = status;
|
||||
pthread_mutex_unlock(connection->status_change_mutex);
|
||||
}
|
||||
{
|
||||
pthread_mutex_lock(connection->status_change_mutex);
|
||||
connection->status = status;
|
||||
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
|
||||
the server closes the connection, in which case there is no way to know
|
||||
whether we got the complete file.
|
||||
*/
|
||||
*/
|
||||
|
||||
uerr_t connection_retr_fsize_not_known(connection_t * connection,
|
||||
char *read_buffer,
|
||||
int read_buffer_size)
|
||||
char *read_buffer,
|
||||
int read_buffer_size)
|
||||
{
|
||||
off_t bytes_read;
|
||||
|
||||
@ -166,52 +165,51 @@ uerr_t connection_retr_fsize_not_known(connection_t * connection,
|
||||
gettimeofday(&connection->time_begin, NULL);
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
while (bytes_read > 0);
|
||||
/*TODO: caclculate and throttle connections speed here */
|
||||
/*DONE: */
|
||||
connection_calc_ratebps(connection);
|
||||
connection_throttle_bps(connection);
|
||||
}
|
||||
} while (bytes_read > 0);
|
||||
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
if (errno == ETIMEDOUT)
|
||||
{
|
||||
proz_debug(_("connection timed out"));
|
||||
connection_change_status(connection, TIMEDOUT);
|
||||
if (errno == ETIMEDOUT)
|
||||
{
|
||||
proz_debug(_("connection timed out"));
|
||||
connection_change_status(connection, TIMEDOUT);
|
||||
return READERR;
|
||||
}
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return READERR;
|
||||
}
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return READERR;
|
||||
}
|
||||
|
||||
connection_change_status(connection, COMPLETED);
|
||||
|
||||
connection_show_message(connection,
|
||||
_("download for this connection completed"
|
||||
"%s : %ld received"), connection->localfile,
|
||||
connection->remote_bytes_received);
|
||||
_("download for this connection completed"
|
||||
"%s : %ld received"), connection->localfile,
|
||||
connection->remote_bytes_received);
|
||||
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
|
||||
closes the connection prematurely we know that has hapenned (because it hasn't supplied
|
||||
the required number of bytes) and return a READERR.
|
||||
*/
|
||||
*/
|
||||
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_to_get;
|
||||
@ -236,94 +234,90 @@ uerr_t connection_retr_fsize_known(connection_t * connection,
|
||||
gettimeofday(&connection->time_begin, NULL);
|
||||
|
||||
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,
|
||||
_("Server Closed Connection Prematurely!"));
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return READERR;
|
||||
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,
|
||||
_("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_show_message(connection,
|
||||
_("download for this connection completed"
|
||||
"%s : %ld received"), connection->localfile,
|
||||
connection->remote_bytes_received);
|
||||
_("download for this connection completed"
|
||||
"%s : %ld received"), connection->localfile,
|
||||
connection->remote_bytes_received);
|
||||
return FILEGETOK;
|
||||
}
|
||||
|
||||
|
||||
/* This function modifies a single connections download start and
|
||||
end info it returns 1 on sucess and -1 on error.
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
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));
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
proz_debug("connection->remote start pos after loading %ld", connection->remote_startpos);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
dl_status proz_connection_get_status(connection_t * connection)
|
||||
{
|
||||
dl_status status;
|
||||
|
||||
pthread_mutex_lock(connection->status_change_mutex);
|
||||
status = connection->status;
|
||||
pthread_mutex_unlock(connection->status_change_mutex);
|
||||
@ -335,48 +329,50 @@ dl_status proz_connection_get_status(connection_t * connection)
|
||||
char *proz_connection_get_status_string(connection_t * connection)
|
||||
{
|
||||
dl_status status;
|
||||
|
||||
pthread_mutex_lock(connection->status_change_mutex);
|
||||
status = connection->status;
|
||||
pthread_mutex_unlock(connection->status_change_mutex);
|
||||
|
||||
switch (connection->status)
|
||||
{
|
||||
{
|
||||
case IDLE:
|
||||
return(_("Idle"));
|
||||
|
||||
case IDLE:
|
||||
return (_("Idle"));
|
||||
case CONNECTING:
|
||||
return(_("Connecting"));
|
||||
|
||||
case CONNECTING:
|
||||
return (_("Connecting"));
|
||||
case LOGGININ:
|
||||
return(_("Logging in"));
|
||||
|
||||
case LOGGININ:
|
||||
return (_("Logging in"));
|
||||
case DOWNLOADING:
|
||||
return(_("Downloading"));
|
||||
break;
|
||||
|
||||
case DOWNLOADING:
|
||||
return (_("Downloading"));
|
||||
break;
|
||||
case COMPLETED:
|
||||
return (_("Completed"));
|
||||
case COMPLETED:
|
||||
return(_("Completed"));
|
||||
|
||||
case LOGINFAIL:
|
||||
return (_("Login Denied"));
|
||||
case LOGINFAIL:
|
||||
return(_("Login Denied"));
|
||||
|
||||
case CONREJECT:
|
||||
return (_("Connect Refused"));
|
||||
case CONREJECT:
|
||||
return(_("Connect Refused"));
|
||||
|
||||
case REMOTEFATAL:
|
||||
return (_("Remote Fatal"));
|
||||
case REMOTEFATAL:
|
||||
return(_("Remote Fatal"));
|
||||
|
||||
case LOCALFATAL:
|
||||
return (_("Local Fatal"));
|
||||
case LOCALFATAL:
|
||||
return(_("Local Fatal"));
|
||||
|
||||
case TIMEDOUT:
|
||||
return (_("Timed Out"));
|
||||
case MAXTRYS:
|
||||
return (_("Max attempts reached"));
|
||||
case TIMEDOUT:
|
||||
return(_("Timed Out"));
|
||||
|
||||
default:
|
||||
return (_("Unkown Status!"));
|
||||
}
|
||||
case MAXTRYS:
|
||||
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 */
|
||||
void connection_show_message(connection_t * connection, const char *format,
|
||||
...)
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
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);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Returns the total number of bytes that has being got from the server
|
||||
by this connection.
|
||||
******************************************************************************/
|
||||
Returns the total number of bytes that has being got from the server
|
||||
by this connection.
|
||||
******************************************************************************/
|
||||
off_t proz_connection_get_total_remote_bytes_got(connection_t * connection)
|
||||
{
|
||||
off_t ret;
|
||||
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
ret = (connection->remote_bytes_received
|
||||
- (connection->remote_startpos-connection->orig_remote_startpos));
|
||||
- (connection->remote_startpos - connection->orig_remote_startpos));
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
//proz_debug("CONNECTION TOTAL REMOTE BYTES GOT =%lld", ret);
|
||||
return ret;
|
||||
@ -436,18 +432,17 @@ void proz_get_url_info_loop(connection_t * connection, pthread_t *thread)
|
||||
assert(thread);
|
||||
connection->running = TRUE;
|
||||
pthread_create(thread, NULL,
|
||||
(void *(*)(void *)) get_url_info_loop,
|
||||
(void *) connection);
|
||||
(void *(*)(void *))get_url_info_loop,
|
||||
(void *)connection);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
This Fucntion will retreive info about the given url in the connection,
|
||||
handling conditions like redirection from http to ftp etc
|
||||
This Fucntion will retreive info about the given url in the connection,
|
||||
handling conditions like redirection from http to ftp etc
|
||||
|
||||
*************************************************************************/
|
||||
*************************************************************************/
|
||||
void get_url_info_loop(connection_t * connection)
|
||||
{
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
/*TODO Should we try to make it broadcast a condition to the other threads? */
|
||||
@ -456,65 +451,66 @@ void get_url_info_loop(connection_t * connection)
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
|
||||
do
|
||||
{
|
||||
switch (connection->u.proto)
|
||||
{
|
||||
case URLHTTP:
|
||||
connection->err = http_get_url_info_loop(connection);
|
||||
break;
|
||||
case URLFTP:
|
||||
connection->err = ftp_get_url_info_loop(connection);
|
||||
break;
|
||||
default:
|
||||
proz_die(_("Error: unsupported protocol"));
|
||||
}
|
||||
switch (connection->u.proto)
|
||||
{
|
||||
case URLHTTP:
|
||||
connection->err = http_get_url_info_loop(connection);
|
||||
break;
|
||||
|
||||
if (connection->err == NEWLOCATION)
|
||||
{
|
||||
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);
|
||||
case URLFTP:
|
||||
connection->err = ftp_get_url_info_loop(connection);
|
||||
break;
|
||||
|
||||
proz_debug("Redirected to %s, merged URL = %s",
|
||||
connection->hs.newloc, constructed_newloc);
|
||||
default:
|
||||
proz_die(_("Error: unsupported protocol"));
|
||||
}
|
||||
|
||||
proz_free_url(&connection->u, 0);
|
||||
connection->err =
|
||||
proz_parse_url(constructed_newloc, &connection->u, 0);
|
||||
if (connection->err == NEWLOCATION)
|
||||
{
|
||||
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)
|
||||
{
|
||||
connection_show_message(connection,
|
||||
_
|
||||
("The server returned location is wrong: %s!"),
|
||||
constructed_newloc);
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
connection->running = FALSE;
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
kfree(constructed_newloc);
|
||||
connection->err = HERR;
|
||||
return;
|
||||
} else
|
||||
connection_show_message(connection, _("Redirected to => %s"),
|
||||
constructed_newloc);
|
||||
connection->u.referer=referer;
|
||||
kfree(constructed_newloc);
|
||||
connection->err = NEWLOCATION;
|
||||
}
|
||||
|
||||
}
|
||||
while (connection->err == NEWLOCATION);
|
||||
if (connection->err != URLOK)
|
||||
{
|
||||
connection_show_message(connection,
|
||||
_
|
||||
("The server returned location is wrong: %s!"),
|
||||
constructed_newloc);
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
connection->running = FALSE;
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
kfree(constructed_newloc);
|
||||
connection->err = HERR;
|
||||
return;
|
||||
}
|
||||
else
|
||||
connection_show_message(connection, _("Redirected to => %s"),
|
||||
constructed_newloc);
|
||||
connection->u.referer = referer;
|
||||
kfree(constructed_newloc);
|
||||
connection->err = NEWLOCATION;
|
||||
}
|
||||
} while (connection->err == NEWLOCATION);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
@ -535,16 +531,16 @@ void connection_calc_ratebps(connection_t * connection)
|
||||
|
||||
if (connection->time_begin.tv_sec == 0
|
||||
&& connection->time_begin.tv_usec == 0)
|
||||
{
|
||||
|
||||
connection->rate_bps = 0;
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
} else
|
||||
{
|
||||
gettimeofday(&tv_cur, NULL);
|
||||
proz_timeval_subtract(&tv_diff, &tv_cur, &(connection->time_begin));
|
||||
diff_us = ((float) tv_diff.tv_sec * 10e5) + tv_diff.tv_usec;
|
||||
{
|
||||
connection->rate_bps = 0;
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
gettimeofday(&tv_cur, NULL);
|
||||
proz_timeval_subtract(&tv_diff, &tv_cur, &(connection->time_begin));
|
||||
diff_us = ((float)tv_diff.tv_sec * 10e5) + tv_diff.tv_usec;
|
||||
|
||||
/* if (diff_us == 0) */
|
||||
/* { */
|
||||
@ -552,21 +548,21 @@ void connection_calc_ratebps(connection_t * connection)
|
||||
/* return; */
|
||||
/* } */
|
||||
/* connection->rate_bps = */
|
||||
/* ((float) (connection->remote_bytes_received */
|
||||
/* - (connection->remote_startpos-connection->orig_remote_startpos)) * 10e5 / diff_us); */
|
||||
/* ((float) (connection->remote_bytes_received */
|
||||
/* - (connection->remote_startpos-connection->orig_remote_startpos)) * 10e5 / diff_us); */
|
||||
/* } */
|
||||
|
||||
if (diff_us <100000)
|
||||
{
|
||||
connection->rate_bps = 0;
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
if (diff_us < 100000)
|
||||
{
|
||||
connection->rate_bps = 0;
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
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);
|
||||
return;
|
||||
@ -575,7 +571,6 @@ void connection_calc_ratebps(connection_t * connection)
|
||||
|
||||
void connection_throttle_bps(connection_t * connection)
|
||||
{
|
||||
|
||||
struct timeval tv_cur;
|
||||
struct timeval tv_diff;
|
||||
float diff_us;
|
||||
@ -586,93 +581,94 @@ void connection_throttle_bps(connection_t * connection)
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
|
||||
con_timeout_usecs =
|
||||
(connection->conn_timeout.tv_sec * 10e5) +
|
||||
connection->conn_timeout.tv_usec;
|
||||
(connection->conn_timeout.tv_sec * 10e5) +
|
||||
connection->conn_timeout.tv_usec;
|
||||
|
||||
if (connection->rate_bps == 0 || connection->max_allowed_bps == 0)
|
||||
{
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
}
|
||||
{
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (connection->time_begin.tv_sec == 0
|
||||
&& connection->time_begin.tv_usec == 0)
|
||||
{
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
}
|
||||
{
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
gettimeofday(&tv_cur, NULL);
|
||||
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)
|
||||
{
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
}
|
||||
{
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
wtime =
|
||||
10e5 * (connection->remote_bytes_received
|
||||
- (connection->remote_startpos-connection->orig_remote_startpos)) /
|
||||
connection->max_allowed_bps;
|
||||
10e5 * (connection->remote_bytes_received
|
||||
- (connection->remote_startpos - connection->orig_remote_startpos)) /
|
||||
connection->max_allowed_bps;
|
||||
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
|
||||
memset(&tv_delay, 0, sizeof(tv_delay));
|
||||
|
||||
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
|
||||
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;
|
||||
/*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
|
||||
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?
|
||||
If so no point in delaing beacuse the connection wold timeout
|
||||
*/
|
||||
/* 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 ((con_timeout_usecs - limit_time_us) <= 0)
|
||||
{
|
||||
proz_debug
|
||||
("Cant throttle: Connection would timeout if done so, please try increasing the timeout value");
|
||||
return;
|
||||
}
|
||||
if ((con_timeout_usecs - limit_time_us) <= 0)
|
||||
{
|
||||
proz_debug
|
||||
("Cant throttle: Connection would timeout if done so, please try increasing the timeout value");
|
||||
return;
|
||||
}
|
||||
|
||||
tv_delay.tv_usec = con_timeout_usecs - limit_time_us;
|
||||
/* message
|
||||
("Cant throttle fully : Connection would timeout if done so, please try increasing the timeout value"); */
|
||||
tv_delay.tv_usec = con_timeout_usecs - limit_time_us;
|
||||
/* message
|
||||
("Cant throttle fully : Connection would timeout if done so, please try increasing the timeout value"); */
|
||||
|
||||
proz_debug("delaymaxlimit %ld sec\n", tv_delay.tv_usec);
|
||||
} else
|
||||
{
|
||||
tv_delay.tv_usec = (wtime - diff_us);
|
||||
proz_debug("delaymaxlimit %ld sec\n", tv_delay.tv_usec);
|
||||
}
|
||||
else
|
||||
{
|
||||
tv_delay.tv_usec = (wtime - diff_us);
|
||||
//#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 running;
|
||||
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
running = connection->running;
|
||||
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)
|
||||
{
|
||||
assert(url);
|
||||
memcpy(&connection->u,
|
||||
proz_copy_url(url),
|
||||
sizeof(urlinfo));
|
||||
memcpy(&connection->u,
|
||||
proz_copy_url(url),
|
||||
sizeof(urlinfo));
|
||||
}
|
||||
|
||||
void proz_connection_free_connection(connection_t * connection,
|
||||
boolean complete)
|
||||
boolean complete)
|
||||
{
|
||||
assert(connection);
|
||||
/*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 */
|
||||
if (connection->serv_ret_lines != 0)
|
||||
{
|
||||
done_with_response(connection);
|
||||
}
|
||||
{
|
||||
done_with_response(connection);
|
||||
}
|
||||
|
||||
if (complete == TRUE)
|
||||
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 ret;
|
||||
|
||||
flockfile(connection->fp);
|
||||
/*Seek appropriately......*/
|
||||
|
||||
ret=fseeko(connection->fp, connection->local_startpos+connection->remote_bytes_received, SEEK_SET);
|
||||
ret=fwrite( ptr, size, nmemb, connection->fp);
|
||||
ret = fseeko(connection->fp, connection->local_startpos + connection->remote_bytes_received, SEEK_SET);
|
||||
ret = fwrite(ptr, size, nmemb, connection->fp);
|
||||
|
||||
funlockfile(connection->fp);
|
||||
return ret;
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Several connection-related routines. */
|
||||
|
||||
/* $Id: connection.h,v 1.34 2005/01/11 01:49:11 sean Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef CONNECTION_H
|
||||
@ -35,29 +35,29 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void init_response(connection_t * connection);
|
||||
void done_with_response(connection_t * connection);
|
||||
void connection_change_status(connection_t * connection,
|
||||
dl_status status);
|
||||
void init_response(connection_t * connection);
|
||||
void done_with_response(connection_t * connection);
|
||||
void connection_change_status(connection_t * connection,
|
||||
dl_status status);
|
||||
|
||||
|
||||
uerr_t connection_retr_fsize_not_known(connection_t * connection,
|
||||
char *read_buffer,
|
||||
int read_buffer_size);
|
||||
uerr_t connection_retr_fsize_not_known(connection_t * connection,
|
||||
char *read_buffer,
|
||||
int read_buffer_size);
|
||||
|
||||
uerr_t connection_retr_fsize_known(connection_t * connection,
|
||||
char *read_buffer,
|
||||
int read_buffer_size);
|
||||
int connection_load_resume_info(connection_t * connection);
|
||||
uerr_t connection_retr_fsize_known(connection_t * connection,
|
||||
char *read_buffer,
|
||||
int read_buffer_size);
|
||||
int connection_load_resume_info(connection_t * connection);
|
||||
|
||||
void connection_show_message(connection_t * connection,
|
||||
const char *format, ...);
|
||||
void connection_calc_ratebps(connection_t * connection);
|
||||
void connection_throttle_bps(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);
|
||||
void connection_show_message(connection_t * connection,
|
||||
const char *format, ...);
|
||||
void connection_calc_ratebps(connection_t * connection);
|
||||
void connection_throttle_bps(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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* CONNECTION_H */
|
||||
#endif /* CONNECTION_H */
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Debugging routines. */
|
||||
|
||||
/* $Id: debug.c,v 1.20 2001/08/17 21:53:39 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#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()
|
||||
{
|
||||
@ -43,28 +43,28 @@ void debug_init()
|
||||
|
||||
void proz_debug_delete_log()
|
||||
{
|
||||
|
||||
char logfile_name[PATH_MAX];
|
||||
|
||||
snprintf(logfile_name, PATH_MAX, "%s/debug.log", libprozrtinfo.log_dir);
|
||||
|
||||
|
||||
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, ...)
|
||||
{
|
||||
@ -73,41 +73,42 @@ void proz_debug(const char *format, ...)
|
||||
char message[MAX_MSG_SIZE + 1 + 1];
|
||||
|
||||
char logfile_name[PATH_MAX];
|
||||
|
||||
snprintf(logfile_name, PATH_MAX, "%s/debug.log", libprozrtinfo.log_dir);
|
||||
|
||||
|
||||
pthread_mutex_lock(&debug_mutex);
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&debug_mutex);
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Debugging routines. */
|
||||
|
||||
/* $Id: debug.h,v 1.14 2001/07/11 23:19:41 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef DEBUG_H
|
||||
@ -30,4 +30,4 @@
|
||||
|
||||
void debug_init();
|
||||
|
||||
#endif /* DEBUG_H */
|
||||
#endif /* DEBUG_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Download routines. */
|
||||
|
||||
/* $Id: download.h,v 1.25 2001/09/30 23:13:50 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef DOWNLOAD_H
|
||||
@ -35,17 +35,17 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void download_show_message(download_t * download, const char *format,
|
||||
...);
|
||||
int download_query_conns_status_count(download_t * download,
|
||||
dl_status status, char *server);
|
||||
void download_show_message(download_t * download, const char *format,
|
||||
...);
|
||||
int download_query_conns_status_count(download_t * download,
|
||||
dl_status status, char *server);
|
||||
|
||||
void download_join_downloads(download_t * download);
|
||||
void join_downloads(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_no_ftpsearch(download_t * download);
|
||||
void download_join_downloads(download_t * download);
|
||||
void join_downloads(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_no_ftpsearch(download_t * download);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* DOWNLOAD_H */
|
||||
#endif /* DOWNLOAD_H */
|
||||
|
@ -1,23 +1,23 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* $Id: ftp-retr.c,v 1.18 2005/01/11 01:49:11 sean Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#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 (connection->status == COMPLETED)
|
||||
{
|
||||
gettimeofday(&connection->time_begin, NULL);
|
||||
return FTPOK;
|
||||
}
|
||||
{
|
||||
gettimeofday(&connection->time_begin, NULL);
|
||||
return FTPOK;
|
||||
}
|
||||
|
||||
init_response(connection);
|
||||
|
||||
@ -74,34 +74,35 @@ uerr_t proz_ftp_get_file(connection_t * connection)
|
||||
*/
|
||||
if (ftp_use_proxy(connection)
|
||||
&& connection->ftp_proxy->type == HTTPPROXY)
|
||||
{
|
||||
err = ftp_get_file_from_http_proxy(connection);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
err = ftp_get_file_from_http_proxy(connection);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (ftp_use_proxy(connection))
|
||||
{
|
||||
/* Connect to the proxy server here. */
|
||||
err = ftp_connect_to_server(connection,
|
||||
connection->ftp_proxy->proxy_url.host,
|
||||
connection->ftp_proxy->proxy_url.port);
|
||||
} else
|
||||
{
|
||||
err = ftp_connect_to_server(connection, connection->u.host,
|
||||
connection->u.port);
|
||||
}
|
||||
{
|
||||
/* Connect to the proxy server here. */
|
||||
err = ftp_connect_to_server(connection,
|
||||
connection->ftp_proxy->proxy_url.host,
|
||||
connection->ftp_proxy->proxy_url.port);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = ftp_connect_to_server(connection, connection->u.host,
|
||||
connection->u.port);
|
||||
}
|
||||
|
||||
if (err == FTPCONREFUSED)
|
||||
{
|
||||
connection_change_status(connection, CONREJECT);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
connection_change_status(connection, CONREJECT);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
if (err != FTPOK)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
}
|
||||
|
||||
done_with_response(connection);
|
||||
|
||||
@ -110,15 +111,15 @@ uerr_t proz_ftp_get_file(connection_t * connection)
|
||||
|
||||
/* Use .netrc if asked to do so. */
|
||||
if (connection->use_netrc == TRUE)
|
||||
{
|
||||
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
|
||||
|
||||
if (netrc_ent != NULL)
|
||||
{
|
||||
user = netrc_ent->account;
|
||||
passwd = netrc_ent->password;
|
||||
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
|
||||
|
||||
if (netrc_ent != NULL)
|
||||
{
|
||||
user = netrc_ent->account;
|
||||
passwd = netrc_ent->password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user = user ? user : libprozrtinfo.ftp_default_user;
|
||||
passwd = passwd ? passwd : libprozrtinfo.ftp_default_passwd;
|
||||
@ -129,97 +130,100 @@ uerr_t proz_ftp_get_file(connection_t * connection)
|
||||
init_response(connection);
|
||||
err = ftp_login(connection, user, passwd);
|
||||
if (err != FTPOK)
|
||||
{
|
||||
if (err == FTPLOGREFUSED)
|
||||
{
|
||||
connection_change_status(connection, LOGINFAIL);
|
||||
} else
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
if (err == FTPLOGREFUSED)
|
||||
{
|
||||
connection_change_status(connection, LOGINFAIL);
|
||||
}
|
||||
else
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
}
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
done_with_response(connection);
|
||||
|
||||
|
||||
init_response(connection);
|
||||
err = ftp_binary(connection);
|
||||
if (err != FTPOK)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
done_with_response(connection);
|
||||
|
||||
/* Do we need to CWD? */
|
||||
if (*connection->u.dir)
|
||||
{
|
||||
init_response(connection);
|
||||
{
|
||||
init_response(connection);
|
||||
|
||||
err = ftp_cwd(connection, connection->u.dir);
|
||||
if (err != FTPOK)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
proz_debug(_("CWD failed to change to directory '%s'."),
|
||||
connection->u.dir);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
} else
|
||||
{
|
||||
proz_debug(_("CWD ok."));
|
||||
done_with_response(connection);
|
||||
err = ftp_cwd(connection, connection->u.dir);
|
||||
if (err != FTPOK)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
proz_debug(_("CWD failed to change to directory '%s'."),
|
||||
connection->u.dir);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
else
|
||||
{
|
||||
proz_debug(_("CWD ok."));
|
||||
done_with_response(connection);
|
||||
}
|
||||
}
|
||||
} else
|
||||
else
|
||||
proz_debug(_("CWD not needed."));
|
||||
|
||||
err = ftp_setup_data_sock_1(connection, &passive_mode);
|
||||
if (err != FTPOK)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* do we need to REST */
|
||||
if (connection->remote_startpos > 0
|
||||
&& connection->resume_support == TRUE)
|
||||
{
|
||||
err = ftp_rest(connection, connection->remote_startpos);
|
||||
}
|
||||
{
|
||||
err = ftp_rest(connection, connection->remote_startpos);
|
||||
}
|
||||
if (err != FTPOK)
|
||||
{
|
||||
if (err == FTPRESTFAIL)
|
||||
proz_debug
|
||||
(_
|
||||
("I have a bug in my code!!, check remote_starpos and resume_support values"));
|
||||
{
|
||||
if (err == FTPRESTFAIL)
|
||||
proz_debug
|
||||
(_
|
||||
("I have a bug in my code!!, check remote_starpos and resume_support values"));
|
||||
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
close_sock(&connection->ctrl_sock);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = ftp_retr(connection, connection->u.file);
|
||||
if (err != FTPOK)
|
||||
{
|
||||
proz_debug(_("RETR failed"));
|
||||
close_sock(&connection->ctrl_sock);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
proz_debug(_("RETR failed"));
|
||||
close_sock(&connection->ctrl_sock);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = ftp_setup_data_sock_2(connection, &passive_mode);
|
||||
if (err != FTPOK)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
/* which routine to call */
|
||||
if (connection->main_file_size == -1)
|
||||
err =
|
||||
connection_retr_fsize_not_known(connection, buffer,
|
||||
sizeof(buffer));
|
||||
connection_retr_fsize_not_known(connection, buffer,
|
||||
sizeof(buffer));
|
||||
else
|
||||
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
|
||||
this will handle all possible errors itself, retrying until the number
|
||||
of maximum tries for the connection is realised or a error occurs which
|
||||
needs to be passed upwards for handling, such as LOGINFAIL
|
||||
*/
|
||||
this will handle all possible errors itself, retrying until the number
|
||||
of maximum tries for the connection is realised or a error occurs which
|
||||
needs to be passed upwards for handling, such as LOGINFAIL
|
||||
*/
|
||||
|
||||
uerr_t ftp_loop(connection_t * connection)
|
||||
{
|
||||
@ -249,84 +253,82 @@ uerr_t ftp_loop(connection_t * connection)
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
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)
|
||||
{
|
||||
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 (connection->resume_support == TRUE)
|
||||
{
|
||||
if (connection_load_resume_info(connection) == -1)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (connection->resume_support == TRUE)
|
||||
{
|
||||
if (connection_load_resume_info(connection) == -1)
|
||||
{
|
||||
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 */
|
||||
pthread_cleanup_push(cleanup_socks, (void *) connection);
|
||||
/*Push the handler which will cleanup any sockets that are left open */
|
||||
pthread_cleanup_push(cleanup_socks, (void *)connection);
|
||||
|
||||
|
||||
connection->err = proz_ftp_get_file(connection);
|
||||
/*pop the handler */
|
||||
pthread_cleanup_pop(0);
|
||||
connection->err = proz_ftp_get_file(connection);
|
||||
/*pop the handler */
|
||||
pthread_cleanup_pop(0);
|
||||
|
||||
connection->attempts++;
|
||||
connection->attempts++;
|
||||
|
||||
/*Should the error be handled at this level ? */
|
||||
if (!ftp_loop_handle_error(connection->err))
|
||||
{
|
||||
return connection->err; /*If not return and the main thread will handle it */
|
||||
}
|
||||
/*Should the error be handled at this level ? */
|
||||
if (!ftp_loop_handle_error(connection->err))
|
||||
{
|
||||
return connection->err; /*If not return and the main thread will handle it */
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch (connection->err)
|
||||
{
|
||||
case FTPOK:
|
||||
connection_show_message(connection, _("Successfully got download"));
|
||||
return connection->err;
|
||||
break;
|
||||
switch (connection->err)
|
||||
{
|
||||
case FTPOK:
|
||||
connection_show_message(connection, _("Successfully got download"));
|
||||
return connection->err;
|
||||
break;
|
||||
|
||||
default:
|
||||
connection_show_message(connection,
|
||||
_("Error occured in connection..."));
|
||||
break;
|
||||
}
|
||||
retrying_from_loop = TRUE;
|
||||
}
|
||||
while ((connection->attempts < connection->max_attempts)
|
||||
|| connection->max_attempts == 0);
|
||||
default:
|
||||
connection_show_message(connection,
|
||||
_("Error occured in connection..."));
|
||||
break;
|
||||
}
|
||||
retrying_from_loop = TRUE;
|
||||
} while ((connection->attempts < connection->max_attempts)
|
||||
|| connection->max_attempts == 0);
|
||||
|
||||
|
||||
connection_show_message(connection,
|
||||
_
|
||||
("I have tried %d attempt(s) and have failed, aborting"),
|
||||
connection->attempts);
|
||||
_
|
||||
("I have tried %d attempt(s) and have failed, aborting"),
|
||||
connection->attempts);
|
||||
return connection->err;
|
||||
}
|
||||
|
||||
/*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
|
||||
restart it when necessary after processing other threads status too */
|
||||
or false if it should be passed upwards so that the main download thread can
|
||||
restart it when necessary after processing other threads status too */
|
||||
boolean ftp_loop_handle_error(uerr_t err)
|
||||
{
|
||||
|
||||
proz_debug("Error encountered in ftp_loop is %d", err);
|
||||
if (err == FTPNSFOD || err == FTPLOGREFUSED || err == FTPCONREFUSED
|
||||
|| err == FWRITEERR || err == FOPENERR || err == FTPCWDFAIL
|
||||
@ -334,5 +336,4 @@ boolean ftp_loop_handle_error(uerr_t err)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* $Id: ftp-retr.h,v 1.6 2001/06/25 12:30:55 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef FTP_RETR_H
|
||||
#define FTP_RETR_H
|
||||
@ -29,12 +29,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uerr_t proz_ftp_get_file(connection_t * connection);
|
||||
uerr_t ftp_loop(connection_t * connection);
|
||||
boolean ftp_loop_handle_error(uerr_t err);
|
||||
uerr_t ftp_get_file_from_http_proxy(connection_t * connection);
|
||||
uerr_t proz_ftp_get_file(connection_t * connection);
|
||||
uerr_t ftp_loop(connection_t * connection);
|
||||
boolean ftp_loop_handle_error(uerr_t err);
|
||||
uerr_t ftp_get_file_from_http_proxy(connection_t * connection);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* FTP_RETR_H */
|
||||
#endif /* FTP_RETR_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* FTP support. */
|
||||
|
||||
/* $Id: ftp.h,v 1.35 2005/09/04 00:06:50 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef FTP_H
|
||||
@ -34,44 +34,44 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ftp_check_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, ...);
|
||||
int ftp_check_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_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_binary(connection_t * connection);
|
||||
uerr_t ftp_port(connection_t * connection, const char *command);
|
||||
uerr_t ftp_list(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_rest(connection_t * connection, off_t bytes);
|
||||
uerr_t ftp_cwd(connection_t * connection, const 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_ascii(connection_t * connection);
|
||||
uerr_t ftp_binary(connection_t * connection);
|
||||
uerr_t ftp_port(connection_t * connection, const char *command);
|
||||
uerr_t ftp_list(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_rest(connection_t * connection, off_t bytes);
|
||||
uerr_t ftp_cwd(connection_t * connection, const 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_connect_to_server(connection_t * connection, const char *name,
|
||||
int port);
|
||||
uerr_t ftp_connect_to_server(connection_t * connection, const char *name,
|
||||
int port);
|
||||
|
||||
uerr_t ftp_get_listen_socket(connection_t * connection,
|
||||
int *listen_sock);
|
||||
uerr_t ftp_get_listen_socket(connection_t * connection,
|
||||
int *listen_sock);
|
||||
|
||||
uerr_t ftp_login(connection_t * connection, const char *username,
|
||||
const char *passwd);
|
||||
uerr_t ftp_login(connection_t * connection, const char *username,
|
||||
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,
|
||||
boolean * passive_mode);
|
||||
uerr_t ftp_setup_data_sock_2(connection_t * connection,
|
||||
boolean * passive_mode);
|
||||
uerr_t ftp_get_url_info_loop(connection_t * connection);
|
||||
uerr_t ftp_setup_data_sock_1(connection_t * connection,
|
||||
boolean * passive_mode);
|
||||
uerr_t ftp_setup_data_sock_2(connection_t * connection,
|
||||
boolean * passive_mode);
|
||||
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
|
||||
}
|
||||
#endif
|
||||
#endif /* FTP_H */
|
||||
#endif /* FTP_H */
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
//Rewrite of the ftp parsing code as we needed to extract the date of
|
||||
@ -28,22 +28,23 @@
|
||||
|
||||
|
||||
|
||||
/* MultiNet (some spaces removed from examples) */
|
||||
/* "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)" */
|
||||
/* and non-MutliNet VMS: */
|
||||
/* "CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)" */
|
||||
/* MultiNet (some spaces removed from examples) */
|
||||
/* "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)" */
|
||||
/* and non-MutliNet VMS: */
|
||||
/* "CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)" */
|
||||
|
||||
/* MSDOS format */
|
||||
/* 04-27-00 09:09PM <DIR> licensed */
|
||||
/* 07-18-00 10:16AM <DIR> pub */
|
||||
/* 04-14-00 03:47PM 589 readme.htm */
|
||||
/* MSDOS format */
|
||||
/* 04-27-00 09:09PM <DIR> licensed */
|
||||
/* 07-18-00 10:16AM <DIR> pub */
|
||||
/* 04-14-00 03:47PM 589 readme.htm */
|
||||
|
||||
|
||||
|
||||
long getlong(char *buf,int len)
|
||||
long getlong(char *buf, int len)
|
||||
{
|
||||
long u = 0;
|
||||
|
||||
while (len-- > 0)
|
||||
u = u * 10 + (*buf++ - '0');
|
||||
return u;
|
||||
@ -59,63 +60,82 @@ long getlong(char *buf,int len)
|
||||
** can optionally be quoted using <"> or "<" ">"
|
||||
** Comments surrrounded by '(' ')' are filtered out
|
||||
**
|
||||
** On exit,
|
||||
** On exit,
|
||||
** *pstr has been moved to the first delimiter past the
|
||||
** field
|
||||
** THE STRING HAS BEEN MUTILATED by a 0 terminator
|
||||
**
|
||||
** 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;
|
||||
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 */
|
||||
}
|
||||
char * start = NULL;
|
||||
|
||||
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 == '<') { /* 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 (!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 */
|
||||
{
|
||||
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 == '<') /* 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';
|
||||
*pstr = p;
|
||||
return start;
|
||||
if (*p)
|
||||
*p++ = '\0';
|
||||
*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 *token;
|
||||
char *ptr;
|
||||
char *date;
|
||||
int i;
|
||||
|
||||
fp->filename = 0;
|
||||
fp->namelen = 0;
|
||||
// fp->flagtrycwd = 0;
|
||||
@ -128,13 +148,14 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
|
||||
fp->id = 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);
|
||||
|
||||
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 'c':
|
||||
case 'd':
|
||||
@ -142,65 +163,71 @@ uerr_t ftp_parse(ftpparse *fp,char *buf,int len)
|
||||
case 'p':
|
||||
case 's':
|
||||
case '-':
|
||||
/* UNIX-style listing, without inum and without blocks */
|
||||
/* "-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 512 Apr 8 1994 etc" */
|
||||
/* "lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" */
|
||||
/* Also produced by Microsoft's FTP servers for Windows: */
|
||||
/* "---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z" */
|
||||
/* "d--------- 1 owner group 0 May 9 19:45 Softlib" */
|
||||
/* Also WFTPD for MSDOS: */
|
||||
/* "-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp" */
|
||||
/* Also NetWare: */
|
||||
/* "d [R----F--] supervisor 512 Jan 16 18:53 login" */
|
||||
/* "- [R----F--] rhesus 214059 Oct 20 15:27 cx.exe" */
|
||||
/* Also NetPresenz for the Mac: */
|
||||
/* "-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit" */
|
||||
/* "drwxrwxr-x folder 2 May 10 1996 network"
|
||||
/* UNIX-style listing, without inum and without blocks */
|
||||
/* "-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 512 Apr 8 1994 etc" */
|
||||
/* "lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" */
|
||||
/* Also produced by Microsoft's FTP servers for Windows: */
|
||||
/* "---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z" */
|
||||
/* "d--------- 1 owner group 0 May 9 19:45 Softlib" */
|
||||
/* Also WFTPD for MSDOS: */
|
||||
/* "-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp" */
|
||||
/* Also NetWare: */
|
||||
/* "d [R----F--] supervisor 512 Jan 16 18:53 login" */
|
||||
/* "- [R----F--] rhesus 214059 Oct 20 15:27 cx.exe" */
|
||||
/* Also NetPresenz for the Mac: */
|
||||
/* "-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit" */
|
||||
/* "drwxrwxr-x folder 2 May 10 1996 network"
|
||||
*/
|
||||
|
||||
if (*buf == 'd') fp->filetype = DIRECTORY;
|
||||
if (*buf == '-') fp->filetype = DIRECTORY;
|
||||
if (*buf == 'l') fp->filetype = SYMBOLIC_LINK;
|
||||
ptr=cp=strdup(buf);
|
||||
if (*buf == 'd')
|
||||
fp->filetype = DIRECTORY;
|
||||
if (*buf == '-')
|
||||
fp->filetype = DIRECTORY;
|
||||
if (*buf == 'l')
|
||||
fp->filetype = SYMBOLIC_LINK;
|
||||
ptr = cp = strdup(buf);
|
||||
|
||||
for (i=0;i<4;i++)
|
||||
{
|
||||
//add checking
|
||||
token= get_nextfield(&cp);
|
||||
if(token == NULL) //failed to parse
|
||||
return FTPPARSEFAIL;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
//add checking
|
||||
token = get_nextfield(&cp);
|
||||
if (token == NULL) //failed to parse
|
||||
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)
|
||||
{
|
||||
char * p;
|
||||
struct tm tm;
|
||||
time_t t;
|
||||
|
||||
char * p;
|
||||
struct tm tm;
|
||||
time_t t;
|
||||
|
||||
if (!str) return 0;
|
||||
|
||||
if ((p = strchr(str, ',')))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
if ((p = strchr(str, ',')))
|
||||
{
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* FTP LIST command parsing code. */
|
||||
|
||||
/* $Id: ftpparse.h,v 1.15 2005/08/06 17:07:35 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef FTPPARSE_H
|
||||
@ -41,13 +41,13 @@ typedef struct ftpparse {
|
||||
time_t mtime; /* modification time */
|
||||
file_type_t filetype;
|
||||
char *id; /* not necessarily 0-terminated */
|
||||
char *date_str;
|
||||
}ftpparse ;
|
||||
char *date_str;
|
||||
}ftpparse;
|
||||
|
||||
|
||||
uerr_t ftp_parse(ftpparse *fp,char *buf,int len);
|
||||
uerr_t ftp_parse(ftpparse *fp, char *buf, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* FTPPARSE_H */
|
||||
#endif /* FTPPARSE_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
@ -24,6 +24,6 @@
|
||||
|
||||
int ftpsearch_get_server_position(ftps_request_t * request, char *server);
|
||||
int ftpsearch_get_path_position(ftps_request_t * request, char *server,
|
||||
char *path);
|
||||
char *path);
|
||||
|
||||
#endif
|
||||
|
@ -1,23 +1,23 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* $Id: http-retr.c,v 1.20 2005/03/31 20:10:57 sean Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
#include "common.h"
|
||||
#include "prozilla.h"
|
||||
@ -36,7 +36,7 @@ uerr_t proz_http_get_file(connection_t * connection)
|
||||
uerr_t err;
|
||||
int remote_port_len;
|
||||
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;
|
||||
netrc_entry *netrc_ent;
|
||||
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 (connection->status == COMPLETED)
|
||||
{
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
gettimeofday(&connection->time_begin, NULL);
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return HOK;
|
||||
}
|
||||
{
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
gettimeofday(&connection->time_begin, NULL);
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return HOK;
|
||||
}
|
||||
|
||||
connection_change_status(connection, CONNECTING);
|
||||
|
||||
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->http_proxy->proxy_url.host);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
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->http_proxy->proxy_url.host);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
connection_show_message(connection, _("Connecting to %s"),
|
||||
connection->u.host);
|
||||
else
|
||||
{
|
||||
connection_show_message(connection, _("Connecting to %s"),
|
||||
connection->u.host);
|
||||
|
||||
err = connect_to_server(&connection->data_sock, connection->u.host,
|
||||
connection->u.port, &connection->xfer_timeout);
|
||||
if (err != NOCONERROR)
|
||||
{
|
||||
proz_debug(_("Error connecting to %s"), connection->u.host);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
err = connect_to_server(&connection->data_sock, connection->u.host,
|
||||
connection->u.port, &connection->xfer_timeout);
|
||||
if (err != NOCONERROR)
|
||||
{
|
||||
proz_debug(_("Error connecting to %s"), connection->u.host);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user = connection->u.user;
|
||||
passwd = connection->u.passwd;
|
||||
|
||||
/* Use .netrc if asked to do so. */
|
||||
if (connection->use_netrc == TRUE)
|
||||
{
|
||||
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
|
||||
|
||||
if (netrc_ent != NULL)
|
||||
{
|
||||
user = netrc_ent->account;
|
||||
passwd = netrc_ent->password;
|
||||
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
|
||||
|
||||
if (netrc_ent != NULL)
|
||||
{
|
||||
user = netrc_ent->account;
|
||||
passwd = netrc_ent->password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user = user ? user : "";
|
||||
passwd = passwd ? passwd : "";
|
||||
|
||||
if (strlen(user) || strlen(passwd))
|
||||
{
|
||||
/* Construct the necessary header. */
|
||||
www_auth = get_basic_auth_str(user, passwd, "Authorization");
|
||||
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
|
||||
proz_debug(_("Authentification string=%s"), www_auth);
|
||||
} else
|
||||
{
|
||||
/* Construct the necessary header. */
|
||||
www_auth = get_basic_auth_str(user, passwd, "Authorization");
|
||||
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
|
||||
proz_debug(_("Authentification string=%s"), www_auth);
|
||||
}
|
||||
else
|
||||
www_auth = 0;
|
||||
|
||||
if (http_use_proxy(connection))
|
||||
{
|
||||
if (strlen(connection->http_proxy->username)
|
||||
|| strlen(connection->http_proxy->passwd))
|
||||
proxy_auth =
|
||||
get_basic_auth_str(connection->http_proxy->username,
|
||||
connection->http_proxy->passwd,
|
||||
"Proxy-Authorization");
|
||||
}
|
||||
{
|
||||
if (strlen(connection->http_proxy->username)
|
||||
|| strlen(connection->http_proxy->passwd))
|
||||
proxy_auth =
|
||||
get_basic_auth_str(connection->http_proxy->username,
|
||||
connection->http_proxy->passwd,
|
||||
"Proxy-Authorization");
|
||||
}
|
||||
|
||||
if (connection->u.port == 80)
|
||||
{
|
||||
remote_port = NULL;
|
||||
remote_port_len = 0;
|
||||
} else
|
||||
{
|
||||
remote_port = (char *) alloca(64);
|
||||
remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
|
||||
}
|
||||
{
|
||||
remote_port = NULL;
|
||||
remote_port_len = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
remote_port = (char *)alloca(64);
|
||||
remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
|
||||
}
|
||||
|
||||
if (connection->hs.accept_ranges == 1)
|
||||
{
|
||||
range = (char *) alloca(18 + 64);
|
||||
sprintf(range, "Range: bytes=%lld-\r\n", connection->remote_startpos);
|
||||
proz_debug("Range = %lld Range = %s",connection->remote_startpos, range);
|
||||
}
|
||||
{
|
||||
range = (char *)alloca(18 + 64);
|
||||
sprintf(range, "Range: bytes=%lld-\r\n", connection->remote_startpos);
|
||||
proz_debug("Range = %lld Range = %s", connection->remote_startpos, range);
|
||||
}
|
||||
|
||||
if (connection->u.referer)
|
||||
{
|
||||
referer = (char *) alloca(13 + strlen(connection->u.referer));
|
||||
sprintf(referer, "Referer: %s\r\n", connection->u.referer);
|
||||
}
|
||||
{
|
||||
referer = (char *)alloca(13 + strlen(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 (http_use_proxy(connection))
|
||||
{
|
||||
location = (char *) alloca(strlen(connection->u.url) + 1);
|
||||
strcpy(location, connection->u.url);
|
||||
} else
|
||||
{
|
||||
location = (char *) alloca(strlen(connection->u.path) + 1);
|
||||
strcpy(location, connection->u.path);
|
||||
}
|
||||
{
|
||||
location = (char *)alloca(strlen(connection->u.url) + 1);
|
||||
strcpy(location, connection->u.url);
|
||||
}
|
||||
else
|
||||
{
|
||||
location = (char *)alloca(strlen(connection->u.path) + 1);
|
||||
strcpy(location, connection->u.path);
|
||||
}
|
||||
|
||||
/*Use no-cache directive for proxy servers? */
|
||||
if (http_use_proxy(connection)
|
||||
&& (connection->http_no_cache || connection->attempts > 0))
|
||||
{
|
||||
pragma_no_cache = (char *) alloca(21);
|
||||
sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
|
||||
}
|
||||
{
|
||||
pragma_no_cache = (char *)alloca(21);
|
||||
sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
|
||||
}
|
||||
|
||||
request = (char *) alloca(strlen(location)
|
||||
+ strlen(connection->user_agent)
|
||||
+ strlen(connection->u.host) + remote_port_len
|
||||
+ (range ? strlen(range) : 0)
|
||||
+ (referer ? strlen(referer) : 0)
|
||||
+ (www_auth ? strlen(www_auth) : 0)
|
||||
+ (proxy_auth ? strlen(proxy_auth) : 0)
|
||||
+ 64
|
||||
+
|
||||
(pragma_no_cache ? strlen(pragma_no_cache) :
|
||||
0));
|
||||
request = (char *)alloca(strlen(location)
|
||||
+ strlen(connection->user_agent)
|
||||
+ strlen(connection->u.host) + remote_port_len
|
||||
+ (range ? strlen(range) : 0)
|
||||
+ (referer ? strlen(referer) : 0)
|
||||
+ (www_auth ? strlen(www_auth) : 0)
|
||||
+ (proxy_auth ? strlen(proxy_auth) : 0)
|
||||
+ 64
|
||||
+
|
||||
(pragma_no_cache ? strlen(pragma_no_cache) :
|
||||
0));
|
||||
|
||||
/* TODO Add referrer tag. */
|
||||
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",
|
||||
location, connection->user_agent, connection->u.host,
|
||||
remote_port ? remote_port : "", range ? range : "",
|
||||
referer ? referer : "",
|
||||
www_auth ? www_auth : "", proxy_auth ? proxy_auth : "",
|
||||
pragma_no_cache ? pragma_no_cache : "");
|
||||
"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,
|
||||
remote_port ? remote_port : "", range ? range : "",
|
||||
referer ? referer : "",
|
||||
www_auth ? www_auth : "", proxy_auth ? proxy_auth : "",
|
||||
pragma_no_cache ? pragma_no_cache : "");
|
||||
|
||||
proz_debug("2 HTTP request = %s", request);
|
||||
|
||||
@ -201,41 +205,41 @@ uerr_t proz_http_get_file(connection_t * connection)
|
||||
|
||||
/* What hapenned ? */
|
||||
if (err != HOK)
|
||||
{
|
||||
proz_debug("2 http_fetch_headers err != HOK %d", err);
|
||||
/*Check if we authenticated using any user or password and if we
|
||||
were kicked out, if so return HAUTHFAIL */
|
||||
if (err == HAUTHREQ && (strlen(user) || strlen(passwd)))
|
||||
err = HAUTHFAIL;
|
||||
/*
|
||||
* a error occured druing the process
|
||||
*/
|
||||
close_sock(&connection->data_sock);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
proz_debug("2 http_fetch_headers err != HOK %d", err);
|
||||
/*Check if we authenticated using any user or password and if we
|
||||
were kicked out, if so return HAUTHFAIL */
|
||||
if (err == HAUTHREQ && (strlen(user) || strlen(passwd)))
|
||||
err = HAUTHFAIL;
|
||||
/*
|
||||
* a error occured druing the process
|
||||
*/
|
||||
close_sock(&connection->data_sock);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return err;
|
||||
}
|
||||
|
||||
/*Check for the server lying about it being able to handle ranges */
|
||||
if (hs_after_get.contlen != -1)
|
||||
{
|
||||
if (connection->resume_support == TRUE)
|
||||
{
|
||||
if (hs_after_get.contlen !=
|
||||
connection->main_file_size - connection->remote_startpos)
|
||||
{
|
||||
proz_debug("Error contlen does not match the requested range!");
|
||||
close_sock(&connection->data_sock);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return CANTRESUME;
|
||||
}
|
||||
if (connection->resume_support == TRUE)
|
||||
{
|
||||
if (hs_after_get.contlen !=
|
||||
connection->main_file_size - connection->remote_startpos)
|
||||
{
|
||||
proz_debug("Error contlen does not match the requested range!");
|
||||
close_sock(&connection->data_sock);
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return CANTRESUME;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* which routine to call */
|
||||
if (connection->main_file_size == -1)
|
||||
err =
|
||||
connection_retr_fsize_not_known(connection, buffer,
|
||||
sizeof(buffer));
|
||||
connection_retr_fsize_not_known(connection, buffer,
|
||||
sizeof(buffer));
|
||||
else
|
||||
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)
|
||||
return HOK;
|
||||
else
|
||||
{
|
||||
proz_debug("err != FILEGETOK %d", err);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
proz_debug("err != FILEGETOK %d", err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* A genuine loop ;) It willed be called by the main thread, and
|
||||
this will handle all possible errors itself, retrying until the number
|
||||
of maximum tries for the connection is realised
|
||||
*/
|
||||
this will handle all possible errors itself, retrying until the number
|
||||
of maximum tries for the connection is realised
|
||||
*/
|
||||
|
||||
uerr_t http_loop(connection_t * connection)
|
||||
{
|
||||
boolean retrying_from_loop = FALSE;
|
||||
|
||||
assert(connection->max_attempts >= 0);
|
||||
assert(connection->attempts >= 0);
|
||||
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
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)
|
||||
{
|
||||
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 (connection->resume_support == TRUE)
|
||||
{
|
||||
if (connection_load_resume_info(connection) == -1)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (connection->resume_support == TRUE)
|
||||
{
|
||||
if (connection_load_resume_info(connection) == -1)
|
||||
{
|
||||
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 */
|
||||
pthread_cleanup_push(cleanup_socks, (void *)connection);
|
||||
connection->err = proz_http_get_file(connection);
|
||||
/*pop the handler */
|
||||
pthread_cleanup_pop(0);
|
||||
|
||||
/*Push the handler which will cleanup any sockets that are left open */
|
||||
pthread_cleanup_push(cleanup_socks, (void *) connection);
|
||||
connection->err = proz_http_get_file(connection);
|
||||
/*pop the handler */
|
||||
pthread_cleanup_pop(0);
|
||||
connection->attempts++;
|
||||
|
||||
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 ? */
|
||||
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 */
|
||||
}
|
||||
switch (connection->err)
|
||||
{
|
||||
case HOK:
|
||||
connection_show_message(connection, _("Successfully got download"));
|
||||
return connection->err;
|
||||
break;
|
||||
|
||||
switch (connection->err)
|
||||
{
|
||||
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 */
|
||||
|
||||
/*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:
|
||||
connection_show_message(connection, proz_strerror(connection->err));
|
||||
break;
|
||||
}
|
||||
|
||||
retrying_from_loop = TRUE;
|
||||
|
||||
}
|
||||
while ((connection->attempts < connection->max_attempts)
|
||||
|| connection->max_attempts == 0);
|
||||
retrying_from_loop = TRUE;
|
||||
} while ((connection->attempts < connection->max_attempts)
|
||||
|| connection->max_attempts == 0);
|
||||
|
||||
|
||||
connection_show_message(connection,
|
||||
_
|
||||
("I have tried %d attempt(s) and have failed, aborting"),
|
||||
connection->attempts);
|
||||
_
|
||||
("I have tried %d attempt(s) and have failed, aborting"),
|
||||
connection->attempts);
|
||||
|
||||
return connection->err;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*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
|
||||
restart it when necessary after processing other threads status too */
|
||||
or false if it should be passed upwards so that the main download thread can
|
||||
restart it when necessary after processing other threads status too */
|
||||
boolean http_loop_handle_error(uerr_t 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
|
||||
MHO whoever thought of using HTTP to proxy FTP is a shithead,
|
||||
its such a PITA ;)
|
||||
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,
|
||||
its such a PITA ;)
|
||||
*/
|
||||
uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
|
||||
{
|
||||
|
||||
uerr_t err;
|
||||
int remote_port_len;
|
||||
char *user, *passwd, *www_auth = NULL, *proxy_auth = NULL, *range =
|
||||
NULL, *pragma_no_cache = NULL;
|
||||
NULL, *pragma_no_cache = NULL;
|
||||
|
||||
char *request, *remote_port;
|
||||
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 (connection->status == COMPLETED)
|
||||
{
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
gettimeofday(&connection->time_begin, NULL);
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return FTPOK;
|
||||
}
|
||||
{
|
||||
pthread_mutex_lock(&connection->access_mutex);
|
||||
gettimeofday(&connection->time_begin, NULL);
|
||||
pthread_mutex_unlock(&connection->access_mutex);
|
||||
return FTPOK;
|
||||
}
|
||||
|
||||
err = connect_to_server(&connection->data_sock,
|
||||
connection->ftp_proxy->proxy_url.host,
|
||||
connection->ftp_proxy->proxy_url.port,
|
||||
&connection->xfer_timeout);
|
||||
connection->ftp_proxy->proxy_url.host,
|
||||
connection->ftp_proxy->proxy_url.port,
|
||||
&connection->xfer_timeout);
|
||||
|
||||
if (err != NOCONERROR)
|
||||
{
|
||||
connection_show_message(connection, _("Error connecting to %s"),
|
||||
connection->ftp_proxy->proxy_url.host);
|
||||
return err;
|
||||
}
|
||||
{
|
||||
connection_show_message(connection, _("Error connecting to %s"),
|
||||
connection->ftp_proxy->proxy_url.host);
|
||||
return err;
|
||||
}
|
||||
|
||||
user = connection->u.user;
|
||||
passwd = connection->u.passwd;
|
||||
|
||||
/* Use .netrc if asked to do so. */
|
||||
if (connection->use_netrc == TRUE)
|
||||
{
|
||||
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
|
||||
|
||||
if (netrc_ent != NULL)
|
||||
{
|
||||
user = netrc_ent->account;
|
||||
passwd = netrc_ent->password;
|
||||
netrc_ent = search_netrc(libprozrtinfo.netrc_list, connection->u.host);
|
||||
|
||||
if (netrc_ent != NULL)
|
||||
{
|
||||
user = netrc_ent->account;
|
||||
passwd = netrc_ent->password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user = user ? user : "";
|
||||
passwd = passwd ? passwd : "";
|
||||
|
||||
if (strlen(user) || strlen(passwd))
|
||||
{
|
||||
/* Construct the necessary header. */
|
||||
www_auth = get_basic_auth_str(user, passwd, "Authorization");
|
||||
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
|
||||
proz_debug(_("Authentification string=%s"), www_auth);
|
||||
} else
|
||||
{
|
||||
/* Construct the necessary header. */
|
||||
www_auth = get_basic_auth_str(user, passwd, "Authorization");
|
||||
proz_debug(_("Authenticating as user %s password %s"), user, passwd);
|
||||
proz_debug(_("Authentification string=%s"), www_auth);
|
||||
}
|
||||
else
|
||||
www_auth = 0;
|
||||
|
||||
if (strlen(connection->ftp_proxy->username)
|
||||
|| strlen(connection->ftp_proxy->passwd))
|
||||
proxy_auth =
|
||||
get_basic_auth_str(connection->ftp_proxy->username,
|
||||
connection->ftp_proxy->passwd,
|
||||
"Proxy-Authorization");
|
||||
get_basic_auth_str(connection->ftp_proxy->username,
|
||||
connection->ftp_proxy->passwd,
|
||||
"Proxy-Authorization");
|
||||
|
||||
remote_port = (char *) alloca(64);
|
||||
remote_port = (char *)alloca(64);
|
||||
remote_port_len = sprintf(remote_port, ":%d", connection->u.port);
|
||||
|
||||
if (connection->hs.accept_ranges == 1)
|
||||
{
|
||||
range = (char *) alloca(18 + 64);
|
||||
sprintf(range, "Range: bytes=%lld-\r\n", connection->remote_startpos);
|
||||
}
|
||||
{
|
||||
range = (char *)alloca(18 + 64);
|
||||
sprintf(range, "Range: bytes=%lld-\r\n", connection->remote_startpos);
|
||||
}
|
||||
|
||||
|
||||
/*Use no-cache directive for proxy servers? */
|
||||
if (http_use_proxy(connection)
|
||||
&& (connection->http_no_cache || connection->attempts > 0))
|
||||
{
|
||||
pragma_no_cache = (char *) alloca(21);
|
||||
sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
|
||||
}
|
||||
{
|
||||
pragma_no_cache = (char *)alloca(21);
|
||||
sprintf(pragma_no_cache, "Pragma: no-cache\r\n");
|
||||
}
|
||||
|
||||
|
||||
/*Referrer TAG should not be needed in FTP through HTTP proxy..right */
|
||||
|
||||
|
||||
request = (char *) alloca(strlen(connection->u.url)
|
||||
+ strlen(connection->user_agent)
|
||||
+ strlen(connection->u.host) + remote_port_len
|
||||
+ (range ? strlen(range) : 0)
|
||||
+ (www_auth ? strlen(www_auth) : 0)
|
||||
+ (proxy_auth ? strlen(proxy_auth) : 0)
|
||||
+ 64
|
||||
+
|
||||
(pragma_no_cache ? strlen(pragma_no_cache) :
|
||||
0));
|
||||
request = (char *)alloca(strlen(connection->u.url)
|
||||
+ strlen(connection->user_agent)
|
||||
+ strlen(connection->u.host) + remote_port_len
|
||||
+ (range ? strlen(range) : 0)
|
||||
+ (www_auth ? strlen(www_auth) : 0)
|
||||
+ (proxy_auth ? strlen(proxy_auth) : 0)
|
||||
+ 64
|
||||
+
|
||||
(pragma_no_cache ? strlen(pragma_no_cache) :
|
||||
0));
|
||||
|
||||
|
||||
/* TODO Add referrer tag. */
|
||||
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",
|
||||
connection->u.url, connection->user_agent, connection->u.host,
|
||||
remote_port ? remote_port : "", range ? range : "",
|
||||
www_auth ? www_auth : "", proxy_auth ? proxy_auth : "",
|
||||
pragma_no_cache ? pragma_no_cache : "");
|
||||
"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,
|
||||
remote_port ? remote_port : "", range ? range : "",
|
||||
www_auth ? www_auth : "", proxy_auth ? proxy_auth : "",
|
||||
pragma_no_cache ? pragma_no_cache : "");
|
||||
|
||||
proz_debug("HTTP request = %s", request);
|
||||
|
||||
@ -484,39 +486,41 @@ uerr_t ftp_get_file_from_http_proxy(connection_t * connection)
|
||||
|
||||
|
||||
if (err == HAUTHREQ)
|
||||
{
|
||||
connection_change_status(connection, LOGINFAIL);
|
||||
return FTPLOGREFUSED;
|
||||
} else if (err == HTTPNSFOD)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return FTPNSFOD;
|
||||
} else if (err != HOK)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return FTPERR;
|
||||
}
|
||||
{
|
||||
connection_change_status(connection, LOGINFAIL);
|
||||
return FTPLOGREFUSED;
|
||||
}
|
||||
else if (err == HTTPNSFOD)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return FTPNSFOD;
|
||||
}
|
||||
else if (err != HOK)
|
||||
{
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return FTPERR;
|
||||
}
|
||||
|
||||
/*Check for the server lying about it being able to handle ranges */
|
||||
if (hs_after_get.contlen != -1)
|
||||
{
|
||||
if (connection->resume_support == TRUE)
|
||||
{
|
||||
if (hs_after_get.contlen !=
|
||||
connection->main_file_size - connection->remote_startpos)
|
||||
{
|
||||
proz_debug("Error contlen does not match the requested range!");
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return CANTRESUME;
|
||||
}
|
||||
if (connection->resume_support == TRUE)
|
||||
{
|
||||
if (hs_after_get.contlen !=
|
||||
connection->main_file_size - connection->remote_startpos)
|
||||
{
|
||||
proz_debug("Error contlen does not match the requested range!");
|
||||
connection_change_status(connection, REMOTEFATAL);
|
||||
return CANTRESUME;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* which routine to call */
|
||||
if (connection->main_file_size == -1)
|
||||
err =
|
||||
connection_retr_fsize_not_known(connection, buffer,
|
||||
sizeof(buffer));
|
||||
connection_retr_fsize_not_known(connection, buffer,
|
||||
sizeof(buffer));
|
||||
else
|
||||
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;
|
||||
else
|
||||
return err;
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* $Id: http-retr.h,v 1.5 2001/06/25 12:30:56 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef HTTP_RETR_H
|
||||
@ -30,10 +30,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uerr_t proz_http_get_file(connection_t * connection);
|
||||
uerr_t http_loop(connection_t * connection);
|
||||
boolean http_loop_handle_error(uerr_t err);
|
||||
uerr_t proz_http_get_file(connection_t * connection);
|
||||
uerr_t http_loop(connection_t * connection);
|
||||
boolean http_loop_handle_error(uerr_t err);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* FTP_RETR_H */
|
||||
#endif /* FTP_RETR_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* HTTP support. */
|
||||
|
||||
/* $Id: http.h,v 1.12 2005/03/31 20:10:57 sean Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef HTTP_H
|
||||
@ -34,27 +34,27 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int buf_readchar(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);
|
||||
int buf_readchar(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);
|
||||
|
||||
int hparsestatline(const char *hdr, const char **rp);
|
||||
int hskip_lws(const char *hdr);
|
||||
off_t hgetlen(const char *hdr);
|
||||
off_t hgetrange(const char *hdr);
|
||||
char *hgetlocation(const char *hdr);
|
||||
char *hgetmodified(const char *hdr);
|
||||
int hgetaccept_ranges(const char *hdr);
|
||||
int hparsestatline(const char *hdr, const char **rp);
|
||||
int hskip_lws(const char *hdr);
|
||||
off_t hgetlen(const char *hdr);
|
||||
off_t hgetrange(const char *hdr);
|
||||
char *hgetlocation(const char *hdr);
|
||||
char *hgetmodified(const char *hdr);
|
||||
int hgetaccept_ranges(const char *hdr);
|
||||
|
||||
uerr_t http_fetch_headers(connection_t * connection, http_stat_t * hs,
|
||||
char *command);
|
||||
uerr_t http_fetch_headers(connection_t * connection, http_stat_t * hs,
|
||||
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);
|
||||
uerr_t proz_http_get_url_info(connection_t * connection);
|
||||
uerr_t http_get_url_info_loop(connection_t * connection);
|
||||
boolean http_use_proxy(connection_t * connection);
|
||||
uerr_t proz_http_get_url_info(connection_t * connection);
|
||||
uerr_t http_get_url_info_loop(connection_t * connection);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* HTTP_H */
|
||||
#endif /* HTTP_H */
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
@ -26,7 +26,7 @@
|
||||
/*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,
|
||||
download_t * download)
|
||||
download_t * download)
|
||||
{
|
||||
char buffer[PATH_MAX];
|
||||
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
|
||||
*/
|
||||
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")))
|
||||
{
|
||||
|
||||
/*
|
||||
* fixme add the error displaing to the main function
|
||||
*/
|
||||
download_show_message(download,
|
||||
_("Error opening file %s for writing: %s"),
|
||||
buffer, strerror(errno));
|
||||
_("Error opening file %s for writing: %s"),
|
||||
buffer, strerror(errno));
|
||||
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))
|
||||
{
|
||||
download_show_message(download, _("Error writing to file %s: %s"),
|
||||
buffer, strerror(errno));
|
||||
buffer, strerror(errno));
|
||||
fclose(fp);
|
||||
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))
|
||||
{
|
||||
download_show_message(download, _("Error writing to file %s: %s"),
|
||||
buffer, strerror(errno));
|
||||
buffer, strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
@ -83,64 +82,58 @@ int log_create_logfile(int num_connections, int file_size, char *url,
|
||||
if (download != NULL)
|
||||
{
|
||||
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,
|
||||
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))
|
||||
if (fwrite
|
||||
(&download->pconnections[i]->local_startpos, 1,
|
||||
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;
|
||||
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]->remote_endpos, 1,
|
||||
sizeof(download->pconnections[i]->remote_endpos),
|
||||
fp) != sizeof(download->pconnections[i]->remote_endpos))
|
||||
{
|
||||
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);
|
||||
download_show_message(download, _("Error writing to file %s: %s"),
|
||||
buffer, strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
if (fwrite
|
||||
(&download->pconnections[i]->remote_endpos, 1,
|
||||
sizeof(download->pconnections[i]->remote_endpos),
|
||||
fp) != sizeof(download->pconnections[i]->remote_endpos))
|
||||
{
|
||||
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]->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);
|
||||
@ -158,16 +151,17 @@ int proz_log_logfile_exists(download_t * download)
|
||||
* Compute the name of the logfile
|
||||
*/
|
||||
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);
|
||||
if (ret == -1)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
} else
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -178,20 +172,21 @@ int proz_log_delete_logfile(download_t * download)
|
||||
int ret;
|
||||
|
||||
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);
|
||||
if (ret == -1)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
download_show_message(download, _("logfile doesn't exist"));
|
||||
return 1;
|
||||
} else
|
||||
{
|
||||
download_show_message(download, "Error: Unable to delete the logfile: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
download_show_message(download, _("logfile doesn't exist"));
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
download_show_message(download, "Error: Unable to delete the logfile: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -200,7 +195,7 @@ int proz_log_delete_logfile(download_t * download)
|
||||
/* Read the logfile into the logfile structure */
|
||||
|
||||
int proz_log_read_logfile(logfile * lf, download_t * download,
|
||||
boolean load_con_info)
|
||||
boolean load_con_info)
|
||||
{
|
||||
char buffer[PATH_MAX];
|
||||
FILE *fp = NULL;
|
||||
@ -210,7 +205,7 @@ int proz_log_read_logfile(logfile * lf, download_t * download,
|
||||
* Compute the name of the logfile
|
||||
*/
|
||||
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")))
|
||||
{
|
||||
@ -218,8 +213,8 @@ int proz_log_read_logfile(logfile * lf, download_t * download,
|
||||
* fixme add the error displaing to the main function
|
||||
*/
|
||||
download_show_message(download,
|
||||
_("Error opening file %s for reading: %s"),
|
||||
buffer, strerror(errno));
|
||||
_("Error opening file %s for reading: %s"),
|
||||
buffer, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -244,74 +239,69 @@ int proz_log_read_logfile(logfile * lf, download_t * download,
|
||||
if (load_con_info == TRUE)
|
||||
{
|
||||
for (i = 0; i < lf->num_connections; i++)
|
||||
{
|
||||
{
|
||||
proz_debug("value before= %d", download->pconnections[i]->local_startpos);
|
||||
|
||||
|
||||
|
||||
proz_debug("value before= %d", download->pconnections[i]->local_startpos);
|
||||
|
||||
if (fread
|
||||
(&download->pconnections[i]->local_startpos, 1,
|
||||
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,
|
||||
_("Error reading from file %s: %s"), buffer,
|
||||
strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
download_show_message(download,
|
||||
_("Error reading from file %s: %s"), buffer,
|
||||
strerror(errno));
|
||||
fclose(fp);
|
||||
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);
|
||||
if (fread
|
||||
(&download->pconnections[i]->orig_remote_startpos, 1,
|
||||
sizeof(download->pconnections[i]->orig_remote_startpos),
|
||||
fp) != sizeof(download->pconnections[i]->orig_remote_startpos))
|
||||
{
|
||||
download_show_message(download,
|
||||
_("Error reading from file %s: %s"), buffer,
|
||||
strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
proz_debug("orig_remote_startpos before= %d", download->pconnections[i]->orig_remote_startpos);
|
||||
if (fread
|
||||
(&download->pconnections[i]->orig_remote_startpos, 1,
|
||||
sizeof(download->pconnections[i]->orig_remote_startpos),
|
||||
fp) != sizeof(download->pconnections[i]->orig_remote_startpos))
|
||||
{
|
||||
download_show_message(download,
|
||||
_("Error reading from file %s: %s"), buffer,
|
||||
strerror(errno));
|
||||
fclose(fp);
|
||||
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);
|
||||
if (fread
|
||||
(&download->pconnections[i]->remote_endpos, 1,
|
||||
sizeof(download->pconnections[i]->remote_endpos),
|
||||
fp) != sizeof(download->pconnections[i]->remote_endpos))
|
||||
{
|
||||
download_show_message(download,
|
||||
_("Error reading from file %s: %s"), buffer,
|
||||
strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
proz_debug("remote_edndpos before= %d", download->pconnections[i]->remote_endpos);
|
||||
if (fread
|
||||
(&download->pconnections[i]->remote_endpos, 1,
|
||||
sizeof(download->pconnections[i]->remote_endpos),
|
||||
fp) != sizeof(download->pconnections[i]->remote_endpos))
|
||||
{
|
||||
download_show_message(download,
|
||||
_("Error reading from file %s: %s"), buffer,
|
||||
strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
proz_debug("remote_endpos after= %d", download->pconnections[i]->remote_endpos);
|
||||
proz_debug("remote_bytes_received before= %d", download->pconnections[i]->remote_bytes_received);
|
||||
if (fread
|
||||
(&download->pconnections[i]->remote_bytes_received, 1,
|
||||
sizeof(download->pconnections[i]->remote_bytes_received),
|
||||
fp) != sizeof(download->pconnections[i]->remote_bytes_received))
|
||||
{
|
||||
download_show_message(download,
|
||||
_("Error reading from file %s: %s"), buffer,
|
||||
strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
proz_debug("remote_bytes_received after= %d", download->pconnections[i]->remote_bytes_received);
|
||||
|
||||
}
|
||||
proz_debug("remote_endpos after= %d", download->pconnections[i]->remote_endpos);
|
||||
proz_debug("remote_bytes_received before= %d", download->pconnections[i]->remote_bytes_received);
|
||||
if (fread
|
||||
(&download->pconnections[i]->remote_bytes_received, 1,
|
||||
sizeof(download->pconnections[i]->remote_bytes_received),
|
||||
fp) != sizeof(download->pconnections[i]->remote_bytes_received))
|
||||
{
|
||||
download_show_message(download,
|
||||
_("Error reading from file %s: %s"), buffer,
|
||||
strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
proz_debug("remote_bytes_received after= %d", download->pconnections[i]->remote_bytes_received);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef LOGFILE_H
|
||||
@ -30,8 +30,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
int log_create_logfile(int num_connections, int file_size, char *url,
|
||||
download_t * download);
|
||||
int log_create_logfile(int num_connections, int file_size, char *url,
|
||||
download_t * download);
|
||||
|
||||
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* The main file. */
|
||||
@ -31,18 +31,18 @@
|
||||
|
||||
|
||||
/* static struct option long_opts[] = {
|
||||
// { name has_arg *flag val }
|
||||
{"no-netrc", no_argument, NULL, 'n'},
|
||||
{"use-port", no_argument, NULL, 129},
|
||||
{"libdebug", no_argument, NULL, 130},
|
||||
{NULL, 0, NULL, 0}
|
||||
};*/
|
||||
// { name has_arg *flag val }
|
||||
{"no-netrc", no_argument, NULL, 'n'},
|
||||
{"use-port", no_argument, NULL, 129},
|
||||
{"libdebug", no_argument, NULL, 130},
|
||||
{NULL, 0, NULL, 0}
|
||||
};*/
|
||||
|
||||
libprozinfo libprozrtinfo;
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
Initialize the library.
|
||||
Initialize the library.
|
||||
******************************************************************************/
|
||||
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. */
|
||||
/* while ((c = getopt_long(argc, argv, "", long_opts, NULL)) != EOF)
|
||||
{
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 129:
|
||||
@ -87,24 +87,26 @@ int proz_init(int argc, char **argv)
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
*/
|
||||
/* TODO Get home directory and read .netrc. */
|
||||
}
|
||||
*/
|
||||
/* TODO Get home directory and read .netrc. */
|
||||
|
||||
libprozrtinfo.home_dir = home_dir();
|
||||
|
||||
if (libprozrtinfo.home_dir != NULL)
|
||||
{
|
||||
char *netrc_file = kmalloc(strlen(libprozrtinfo.home_dir)
|
||||
+ strlen(".netrc") + 2);
|
||||
{
|
||||
char *netrc_file = kmalloc(strlen(libprozrtinfo.home_dir)
|
||||
+ 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);
|
||||
} else {
|
||||
/* Make sure home dir is never NULL */
|
||||
libprozrtinfo.home_dir = kstrdup(".");
|
||||
}
|
||||
libprozrtinfo.netrc_list = parse_netrc(netrc_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Make sure home dir is never NULL */
|
||||
libprozrtinfo.home_dir = kstrdup(".");
|
||||
}
|
||||
|
||||
libprozrtinfo.dl_dir = kstrdup(".");
|
||||
libprozrtinfo.output_dir = kstrdup(".");
|
||||
@ -114,7 +116,7 @@ int proz_init(int argc, char **argv)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
...
|
||||
...
|
||||
******************************************************************************/
|
||||
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, ...)
|
||||
{
|
||||
@ -144,7 +146,7 @@ void proz_die(const char *format, ...)
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
...
|
||||
...
|
||||
******************************************************************************/
|
||||
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)
|
||||
{
|
||||
@ -199,7 +201,6 @@ void proz_set_download_dir(char *dir)
|
||||
kfree(libprozrtinfo.dl_dir);
|
||||
|
||||
libprozrtinfo.dl_dir = kstrdup(dir);
|
||||
|
||||
}
|
||||
|
||||
void proz_set_logfile_dir(char *dir)
|
||||
@ -224,6 +225,5 @@ void proz_set_output_dir(char *dir)
|
||||
|
||||
char *proz_get_libprozilla_version()
|
||||
{
|
||||
|
||||
return strdup(VERSION);
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Miscellaneous routines. */
|
||||
|
||||
/* $Id: misc.c,v 1.32 2005/01/11 01:49:11 sean Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#include "common.h"
|
||||
@ -32,8 +32,8 @@ void cleanup_httpsocks(connection_t * connection);
|
||||
void cleanup_ftpsocks(connection_t * connection);
|
||||
|
||||
/******************************************************************************
|
||||
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.
|
||||
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.
|
||||
******************************************************************************/
|
||||
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)
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
@ -98,16 +98,16 @@ boolean is_number(const char *str)
|
||||
return FALSE;
|
||||
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (!isdigit(str[i]))
|
||||
return FALSE;
|
||||
i++;
|
||||
}
|
||||
{
|
||||
if (!isdigit(str[i]))
|
||||
return FALSE;
|
||||
i++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
How many digits are in a long integer?
|
||||
How many digits are in a long integer?
|
||||
******************************************************************************/
|
||||
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
|
||||
char after the last char) to a new, malloc()-ed location. 0-terminate it.
|
||||
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 *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
|
||||
reverse order (the least significant digit first), and are then reversed.
|
||||
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.
|
||||
******************************************************************************/
|
||||
void prnum(char *where, long num)
|
||||
{
|
||||
@ -144,63 +144,64 @@ void prnum(char *where, long num)
|
||||
char c;
|
||||
|
||||
if (num < 0)
|
||||
{
|
||||
*where++ = '-';
|
||||
num = -num;
|
||||
}
|
||||
{
|
||||
*where++ = '-';
|
||||
num = -num;
|
||||
}
|
||||
|
||||
p = where;
|
||||
|
||||
/* Print the digits to the string. */
|
||||
do
|
||||
{
|
||||
*p++ = num % 10 + '0';
|
||||
num /= 10;
|
||||
}
|
||||
while (num);
|
||||
{
|
||||
*p++ = num % 10 + '0';
|
||||
num /= 10;
|
||||
} while (num);
|
||||
|
||||
/* And reverse them. */
|
||||
l = p - where - 1;
|
||||
for (i = l / 2; i >= 0; i--)
|
||||
{
|
||||
c = where[i];
|
||||
where[i] = where[l - i];
|
||||
where[l - i] = c;
|
||||
}
|
||||
{
|
||||
c = where[i];
|
||||
where[i] = where[l - i];
|
||||
where[l - i] = c;
|
||||
}
|
||||
where[l + 1] = '\0';
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
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
|
||||
argument etc).
|
||||
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
|
||||
argument etc).
|
||||
******************************************************************************/
|
||||
int setargval(char *optstr, int *num)
|
||||
{
|
||||
if (*optstr == '=')
|
||||
{
|
||||
if (is_number(optstr + 1))
|
||||
{
|
||||
*num = atoi(optstr + 1);
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
} else
|
||||
{
|
||||
if (is_number(optstr))
|
||||
if (is_number(optstr + 1))
|
||||
{
|
||||
*num = atoi(optstr + 1);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*num = atoi(optstr);
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_number(optstr))
|
||||
{
|
||||
*num = atoi(optstr);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
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
|
||||
1+BASE64_LENGTH(length) bytes. Note: Routine stolen from wget (grendel).
|
||||
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
|
||||
1+BASE64_LENGTH(length) bytes. Note: Routine stolen from wget (grendel).
|
||||
******************************************************************************/
|
||||
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;
|
||||
unsigned char *p = (unsigned char *) store;
|
||||
unsigned char *p = (unsigned char *)store;
|
||||
|
||||
/* Transform the 3x8 bits to 4x6 bits, as required by base64. */
|
||||
for (i = 0; i < length; i += 3)
|
||||
{
|
||||
*p++ = tbl[s[0] >> 2];
|
||||
*p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];
|
||||
*p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];
|
||||
*p++ = tbl[s[2] & 0x3f];
|
||||
s += 3;
|
||||
}
|
||||
{
|
||||
*p++ = tbl[s[0] >> 2];
|
||||
*p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];
|
||||
*p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];
|
||||
*p++ = tbl[s[2] & 0x3f];
|
||||
s += 3;
|
||||
}
|
||||
|
||||
/* Pad the result if necessary... */
|
||||
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 = getenv("HOME");
|
||||
|
||||
if (home == NULL)
|
||||
{
|
||||
/* If $HOME is not defined, try getting it from the passwd file. */
|
||||
struct passwd *pwd = getpwuid(getuid());
|
||||
if (!pwd || !pwd->pw_dir)
|
||||
return NULL;
|
||||
home = pwd->pw_dir;
|
||||
}
|
||||
{
|
||||
/* If $HOME is not defined, try getting it from the passwd file. */
|
||||
struct passwd *pwd = getpwuid(getuid());
|
||||
if (!pwd || !pwd->pw_dir)
|
||||
return NULL;
|
||||
home = pwd->pw_dir;
|
||||
}
|
||||
|
||||
return home ? kstrdup(home) : NULL;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
Subtract the `struct timeval' values X and Y, storing the result in RESULT.
|
||||
Return 1 if the difference is negative, otherwise 0.
|
||||
Subtract the `struct timeval' values X and Y, storing the result in RESULT.
|
||||
Return 1 if the difference is negative, otherwise 0.
|
||||
******************************************************************************/
|
||||
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. */
|
||||
if (x->tv_usec < y->tv_usec)
|
||||
{
|
||||
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
||||
y->tv_usec -= 1000000 * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
{
|
||||
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
||||
y->tv_usec -= 1000000 * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
|
||||
if (x->tv_usec - y->tv_usec > 1000000)
|
||||
{
|
||||
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
|
||||
y->tv_usec += 1000000 * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
{
|
||||
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
|
||||
y->tv_usec += 1000000 * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait. `tv_usec' is certainly positive. */
|
||||
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)
|
||||
{
|
||||
@ -300,7 +300,7 @@ void delay_ms(int ms)
|
||||
tv_delay.tv_sec = ms / 1000;
|
||||
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"));
|
||||
}
|
||||
|
||||
@ -308,8 +308,8 @@ void delay_ms(int ms)
|
||||
/*Closes a socket and zeroes the socket before returning */
|
||||
int close_sock(int *sock)
|
||||
{
|
||||
|
||||
int retval = close(*sock);
|
||||
|
||||
*sock = 0;
|
||||
return retval;
|
||||
}
|
||||
@ -318,158 +318,198 @@ int close_sock(int *sock)
|
||||
|
||||
char *proz_strerror(uerr_t error)
|
||||
{
|
||||
|
||||
switch (error)
|
||||
{
|
||||
{
|
||||
case HOSTERR:
|
||||
return _("Unable to lookup hostname");
|
||||
|
||||
case HOSTERR:
|
||||
return _("Unable to lookup hostname");
|
||||
case CONSOCKERR:
|
||||
return _("Unable to create socket");
|
||||
case CONERROR:
|
||||
return _("Error occured while connecting");
|
||||
case CONREFUSED:
|
||||
return _("The connection attempt was refused");
|
||||
case ACCEPTERR:
|
||||
return _("Error while accepting the connection");
|
||||
case BINDERR:
|
||||
return _("Error while Binding socket");
|
||||
case LISTENERR:
|
||||
return _("Error while listening");
|
||||
case SERVERCLOSECONERR:
|
||||
return _("The connection was reset/closed by the peer");
|
||||
case URLUNKNOWN:
|
||||
return _("The URL Protocol was unknown");
|
||||
case URLBADPORT:
|
||||
return _("The port specified in the URL is not valid!");
|
||||
case URLBADHOST:
|
||||
return _("The Hostname specified in the URL is not valid!");
|
||||
case URLBADPATTERN:
|
||||
return _("The Pattern specified in the URL does not look valid!");
|
||||
case HEOF:
|
||||
return _("End of file reached in HTTP connection");
|
||||
case HERR:
|
||||
return _("Error occured in HTTP data transfer");
|
||||
case HAUTHREQ:
|
||||
return _("Authentification is required to access this resource");
|
||||
case HAUTHFAIL:
|
||||
return _("Failed to Authenticate with host!");
|
||||
case HTTPNSFOD:
|
||||
return _("The URL was not found on the host!");
|
||||
case FTPLOGREFUSED:
|
||||
return _("The host disallowed the login attempt");
|
||||
case FTPPORTERR:
|
||||
return _("The PORT request was rejected by the server");
|
||||
case FTPNSFOD:
|
||||
return _("The object file/dir was not found on the host!");
|
||||
case FTPUNKNOWNTYPE:
|
||||
return _("The TYPE specified in not known by the FTP server!");
|
||||
case FTPUNKNOWNCMD:
|
||||
return _("The command is not known by the FTP server!");
|
||||
case FTPSIZEFAIL:
|
||||
return _("The SIZE command failed");
|
||||
case FTPERR:
|
||||
return _("Error occured in FTP data transfer");
|
||||
case FTPRESTFAIL:
|
||||
return _("The REST command failed");
|
||||
case FTPACCDENIED:
|
||||
return _("The peer did not allow access");
|
||||
case FTPPWDERR:
|
||||
return _("The host rejected the password");
|
||||
case FTPPWDFAIL:
|
||||
return _("The host rejected the password");
|
||||
case FTPINVPASV:
|
||||
return _("The PASV (passive mode) was not supported the host");
|
||||
case FTPNOPASV:
|
||||
return _("The host does not support PASV (passive mode) transfers");
|
||||
case FTPCONREFUSED:
|
||||
return _("The connection attempt was refused");
|
||||
case FTPCWDFAIL:
|
||||
return _("Failed to (CWD)change to the directory");
|
||||
case FTPSERVCLOSEDATLOGIN:
|
||||
return
|
||||
_
|
||||
("The host said the requested service was unavailable and closed the control connection");
|
||||
case CONPORTERR:
|
||||
return _("getsockname failed!");
|
||||
case CONSOCKERR:
|
||||
return _("Unable to create socket");
|
||||
|
||||
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 CONERROR:
|
||||
return _("Error occured while connecting");
|
||||
|
||||
case SERVICEUNAVAIL:
|
||||
return
|
||||
_
|
||||
("The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.");
|
||||
case CONREFUSED:
|
||||
return _("The connection attempt was refused");
|
||||
|
||||
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 ACCEPTERR:
|
||||
return _("Error while accepting the connection");
|
||||
|
||||
case INTERNALSERVERR:
|
||||
return
|
||||
_
|
||||
("The server encountered an unexpected condition which prevented it from fulfilling the request.");
|
||||
case BINDERR:
|
||||
return _("Error while Binding socket");
|
||||
|
||||
case UNKNOWNREQ:
|
||||
return
|
||||
_
|
||||
("The server does not support the functionality required to fulfill the request.");
|
||||
case LISTENERR:
|
||||
return _("Error while listening");
|
||||
|
||||
case FOPENERR:
|
||||
return _("Error while opening file");
|
||||
case FWRITEERR:
|
||||
return _("Error while writing to file");
|
||||
case SERVERCLOSECONERR:
|
||||
return _("The connection was reset/closed by the peer");
|
||||
|
||||
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");
|
||||
case URLUNKNOWN:
|
||||
return _("The URL Protocol was unknown");
|
||||
|
||||
default:
|
||||
return _("Unknown/Unsupported error code");
|
||||
}
|
||||
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:
|
||||
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
|
||||
*/
|
||||
*/
|
||||
#include "ftp.h"
|
||||
|
||||
void cleanup_socks(void *cdata)
|
||||
{
|
||||
connection_t *connection = (connection_t *) cdata;
|
||||
connection_t *connection = (connection_t *)cdata;
|
||||
|
||||
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
|
||||
if we are going through a http proxy */
|
||||
case URLHTTP:
|
||||
cleanup_httpsocks(connection);
|
||||
} else
|
||||
cleanup_ftpsocks(connection);
|
||||
break;
|
||||
default:
|
||||
proz_die(_("Error: unsupported protocol"));
|
||||
}
|
||||
break;
|
||||
|
||||
case URLFTP:
|
||||
if (ftp_use_proxy(connection)
|
||||
&& 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)
|
||||
{
|
||||
flags = fcntl(connection->data_sock, F_GETFD, 0);
|
||||
if (flags == -1)
|
||||
{
|
||||
proz_debug("data sock invalid\n");
|
||||
} else
|
||||
close_sock(&connection->data_sock);
|
||||
}
|
||||
flags = fcntl(connection->data_sock, F_GETFD, 0);
|
||||
if (flags == -1)
|
||||
{
|
||||
proz_debug("data sock invalid\n");
|
||||
}
|
||||
else
|
||||
close_sock(&connection->data_sock);
|
||||
}
|
||||
|
||||
if (connection->ctrl_sock > 0)
|
||||
{
|
||||
flags = fcntl(connection->ctrl_sock, F_GETFD, 0);
|
||||
if (flags == -1)
|
||||
{
|
||||
proz_debug("control sock invalid\n");
|
||||
} else
|
||||
close_sock(&connection->ctrl_sock);
|
||||
}
|
||||
|
||||
flags = fcntl(connection->ctrl_sock, F_GETFD, 0);
|
||||
if (flags == -1)
|
||||
{
|
||||
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");
|
||||
|
||||
if (connection->data_sock > 0)
|
||||
{
|
||||
flags = fcntl(connection->data_sock, F_GETFD, 0);
|
||||
if (flags == -1)
|
||||
{
|
||||
proz_debug("sock invalid\n");
|
||||
} else
|
||||
close(connection->data_sock);
|
||||
}
|
||||
|
||||
flags = fcntl(connection->data_sock, F_GETFD, 0);
|
||||
if (flags == -1)
|
||||
{
|
||||
proz_debug("sock invalid\n");
|
||||
}
|
||||
else
|
||||
close(connection->data_sock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Miscellaneous routines. */
|
||||
|
||||
/* $Id: misc.h,v 1.25 2001/09/02 23:29:16 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef MISC_H
|
||||
@ -46,4 +46,4 @@ char *home_dir(void);
|
||||
void delay_ms(int ms);
|
||||
int close_sock(int *sock);
|
||||
void cleanup_socks(void *cdata);
|
||||
#endif /* MISC_H */
|
||||
#endif /* MISC_H */
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
/* Slightly modified for libprozilla, by Grendel <kalum@delrom.ro>. */
|
||||
|
||||
/* $Id: netrc.c,v 1.17 2001/08/09 23:35:26 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#include "common.h"
|
||||
@ -29,35 +29,37 @@
|
||||
#define POPBUFSIZE BUFSIZ
|
||||
|
||||
/******************************************************************************
|
||||
Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is
|
||||
set to a ready-to-use netrc_entry, in any event.
|
||||
Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is
|
||||
set to a ready-to-use netrc_entry, in any event.
|
||||
******************************************************************************/
|
||||
static void maybe_add_to_list(netrc_entry ** newentry, netrc_entry ** list)
|
||||
{
|
||||
netrc_entry *a, *l;
|
||||
|
||||
a = *newentry;
|
||||
l = *list;
|
||||
|
||||
/* We need an account name in order to add the entry to the list. */
|
||||
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. */
|
||||
a->next = l;
|
||||
l = a;
|
||||
/* 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. */
|
||||
a->next = l;
|
||||
l = a;
|
||||
}
|
||||
|
||||
/* Allocate a new netrc_entry structure. */
|
||||
a = kmalloc(sizeof(netrc_entry));
|
||||
}
|
||||
/* Allocate a new netrc_entry structure. */
|
||||
a = kmalloc(sizeof(netrc_entry));
|
||||
}
|
||||
|
||||
/* Zero the structure, so that it is ready to use. */
|
||||
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
|
||||
entries. NULL is returned if the file could not be parsed.
|
||||
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.
|
||||
******************************************************************************/
|
||||
netrc_entry *parse_netrc(char *file)
|
||||
{
|
||||
@ -90,10 +92,10 @@ netrc_entry *parse_netrc(char *file)
|
||||
|
||||
fp = fopen(file, "r");
|
||||
if (!fp)
|
||||
{
|
||||
/* Just return NULL if we can't open the file. */
|
||||
return NULL;
|
||||
}
|
||||
{
|
||||
/* Just return NULL if we can't open the file. */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize the file data. */
|
||||
ln = 0;
|
||||
@ -101,151 +103,153 @@ netrc_entry *parse_netrc(char *file)
|
||||
|
||||
/* While there are lines in the file... */
|
||||
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)
|
||||
last_token = tok_nothing; /* End of macro. */
|
||||
else
|
||||
continue; /* Otherwise ignore it. */
|
||||
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)
|
||||
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(¤t, &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(¤t, &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(¤t, &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(¤t, &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);
|
||||
|
||||
/* Finalize the last machine entry we found. */
|
||||
@ -256,37 +260,37 @@ netrc_entry *parse_netrc(char *file)
|
||||
current = retval;
|
||||
retval = NULL;
|
||||
while (current)
|
||||
{
|
||||
netrc_entry *saved_reference;
|
||||
{
|
||||
netrc_entry *saved_reference;
|
||||
|
||||
/* Change the direction of the pointers. */
|
||||
saved_reference = current->next;
|
||||
current->next = retval;
|
||||
/* Change the direction of the pointers. */
|
||||
saved_reference = current->next;
|
||||
current->next = retval;
|
||||
|
||||
/* Advance to the next node. */
|
||||
retval = current;
|
||||
current = saved_reference;
|
||||
}
|
||||
/* Advance to the next node. */
|
||||
retval = current;
|
||||
current = saved_reference;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
Return the netrc entry from LIST corresponding to HOST. NULL is returned if
|
||||
no such entry exists.
|
||||
Return the netrc entry from LIST corresponding to HOST. NULL is returned if
|
||||
no such entry exists.
|
||||
******************************************************************************/
|
||||
netrc_entry *search_netrc(netrc_entry * list, const char *host)
|
||||
{
|
||||
/* Look for the HOST in LIST. */
|
||||
while (list)
|
||||
{
|
||||
if (!list->host)
|
||||
break; /* We hit the default entry. */
|
||||
else if (!strcmp(list->host, host))
|
||||
break; /* We found a matching entry. */
|
||||
{
|
||||
if (!list->host)
|
||||
break; /* We hit the default entry. */
|
||||
else if (!strcmp(list->host, host))
|
||||
break; /* We found a matching entry. */
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
/* Return the matching entry, or NULL. */
|
||||
return list;
|
||||
|
@ -16,7 +16,7 @@
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
/* $Id: netrc.h,v 1.11 2001/05/30 15:01:40 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef NETRC_H
|
||||
@ -33,8 +33,8 @@
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
#else
|
||||
# define __BEGIN_DECLS /* Empty. */
|
||||
# define __END_DECLS /* Empty. */
|
||||
# define __BEGIN_DECLS /* Empty. */
|
||||
# define __END_DECLS /* Empty. */
|
||||
#endif
|
||||
|
||||
#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));
|
||||
|
||||
__END_DECLS
|
||||
#endif /* NETRC_H */
|
||||
#endif /* NETRC_H */
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
@ -40,9 +40,9 @@ uerr_t tcp_ping(ping_t * ping_data)
|
||||
struct timeval end_time;
|
||||
char ping_buf[TCP_PING_PACKSIZE];
|
||||
int bytes_read;
|
||||
struct addrinfo hints, *res=NULL;
|
||||
char szPort[10];
|
||||
int error;
|
||||
struct addrinfo hints, *res = NULL;
|
||||
char szPort[10];
|
||||
int error;
|
||||
|
||||
assert(ping_data->host);
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
@ -51,16 +51,17 @@ uerr_t tcp_ping(ping_t * ping_data)
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
error = getaddrinfo(ping_data->host, szPort, &hints, &res);
|
||||
if (error) {
|
||||
error = getaddrinfo(ping_data->host, szPort, &hints, &res);
|
||||
if (error)
|
||||
{
|
||||
return ping_data->err = HOSTERR;
|
||||
}
|
||||
}
|
||||
|
||||
if ((ping_data->sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1)
|
||||
{
|
||||
free(res);
|
||||
return ping_data->err = CONSOCKERR;
|
||||
}
|
||||
if ((ping_data->sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1)
|
||||
{
|
||||
free(res);
|
||||
return ping_data->err = CONSOCKERR;
|
||||
}
|
||||
|
||||
/* Experimental. */
|
||||
flags = fcntl(ping_data->sock, F_GETFL, 0);
|
||||
@ -73,62 +74,66 @@ uerr_t tcp_ping(ping_t * ping_data)
|
||||
gettimeofday(&start_time, 0);
|
||||
|
||||
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))
|
||||
{
|
||||
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
|
||||
(ping_data->sock, SOL_SOCKET, SO_ERROR, &status, &arglen) < 0)
|
||||
status = errno;
|
||||
FD_ZERO(&writefd);
|
||||
FD_SET(ping_data->sock, &writefd);
|
||||
|
||||
if (status != 0)
|
||||
errno = status, status = -1;
|
||||
status =
|
||||
select((ping_data->sock + 1), NULL, &writefd, NULL,
|
||||
&ping_data->timeout);
|
||||
|
||||
if (errno == EINPROGRESS)
|
||||
errno = ETIMEDOUT;
|
||||
} else if (status == 0)
|
||||
errno = ETIMEDOUT, status = -1;
|
||||
}
|
||||
/* Do we need to retry if the err is EINTR? */
|
||||
|
||||
if (status > 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
close_sock(&ping_data->sock);
|
||||
{
|
||||
close_sock(&ping_data->sock);
|
||||
|
||||
if (errno == ECONNREFUSED)
|
||||
{
|
||||
free(res);
|
||||
return ping_data->err = CONREFUSED;
|
||||
} else if (errno == ETIMEDOUT)
|
||||
{
|
||||
free(res);
|
||||
return ping_data->err = PINGTIMEOUT;
|
||||
} else
|
||||
{
|
||||
free(res);
|
||||
return ping_data->err = CONERROR;
|
||||
if (errno == ECONNREFUSED)
|
||||
{
|
||||
free(res);
|
||||
return ping_data->err = CONREFUSED;
|
||||
}
|
||||
else if (errno == ETIMEDOUT)
|
||||
{
|
||||
free(res);
|
||||
return ping_data->err = PINGTIMEOUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(res);
|
||||
return ping_data->err = CONERROR;
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
flags = fcntl(ping_data->sock, F_GETFL, 0);
|
||||
else
|
||||
{
|
||||
flags = fcntl(ping_data->sock, F_GETFL, 0);
|
||||
|
||||
if (flags != -1)
|
||||
fcntl(ping_data->sock, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
if (flags != -1)
|
||||
fcntl(ping_data->sock, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
|
||||
/* setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&opt,
|
||||
(int) sizeof(opt)); */
|
||||
@ -139,18 +144,18 @@ uerr_t tcp_ping(ping_t * ping_data)
|
||||
/*So far so good connection established */
|
||||
|
||||
bytes_read =
|
||||
krecv(ping_data->sock, ping_buf, TCP_PING_PACKSIZE, 0,
|
||||
&ping_data->timeout);
|
||||
krecv(ping_data->sock, ping_buf, TCP_PING_PACKSIZE, 0,
|
||||
&ping_data->timeout);
|
||||
close_sock(&ping_data->sock);
|
||||
|
||||
proz_debug("bytes read = %d", bytes_read);
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
if (errno == ETIMEDOUT)
|
||||
return ping_data->err = PINGTIMEOUT;
|
||||
else
|
||||
return ping_data->err = READERR;
|
||||
}
|
||||
{
|
||||
if (errno == ETIMEDOUT)
|
||||
return ping_data->err = PINGTIMEOUT;
|
||||
else
|
||||
return ping_data->err = READERR;
|
||||
}
|
||||
|
||||
if (bytes_read == 0 || bytes_read < TCP_PING_PACKSIZE)
|
||||
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)
|
||||
{
|
||||
|
||||
request->mass_ping_running = TRUE;
|
||||
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"));
|
||||
|
||||
}
|
||||
|
||||
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 */
|
||||
request->mass_ping_running = FALSE;
|
||||
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)
|
||||
@ -198,7 +201,7 @@ void mass_ping(ftps_request_t * request)
|
||||
simul_pings = request->max_simul_pings;
|
||||
|
||||
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);
|
||||
|
||||
num_iter = request->num_mirrors / simul_pings;
|
||||
@ -214,95 +217,97 @@ void mass_ping(ftps_request_t * request)
|
||||
k = 0;
|
||||
|
||||
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;
|
||||
|
||||
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].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");
|
||||
(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;
|
||||
|
||||
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;
|
||||
|
||||
for (j = 0; j < num_left; j++)
|
||||
{
|
||||
/*Wait till the end of each thread. */
|
||||
pthread_join(ping_threads[j], NULL);
|
||||
{
|
||||
/*Wait till the end of each thread. */
|
||||
pthread_join(ping_threads[j], NULL);
|
||||
|
||||
/*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);
|
||||
/*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++;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
|
||||
proz_debug("mass_ping complete.");
|
||||
pthread_mutex_lock(&request->access_mutex);
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* Main include-file. */
|
||||
|
||||
/* $Id: prozilla.h,v 1.63 2005/09/19 15:25:48 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef PROZILLA_H
|
||||
@ -34,55 +34,55 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
/*Connect establishment related values */
|
||||
NOCONERROR, HOSTERR, CONSOCKERR, CONERROR,
|
||||
CONREFUSED, ACCEPTERR, ACCEPTOK, BINDERR, BINDOK, LISTENERR, LISTENOK,
|
||||
SERVERCLOSECONERR, CONPORTERR,
|
||||
typedef enum {
|
||||
/*Connect establishment related values */
|
||||
NOCONERROR, HOSTERR, CONSOCKERR, CONERROR,
|
||||
CONREFUSED, ACCEPTERR, ACCEPTOK, BINDERR, BINDOK, LISTENERR, LISTENOK,
|
||||
SERVERCLOSECONERR, CONPORTERR,
|
||||
|
||||
/* URL handling related value */
|
||||
URLOK, URLHTTP, URLFTP, URLFILE, URLUNKNOWN, URLBADPORT,
|
||||
URLBADHOST, URLBADPATTERN,
|
||||
/* URL handling related value */
|
||||
URLOK, URLHTTP, URLFTP, URLFILE, URLUNKNOWN, URLBADPORT,
|
||||
URLBADHOST, URLBADPATTERN,
|
||||
|
||||
/* HTTP related values */
|
||||
NEWLOCATION, HOK, HEOF, HERR, HAUTHREQ, HAUTHFAIL,
|
||||
HTTPNSFOD,
|
||||
/* HTTP related values */
|
||||
NEWLOCATION, HOK, HEOF, HERR, HAUTHREQ, HAUTHFAIL,
|
||||
HTTPNSFOD,
|
||||
|
||||
/*FTP related value */
|
||||
FTPOK, FTPLOGINC, FTPLOGREFUSED, FTPPORTERR,
|
||||
FTPNSFOD, FTPRETROK, FTPUNKNOWNTYPE, FTPUNKNOWNCMD, FTPSIZEFAIL,
|
||||
FTPERR, FTPRESTFAIL, FTPACCDENIED,
|
||||
FTPPWDERR,
|
||||
FTPINVPASV, FTPNOPASV, FTPCONREFUSED, FTPCWDFAIL, FTPPWDFAIL,
|
||||
FTPSERVCLOSEDATLOGIN,
|
||||
/*FTP parsing related values */
|
||||
FTPPARSEOK, FTPPARSENOTEXIST, FTPPARSEFAIL,
|
||||
/*FTP related value */
|
||||
FTPOK, FTPLOGINC, FTPLOGREFUSED, FTPPORTERR,
|
||||
FTPNSFOD, FTPRETROK, FTPUNKNOWNTYPE, FTPUNKNOWNCMD, FTPSIZEFAIL,
|
||||
FTPERR, FTPRESTFAIL, FTPACCDENIED,
|
||||
FTPPWDERR,
|
||||
FTPINVPASV, FTPNOPASV, FTPCONREFUSED, FTPCWDFAIL, FTPPWDFAIL,
|
||||
FTPSERVCLOSEDATLOGIN,
|
||||
/*FTP parsing related values */
|
||||
FTPPARSEOK, FTPPARSENOTEXIST, FTPPARSEFAIL,
|
||||
|
||||
/*Error values that can happen due to failed proxie request */
|
||||
GATEWAYTIMEOUT, SERVICEUNAVAIL, BADGATEWAY, INTERNALSERVERR,
|
||||
UNKNOWNREQ,
|
||||
/*Error values that can happen due to failed proxie request */
|
||||
GATEWAYTIMEOUT, SERVICEUNAVAIL, BADGATEWAY, INTERNALSERVERR,
|
||||
UNKNOWNREQ,
|
||||
|
||||
/*File handling related return values. */
|
||||
FOPENERR, FWRITEERR,
|
||||
RETROK,
|
||||
/*File handling related return values. */
|
||||
FOPENERR, FWRITEERR,
|
||||
RETROK,
|
||||
|
||||
/*Download related retrn values. */
|
||||
DLINPROGRESS, DLABORTED, DLDONE, CANTRESUME, DLLOCALFATAL,
|
||||
DLREMOTEFATAL,
|
||||
/*FTPSEARCH+ping related return values. */
|
||||
FTPSINPROGRESS, MASSPINGINPROGRESS, FTPSFAIL, MASSPINGDONE,
|
||||
/*Download related retrn values. */
|
||||
DLINPROGRESS, DLABORTED, DLDONE, CANTRESUME, DLLOCALFATAL,
|
||||
DLREMOTEFATAL,
|
||||
/*FTPSEARCH+ping related return values. */
|
||||
FTPSINPROGRESS, MASSPINGINPROGRESS, FTPSFAIL, MASSPINGDONE,
|
||||
|
||||
/*PING related values */
|
||||
PINGOK, PINGTIMEOUT,
|
||||
/*Misc Value */
|
||||
RETRFINISHED, READERR,
|
||||
/*PING related values */
|
||||
PINGOK, PINGTIMEOUT,
|
||||
/*Misc Value */
|
||||
RETRFINISHED, READERR,
|
||||
|
||||
PROXERR, WRITEERR,
|
||||
FILEISDIR,
|
||||
MIRINFOK, MIRPARSEOK, MIRPARSEFAIL, FILEGETOK,
|
||||
/*Related to file joining */
|
||||
JOININPROGRESS, JOINDONE, JOINERR
|
||||
} uerr_t;
|
||||
PROXERR, WRITEERR,
|
||||
FILEISDIR,
|
||||
MIRINFOK, MIRPARSEOK, MIRPARSEFAIL, FILEGETOK,
|
||||
/*Related to file joining */
|
||||
JOININPROGRESS, JOINDONE, JOINERR
|
||||
} uerr_t;
|
||||
|
||||
|
||||
#define FTP_BUFFER_SIZE 2048
|
||||
@ -105,467 +105,466 @@ extern "C" {
|
||||
|
||||
#define DEFAULT_USER_AGENT "Prozilla"
|
||||
|
||||
typedef char longstring[1024];
|
||||
typedef char longstring[1024];
|
||||
|
||||
/* 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. */
|
||||
typedef struct _urlinfo {
|
||||
char *url; /* Unchanged URL. */
|
||||
uerr_t proto; /* URL protocol. */
|
||||
char *host; /* Extracted hostname. */
|
||||
unsigned short port;
|
||||
char ftp_type;
|
||||
char *path, *dir, *file; /* Path, dir and file (properly decoded). */
|
||||
char *user, *passwd; /* For FTP. */
|
||||
typedef struct _urlinfo {
|
||||
char *url; /* Unchanged URL. */
|
||||
uerr_t proto; /* URL protocol. */
|
||||
char *host; /* Extracted hostname. */
|
||||
unsigned short port;
|
||||
char ftp_type;
|
||||
char *path, *dir, *file; /* Path, dir and file (properly decoded). */
|
||||
char *user, *passwd; /* For FTP. */
|
||||
|
||||
char *referer; /* The source from which the request
|
||||
URI was obtained. */
|
||||
} urlinfo;
|
||||
char *referer; /* The source from which the request
|
||||
URI was obtained. */
|
||||
} urlinfo;
|
||||
|
||||
typedef enum {
|
||||
USERatSITE,
|
||||
USERatPROXYUSERatSITE,
|
||||
USERatSITE_PROXYUSER,
|
||||
PROXYUSERatSITE,
|
||||
LOGINthenUSERatSITE,
|
||||
OPENSITE,
|
||||
SITESITE,
|
||||
HTTPPROXY,
|
||||
FTPGATE,
|
||||
WINGATE
|
||||
} proxy_type;
|
||||
typedef enum {
|
||||
USERatSITE,
|
||||
USERatPROXYUSERatSITE,
|
||||
USERatSITE_PROXYUSER,
|
||||
PROXYUSERatSITE,
|
||||
LOGINthenUSERatSITE,
|
||||
OPENSITE,
|
||||
SITESITE,
|
||||
HTTPPROXY,
|
||||
FTPGATE,
|
||||
WINGATE
|
||||
} proxy_type;
|
||||
|
||||
|
||||
typedef enum {
|
||||
IDLE = 0,
|
||||
CONNECTING,
|
||||
LOGGININ,
|
||||
DOWNLOADING,
|
||||
COMPLETED,
|
||||
LOGINFAIL,
|
||||
CONREJECT,
|
||||
REMOTEFATAL,
|
||||
LOCALFATAL,
|
||||
TIMEDOUT,
|
||||
MAXTRYS
|
||||
} dl_status;
|
||||
typedef enum {
|
||||
IDLE = 0,
|
||||
CONNECTING,
|
||||
LOGGININ,
|
||||
DOWNLOADING,
|
||||
COMPLETED,
|
||||
LOGINFAIL,
|
||||
CONREJECT,
|
||||
REMOTEFATAL,
|
||||
LOCALFATAL,
|
||||
TIMEDOUT,
|
||||
MAXTRYS
|
||||
} dl_status;
|
||||
|
||||
|
||||
typedef enum {
|
||||
NOT_FOUND,
|
||||
REGULAR_FILE,
|
||||
DIRECTORY,
|
||||
SYMBOLIC_LINK,
|
||||
UNKNOWN
|
||||
} file_type_t;
|
||||
typedef enum {
|
||||
NOT_FOUND,
|
||||
REGULAR_FILE,
|
||||
DIRECTORY,
|
||||
SYMBOLIC_LINK,
|
||||
UNKNOWN
|
||||
} file_type_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
off_t len; /* Received length. */
|
||||
off_t contlen; /* Expected length. */
|
||||
int res; /* The result of last read. */
|
||||
typedef struct {
|
||||
off_t len; /* Received length. */
|
||||
off_t contlen; /* Expected length. */
|
||||
int res; /* The result of last read. */
|
||||
|
||||
/* -1 = Accept ranges not found.
|
||||
0 = Accepts range is none.
|
||||
1 = Accepts ranges. */
|
||||
int accept_ranges;
|
||||
/* -1 = Accept ranges not found.
|
||||
0 = Accepts range is none.
|
||||
1 = Accepts ranges. */
|
||||
int accept_ranges;
|
||||
|
||||
char *newloc; /* New location (redirection). */
|
||||
char *remote_time; /* Remote time-stamp string. */
|
||||
char *error; /* Textual HTTP error. */
|
||||
int statcode; /* Status code. */
|
||||
} http_stat_t;
|
||||
char *newloc; /* New location (redirection). */
|
||||
char *remote_time; /* Remote time-stamp string. */
|
||||
char *error; /* Textual HTTP error. */
|
||||
int statcode; /* Status code. */
|
||||
} http_stat_t;
|
||||
|
||||
typedef struct {
|
||||
urlinfo proxy_url;
|
||||
char *username;
|
||||
char *passwd;
|
||||
proxy_type type;
|
||||
boolean use_proxy;
|
||||
} proxy_info;
|
||||
typedef struct {
|
||||
urlinfo proxy_url;
|
||||
char *username;
|
||||
char *passwd;
|
||||
proxy_type type;
|
||||
boolean use_proxy;
|
||||
} proxy_info;
|
||||
|
||||
typedef struct libprozinfo {
|
||||
int argc;
|
||||
char **argv;
|
||||
boolean debug_mode;
|
||||
typedef struct libprozinfo {
|
||||
int argc;
|
||||
char **argv;
|
||||
boolean debug_mode;
|
||||
|
||||
/* For netrc. */
|
||||
netrc_entry *netrc_list;
|
||||
boolean use_netrc;
|
||||
/* For netrc. */
|
||||
netrc_entry *netrc_list;
|
||||
boolean use_netrc;
|
||||
|
||||
char *home_dir;
|
||||
char *ftp_default_user;
|
||||
char *ftp_default_passwd;
|
||||
char *dl_dir;
|
||||
char *output_dir;
|
||||
char *log_dir;
|
||||
boolean ftp_use_pasv;
|
||||
proxy_info *ftp_proxy;
|
||||
proxy_info *http_proxy;
|
||||
boolean http_no_cache;
|
||||
/* the default timeout for all the connection types (ctrl, data etc) */
|
||||
struct timeval conn_timeout;
|
||||
struct timeval conn_retry_delay;
|
||||
int max_attempts;
|
||||
long max_bps_per_dl;
|
||||
} libprozinfo;
|
||||
char *home_dir;
|
||||
char *ftp_default_user;
|
||||
char *ftp_default_passwd;
|
||||
char *dl_dir;
|
||||
char *output_dir;
|
||||
char *log_dir;
|
||||
boolean ftp_use_pasv;
|
||||
proxy_info *ftp_proxy;
|
||||
proxy_info *http_proxy;
|
||||
boolean http_no_cache;
|
||||
/* the default timeout for all the connection types (ctrl, data etc) */
|
||||
struct timeval conn_timeout;
|
||||
struct timeval conn_retry_delay;
|
||||
int max_attempts;
|
||||
long max_bps_per_dl;
|
||||
} libprozinfo;
|
||||
|
||||
extern libprozinfo libprozrtinfo;
|
||||
extern libprozinfo libprozrtinfo;
|
||||
|
||||
|
||||
typedef struct response_line {
|
||||
char *line;
|
||||
struct response_line *next;
|
||||
} response_line;
|
||||
typedef struct response_line {
|
||||
char *line;
|
||||
struct response_line *next;
|
||||
} 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,
|
||||
path,protocol etc. */
|
||||
urlinfo u;
|
||||
/* The error status of the connection. */
|
||||
uerr_t err;
|
||||
|
||||
/* The error status of the connection. */
|
||||
uerr_t err;
|
||||
/* Proxy specific info. */
|
||||
|
||||
/* Proxy specific info. */
|
||||
proxy_info *ftp_proxy;
|
||||
proxy_info *http_proxy;
|
||||
|
||||
proxy_info *ftp_proxy;
|
||||
proxy_info *http_proxy;
|
||||
/* Netrc. */
|
||||
boolean use_netrc;
|
||||
|
||||
/* Netrc. */
|
||||
boolean use_netrc;
|
||||
/* FTP specific info. */
|
||||
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. */
|
||||
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;
|
||||
/* Additional info about what this URL is. */
|
||||
/* FIXME Should this be in the url_info struct? */
|
||||
file_type_t file_type;
|
||||
|
||||
/* Additional info about what this URL is. */
|
||||
/* FIXME Should this be in the url_info struct? */
|
||||
file_type_t file_type;
|
||||
/* The lines that the server returned. */
|
||||
response_line *serv_ret_lines;
|
||||
|
||||
/* The lines that the server returned. */
|
||||
response_line *serv_ret_lines;
|
||||
/* Does the server support resume? */
|
||||
boolean resume_support;
|
||||
|
||||
/* Does the server support resume? */
|
||||
boolean resume_support;
|
||||
/* The file name to save the data to locally. */
|
||||
char *localfile;
|
||||
|
||||
/* The file name to save the data to locally. */
|
||||
char *localfile;
|
||||
/* Pointer to file that we will be saving the data to locally. */
|
||||
FILE *fp;
|
||||
|
||||
/* Pointer to file that we will be saving the data to locally. */
|
||||
FILE *fp;
|
||||
/* Tells whether to open the file for appending or for writing etc.
|
||||
Used for adding resume support. */
|
||||
char *file_mode;
|
||||
|
||||
/* Tells whether to open the file for appending or for writing etc.
|
||||
Used for adding resume support. */
|
||||
char *file_mode;
|
||||
/* FIXME Add an enum here to say whether run mode is resume or normal etc.
|
||||
and remove the file mode. */
|
||||
|
||||
/* FIXME Add an enum here to say whether run mode is resume or normal etc.
|
||||
and remove the file mode. */
|
||||
off_t remote_startpos;
|
||||
off_t orig_remote_startpos;
|
||||
off_t remote_endpos;
|
||||
off_t remote_bytes_received;
|
||||
|
||||
off_t remote_startpos;
|
||||
off_t orig_remote_startpos;
|
||||
off_t remote_endpos;
|
||||
off_t remote_bytes_received;
|
||||
off_t main_file_size;
|
||||
|
||||
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
|
||||
anticipation of making the threads download to a single file. */
|
||||
off_t local_base_offset;
|
||||
/* Indicates the startpos of the localfile. It is always 0 in normal mode
|
||||
and can be any positive value in resume mode. */
|
||||
off_t local_startpos;
|
||||
|
||||
/* Indicates the startpos of the localfile. It is always 0 in normal mode
|
||||
and can be any positive value in resume mode. */
|
||||
off_t local_startpos;
|
||||
/* The start position at the beginning of the download. */
|
||||
off_t orig_local_startpos;
|
||||
/* long bytes_xferred; */
|
||||
dl_status status;
|
||||
char *szBuffer;
|
||||
|
||||
/* The start position at the beginning of the download. */
|
||||
off_t orig_local_startpos;
|
||||
/* long bytes_xferred; */
|
||||
dl_status status;
|
||||
char *szBuffer;
|
||||
/* Tells the download thread whether to abort the download or not. */
|
||||
boolean abort;
|
||||
|
||||
/* Tells the download thread whether to abort the download or not. */
|
||||
boolean abort;
|
||||
/* Information about the connection's start and end time. */
|
||||
struct timeval time_begin;
|
||||
struct timeval time_end;
|
||||
|
||||
/* Information about the connection's start and end time. */
|
||||
struct timeval time_begin;
|
||||
struct timeval time_end;
|
||||
/* Info about whether to retry the thread or not. */
|
||||
boolean retry;
|
||||
|
||||
/* Info about whether to retry the thread or not. */
|
||||
boolean retry;
|
||||
/* The number of attempts to try to complete a connection. 0 means unlimited
|
||||
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
|
||||
connection attempts. */
|
||||
int max_attempts;
|
||||
/* The number of attempts that this connection has been tried */
|
||||
int attempts;
|
||||
/* The time when to try to restart the connection. */
|
||||
struct timeval retry_delay;
|
||||
|
||||
/* The time when to try to restart the connection. */
|
||||
struct timeval retry_delay;
|
||||
/* Each connection will acquire this mutex before changing state. */
|
||||
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. */
|
||||
pthread_mutex_t *status_change_mutex;
|
||||
/*This will be broadcast when the connection starts connecting */
|
||||
pthread_cond_t connecting_cond;
|
||||
/* User agent for HTTP. */
|
||||
char *user_agent;
|
||||
|
||||
/* User agent for HTTP. */
|
||||
char *user_agent;
|
||||
|
||||
http_stat_t hs;
|
||||
message_proc msg_proc;
|
||||
/*additional callback data whcih is specified by the user
|
||||
that is passed to msg_proc */
|
||||
void *cb_data;
|
||||
/* Indicates whether a conenction is running or not */
|
||||
int running;
|
||||
/*Mutex used to lock acesss to data in this struct
|
||||
that is accesed/written by other threads */
|
||||
pthread_mutex_t access_mutex;
|
||||
/*This indicates that we should use the pragma no-cache directive for http proxies */
|
||||
boolean http_no_cache;
|
||||
/*The rate of this connection whcih is calcualted */
|
||||
long rate_bps;
|
||||
/*We limit the connections speed to this */
|
||||
long max_allowed_bps;
|
||||
} connection_t;
|
||||
http_stat_t hs;
|
||||
message_proc msg_proc;
|
||||
/*additional callback data whcih is specified by the user
|
||||
that is passed to msg_proc */
|
||||
void *cb_data;
|
||||
/* Indicates whether a conenction is running or not */
|
||||
int running;
|
||||
/*Mutex used to lock acesss to data in this struct
|
||||
that is accesed/written by other threads */
|
||||
pthread_mutex_t access_mutex;
|
||||
/*This indicates that we should use the pragma no-cache directive for http proxies */
|
||||
boolean http_no_cache;
|
||||
/*The rate of this connection whcih is calcualted */
|
||||
long rate_bps;
|
||||
/*We limit the connections speed to this */
|
||||
long max_allowed_bps;
|
||||
} connection_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
UNTESTED = 0, RESPONSEOK, NORESPONSE, ERROR
|
||||
} ftp_mirror_stat_t;
|
||||
typedef enum {
|
||||
UNTESTED = 0, RESPONSEOK, NORESPONSE, ERROR
|
||||
} ftp_mirror_stat_t;
|
||||
|
||||
typedef enum {
|
||||
LYCOS, FILESEARCH_RU
|
||||
} ftpsearch_server_type_t;
|
||||
typedef enum {
|
||||
LYCOS, FILESEARCH_RU
|
||||
} ftpsearch_server_type_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
char *path;
|
||||
boolean valid;
|
||||
} mirror_path_t;
|
||||
typedef struct {
|
||||
char *path;
|
||||
boolean valid;
|
||||
} mirror_path_t;
|
||||
|
||||
typedef struct ftp_mirror {
|
||||
char *server_name;
|
||||
mirror_path_t *paths;
|
||||
char *file_name;
|
||||
char *full_name;
|
||||
char *file_size;
|
||||
struct timeval tv;
|
||||
int milli_secs;
|
||||
int num_paths;
|
||||
ftp_mirror_stat_t status;
|
||||
int copied;
|
||||
boolean resume_supported;
|
||||
int max_simul_connections;
|
||||
} ftp_mirror_t;
|
||||
typedef struct ftp_mirror {
|
||||
char *server_name;
|
||||
mirror_path_t *paths;
|
||||
char *file_name;
|
||||
char *full_name;
|
||||
char *file_size;
|
||||
struct timeval tv;
|
||||
int milli_secs;
|
||||
int num_paths;
|
||||
ftp_mirror_stat_t status;
|
||||
int copied;
|
||||
boolean resume_supported;
|
||||
int max_simul_connections;
|
||||
} ftp_mirror_t;
|
||||
|
||||
typedef struct {
|
||||
off_t file_size;
|
||||
char *file_name;
|
||||
connection_t *connection;
|
||||
ftpsearch_server_type_t server_type;
|
||||
ftp_mirror_t *mirrors;
|
||||
int num_mirrors;
|
||||
uerr_t err;
|
||||
boolean info_running;
|
||||
boolean mass_ping_running;
|
||||
pthread_mutex_t access_mutex;
|
||||
pthread_t info_thread;
|
||||
pthread_t mass_ping_thread;
|
||||
int max_simul_pings;
|
||||
struct timeval ping_timeout;
|
||||
urlinfo *requested_url;
|
||||
} ftps_request_t;
|
||||
typedef struct {
|
||||
off_t file_size;
|
||||
char *file_name;
|
||||
connection_t *connection;
|
||||
ftpsearch_server_type_t server_type;
|
||||
ftp_mirror_t *mirrors;
|
||||
int num_mirrors;
|
||||
uerr_t err;
|
||||
boolean info_running;
|
||||
boolean mass_ping_running;
|
||||
pthread_mutex_t access_mutex;
|
||||
pthread_t info_thread;
|
||||
pthread_t mass_ping_thread;
|
||||
int max_simul_pings;
|
||||
struct timeval ping_timeout;
|
||||
urlinfo *requested_url;
|
||||
} ftps_request_t;
|
||||
|
||||
|
||||
typedef struct download_t {
|
||||
urlinfo u;
|
||||
char *dl_dir;
|
||||
char *log_dir;
|
||||
char *output_dir;
|
||||
connection_t **pconnections;
|
||||
pthread_t *threads;
|
||||
pthread_mutex_t status_change_mutex;
|
||||
int num_connections;
|
||||
/* Optional will be called back with info about download. */
|
||||
message_proc msg_proc;
|
||||
/*additional callback data which is specified by the user
|
||||
that is passed to msg_proc */
|
||||
void *cb_data;
|
||||
off_t main_file_size;
|
||||
boolean resume_mode;
|
||||
struct timeval start_time;
|
||||
/*Does this DL support resume? */
|
||||
boolean resume_support;
|
||||
/*This contains the building status, 1 = building,0 build finished, -1 error occured */
|
||||
int building;
|
||||
/*This is the percentage of the file that is been built currently */
|
||||
float file_build_percentage;
|
||||
int max_simul_connections;
|
||||
/*Mutex used to lock acesss to data in this struct
|
||||
that is accesed/written by other threads */
|
||||
pthread_mutex_t access_mutex;
|
||||
/* The message that is returned when the file build process is finished
|
||||
*/
|
||||
char *file_build_msg;
|
||||
/*Max mps for this download */
|
||||
long max_allowed_bps;
|
||||
ftps_request_t *ftps_info;
|
||||
boolean using_ftpsearch;
|
||||
pthread_t join_thread;
|
||||
} download_t;
|
||||
typedef struct download_t {
|
||||
urlinfo u;
|
||||
char *dl_dir;
|
||||
char *log_dir;
|
||||
char *output_dir;
|
||||
connection_t **pconnections;
|
||||
pthread_t *threads;
|
||||
pthread_mutex_t status_change_mutex;
|
||||
int num_connections;
|
||||
/* Optional will be called back with info about download. */
|
||||
message_proc msg_proc;
|
||||
/*additional callback data which is specified by the user
|
||||
that is passed to msg_proc */
|
||||
void *cb_data;
|
||||
off_t main_file_size;
|
||||
boolean resume_mode;
|
||||
struct timeval start_time;
|
||||
/*Does this DL support resume? */
|
||||
boolean resume_support;
|
||||
/*This contains the building status, 1 = building,0 build finished, -1 error occured */
|
||||
int building;
|
||||
/*This is the percentage of the file that is been built currently */
|
||||
float file_build_percentage;
|
||||
int max_simul_connections;
|
||||
/*Mutex used to lock acesss to data in this struct
|
||||
that is accesed/written by other threads */
|
||||
pthread_mutex_t access_mutex;
|
||||
/* The message that is returned when the file build process is finished
|
||||
*/
|
||||
char *file_build_msg;
|
||||
/*Max mps for this download */
|
||||
long max_allowed_bps;
|
||||
ftps_request_t *ftps_info;
|
||||
boolean using_ftpsearch;
|
||||
pthread_t join_thread;
|
||||
} download_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
/* the number of connections that this download was started with */
|
||||
int num_connections;
|
||||
/*I have added these newly */
|
||||
int version; /*The version of this logfile */
|
||||
/*Indicates whether we have got info about the files size, final URL etc */
|
||||
boolean got_info;
|
||||
off_t file_size;
|
||||
int url_len; /*The length in bytes of the url text stred in the log file */
|
||||
char *url;
|
||||
int reserved[30];
|
||||
} logfile;
|
||||
typedef struct {
|
||||
/* the number of connections that this download was started with */
|
||||
int num_connections;
|
||||
/*I have added these newly */
|
||||
int version; /*The version of this logfile */
|
||||
/*Indicates whether we have got info about the files size, final URL etc */
|
||||
boolean got_info;
|
||||
off_t file_size;
|
||||
int url_len; /*The length in bytes of the url text stred in the log file */
|
||||
char *url;
|
||||
int reserved[30];
|
||||
} logfile;
|
||||
|
||||
|
||||
/*Structs for logfile handling */
|
||||
/*Structs for logfile handling */
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
char *host;
|
||||
int port;
|
||||
struct timeval timeout;
|
||||
struct timeval ping_time;
|
||||
int sock;
|
||||
uerr_t err;
|
||||
} ping_t;
|
||||
typedef struct {
|
||||
char *host;
|
||||
int port;
|
||||
struct timeval timeout;
|
||||
struct timeval ping_time;
|
||||
int sock;
|
||||
uerr_t err;
|
||||
} ping_t;
|
||||
|
||||
|
||||
/*Functions for URL parsing */
|
||||
uerr_t proz_parse_url(const char *url, urlinfo * u, boolean strict);
|
||||
urlinfo *proz_copy_url(urlinfo * u);
|
||||
void proz_free_url(urlinfo * u, boolean complete);
|
||||
uerr_t proz_parse_url(const char *url, urlinfo * u, boolean strict);
|
||||
urlinfo *proz_copy_url(urlinfo * u);
|
||||
void proz_free_url(urlinfo * u, boolean complete);
|
||||
|
||||
/*Functions that set values which will apply for all conenctions. */
|
||||
int proz_init(int argc, char **argv);
|
||||
void proz_shutdown(void);
|
||||
void proz_die(const char *message, ...);
|
||||
int proz_init(int argc, char **argv);
|
||||
void proz_shutdown(void);
|
||||
void proz_die(const char *message, ...);
|
||||
|
||||
void proz_set_http_proxy(proxy_info * proxy);
|
||||
void proz_set_ftp_proxy(proxy_info * proxy);
|
||||
void proz_use_ftp_proxy(boolean use);
|
||||
void proz_use_http_proxy(boolean use);
|
||||
void proz_set_connection_timeout(struct timeval *timeout);
|
||||
void proz_set_connection_retry_delay(struct timeval *delay);
|
||||
void proz_set_download_dir(char *dir);
|
||||
void proz_set_logfile_dir(char *dir);
|
||||
void proz_set_output_dir(char *dir);
|
||||
char *proz_get_libprozilla_version();
|
||||
void proz_set_http_proxy(proxy_info * proxy);
|
||||
void proz_set_ftp_proxy(proxy_info * proxy);
|
||||
void proz_use_ftp_proxy(boolean use);
|
||||
void proz_use_http_proxy(boolean use);
|
||||
void proz_set_connection_timeout(struct timeval *timeout);
|
||||
void proz_set_connection_retry_delay(struct timeval *delay);
|
||||
void proz_set_download_dir(char *dir);
|
||||
void proz_set_logfile_dir(char *dir);
|
||||
void proz_set_output_dir(char *dir);
|
||||
char *proz_get_libprozilla_version();
|
||||
|
||||
/*Functions for loggind debug messages */
|
||||
void proz_debug(const char *format, ...);
|
||||
void proz_debug_delete_log();
|
||||
/*Functions for loggind debug messages */
|
||||
void proz_debug(const char *format, ...);
|
||||
void proz_debug_delete_log();
|
||||
|
||||
/*Functions which are for handling a single connection. */
|
||||
connection_t * proz_connection_init(urlinfo * url, pthread_mutex_t * mutex);
|
||||
void proz_connection_set_url(connection_t * connection, urlinfo *url);
|
||||
connection_t * proz_connection_init(urlinfo * url, pthread_mutex_t * mutex);
|
||||
void proz_connection_set_url(connection_t * connection, urlinfo *url);
|
||||
|
||||
char *proz_connection_get_status_string(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);
|
||||
off_t proz_connection_get_total_remote_bytes_got(connection_t *
|
||||
connection);
|
||||
void proz_connection_set_msg_proc(connection_t * connection,
|
||||
message_proc msg_proc, void *cb_data);
|
||||
void proz_connection_free_connection(connection_t * connection,
|
||||
boolean complete);
|
||||
dl_status proz_connection_get_status(connection_t * connection);
|
||||
boolean proz_connection_running(connection_t * connection);
|
||||
char *proz_connection_get_status_string(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);
|
||||
off_t proz_connection_get_total_remote_bytes_got(connection_t *
|
||||
connection);
|
||||
void proz_connection_set_msg_proc(connection_t * connection,
|
||||
message_proc msg_proc, void *cb_data);
|
||||
void proz_connection_free_connection(connection_t * connection,
|
||||
boolean complete);
|
||||
dl_status proz_connection_get_status(connection_t * connection);
|
||||
boolean proz_connection_running(connection_t * connection);
|
||||
|
||||
/*Functions which are for handling a download */
|
||||
download_t *proz_download_init(urlinfo * u);
|
||||
int proz_download_setup_connections_no_ftpsearch(download_t * download,
|
||||
connection_t *
|
||||
connection,
|
||||
int req_connections);
|
||||
void proz_download_start_downloads(download_t * download,
|
||||
boolean resume);
|
||||
int proz_download_load_resume_info(download_t * download);
|
||||
void proz_download_stop_downloads(download_t * download);
|
||||
download_t *proz_download_init(urlinfo * u);
|
||||
int proz_download_setup_connections_no_ftpsearch(download_t * download,
|
||||
connection_t *
|
||||
connection,
|
||||
int req_connections);
|
||||
void proz_download_start_downloads(download_t * download,
|
||||
boolean resume);
|
||||
int proz_download_load_resume_info(download_t * download);
|
||||
void proz_download_stop_downloads(download_t * download);
|
||||
|
||||
boolean proz_download_all_dls_status(download_t * download,
|
||||
dl_status status);
|
||||
boolean proz_download_all_dls_err(download_t * download, uerr_t err);
|
||||
boolean proz_download_all_dls_status(download_t * download,
|
||||
dl_status status);
|
||||
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_ftpcwdfail(download_t * download);
|
||||
boolean proz_download_all_dls_filensfod(download_t * download);
|
||||
boolean proz_download_all_dls_ftpcwdfail(download_t * download);
|
||||
|
||||
|
||||
off_t proz_download_get_total_bytes_got(download_t * download);
|
||||
uerr_t proz_download_handle_threads(download_t * download);
|
||||
int proz_download_prev_download_exists(download_t * download);
|
||||
float proz_download_get_average_speed(download_t * download);
|
||||
int proz_download_delete_dl_file(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);
|
||||
void proz_download_set_msg_proc(download_t * download,
|
||||
message_proc msg_proc, void *cb_data);
|
||||
off_t proz_download_get_est_time_left(download_t * download);
|
||||
void proz_download_free_download(download_t * download,
|
||||
boolean complete);
|
||||
int proz_download_target_exist(download_t * download);
|
||||
int proz_download_delete_target(download_t * download);
|
||||
off_t proz_download_get_total_bytes_got(download_t * download);
|
||||
uerr_t proz_download_handle_threads(download_t * download);
|
||||
int proz_download_prev_download_exists(download_t * download);
|
||||
float proz_download_get_average_speed(download_t * download);
|
||||
int proz_download_delete_dl_file(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);
|
||||
void proz_download_set_msg_proc(download_t * download,
|
||||
message_proc msg_proc, void *cb_data);
|
||||
off_t proz_download_get_est_time_left(download_t * download);
|
||||
void proz_download_free_download(download_t * download,
|
||||
boolean complete);
|
||||
int proz_download_target_exist(download_t * download);
|
||||
int proz_download_delete_target(download_t * download);
|
||||
|
||||
/* Functions related to handling the logfile created for a download */
|
||||
int proz_log_read_logfile(logfile * lf, download_t * download,
|
||||
boolean load_con_info);
|
||||
int proz_log_delete_logfile(download_t * download);
|
||||
int proz_log_logfile_exists(download_t * download);
|
||||
char *proz_strerror(uerr_t error);
|
||||
/* Functions related to handling the logfile created for a download */
|
||||
int proz_log_read_logfile(logfile * lf, download_t * download,
|
||||
boolean load_con_info);
|
||||
int proz_log_delete_logfile(download_t * download);
|
||||
int proz_log_logfile_exists(download_t * download);
|
||||
char *proz_strerror(uerr_t error);
|
||||
|
||||
/*Ftpsearch releated */
|
||||
/*Ftpsearch releated */
|
||||
ftps_request_t * proz_ftps_request_init(
|
||||
urlinfo * requested_url, off_t file_size,
|
||||
char *ftps_loc,
|
||||
ftpsearch_server_type_t server_type,
|
||||
int num_req_mirrors);
|
||||
void proz_get_complete_mirror_list(ftps_request_t * request);
|
||||
boolean proz_request_info_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_sort_mirror_list(ftp_mirror_t * mirrors, int num_servers);
|
||||
void proz_cancel_mirror_list_request(ftps_request_t * request);
|
||||
urlinfo * requested_url, off_t file_size,
|
||||
char *ftps_loc,
|
||||
ftpsearch_server_type_t server_type,
|
||||
int num_req_mirrors);
|
||||
void proz_get_complete_mirror_list(ftps_request_t * request);
|
||||
boolean proz_request_info_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_sort_mirror_list(ftp_mirror_t * mirrors, int num_servers);
|
||||
void proz_cancel_mirror_list_request(ftps_request_t * request);
|
||||
|
||||
int proz_download_setup_connections_ftpsearch(download_t * download,
|
||||
connection_t * connection,
|
||||
ftps_request_t * request,
|
||||
int req_connections);
|
||||
void proz_cancel_mass_ping(ftps_request_t * request);
|
||||
int proz_download_setup_connections_ftpsearch(download_t * download,
|
||||
connection_t * connection,
|
||||
ftps_request_t * request,
|
||||
int req_connections);
|
||||
void proz_cancel_mass_ping(ftps_request_t * request);
|
||||
|
||||
/*Misc functions */
|
||||
int proz_timeval_subtract(struct timeval *result, struct timeval *x,
|
||||
struct timeval *y);
|
||||
/*Misc functions */
|
||||
int proz_timeval_subtract(struct timeval *result, struct timeval *x,
|
||||
struct timeval *y);
|
||||
|
||||
/*Funcs related to joining the downloaded file portions */
|
||||
void proz_download_join_downloads(download_t * download);
|
||||
uerr_t proz_download_get_join_status(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_wait_till_end_joining_thread(download_t * download);
|
||||
/*Funcs related to joining the downloaded file portions */
|
||||
void proz_download_join_downloads(download_t * download);
|
||||
uerr_t proz_download_get_join_status(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_wait_till_end_joining_thread(download_t * download);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* PROZILLA_H */
|
||||
#endif /* PROZILLA_H */
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************************
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
libprozilla - a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
/* A test program. */
|
||||
|
||||
/* $Id: test.c,v 1.30 2001/09/23 01:39:16 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#include "common.h"
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
The main function.
|
||||
The main function.
|
||||
******************************************************************************/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@ -49,18 +49,18 @@ int main(int argc, char **argv)
|
||||
libprozrtinfo.conn_timeout.tv_sec = 100;
|
||||
|
||||
proz_prepare_ftps_request(&request, "ddd-3.3.tar.bz2", 4811576,
|
||||
"http://ftpsearch.uniovi.es:8000/ftpsearch",
|
||||
LYCOS, 40);
|
||||
"http://ftpsearch.uniovi.es:8000/ftpsearch",
|
||||
LYCOS, 40);
|
||||
|
||||
proz_get_complete_mirror_list(&request);
|
||||
|
||||
for (i = 0; i < request.num_mirrors; i++)
|
||||
{
|
||||
printf("%s\n", request.mirrors[i].server_name);
|
||||
printf("\t%d\n", request.mirrors[i].num_paths);
|
||||
for (j = 0; j < request.mirrors[i].num_paths; j++)
|
||||
printf("\t\t%s\n", request.mirrors[i].paths[j].path);
|
||||
}
|
||||
{
|
||||
printf("%s\n", request.mirrors[i].server_name);
|
||||
printf("\t%d\n", request.mirrors[i].num_paths);
|
||||
for (j = 0; j < request.mirrors[i].num_paths; j++)
|
||||
printf("\t\t%s\n", request.mirrors[i].paths[j].path);
|
||||
}
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
/* $Id: url.h,v 1.20 2001/08/17 21:53:39 kalum Exp $ */
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
#ifndef URL_H
|
||||
@ -31,44 +31,44 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* Structure containing info on a protocol. */
|
||||
typedef struct proto {
|
||||
char *name;
|
||||
uerr_t ind;
|
||||
unsigned short port;
|
||||
} proto_t;
|
||||
typedef struct proto {
|
||||
char *name;
|
||||
uerr_t ind;
|
||||
unsigned short port;
|
||||
} proto_t;
|
||||
|
||||
enum uflags {
|
||||
URELATIVE = 0x0001, /* Is URL relative? */
|
||||
UNOPROTO = 0x0002, /* Is URL without a protocol? */
|
||||
UABS2REL = 0x0004, /* Convert absolute to relative? */
|
||||
UREL2ABS = 0x0008 /* Convert relative to absolute? */
|
||||
};
|
||||
enum uflags {
|
||||
URELATIVE = 0x0001, /* Is URL relative? */
|
||||
UNOPROTO = 0x0002, /* Is URL without a protocol? */
|
||||
UABS2REL = 0x0004, /* Convert absolute to relative? */
|
||||
UREL2ABS = 0x0008 /* Convert relative to absolute? */
|
||||
};
|
||||
|
||||
/* A structure that defines the whereabouts of a URL, i.e. its
|
||||
position in an HTML document, etc. */
|
||||
typedef struct _urlpos {
|
||||
char *url; /* URL */
|
||||
char *local_name; /* Local file to which it was saved. */
|
||||
enum uflags flags; /* Various flags. */
|
||||
int pos, size; /* Rekative position in the buffer. */
|
||||
struct _urlpos *next; /* Next struct in list. */
|
||||
} urlpos;
|
||||
typedef struct _urlpos {
|
||||
char *url; /* URL */
|
||||
char *local_name; /* Local file to which it was saved. */
|
||||
enum uflags flags; /* Various flags. */
|
||||
int pos, size; /* Rekative position in the buffer. */
|
||||
struct _urlpos *next; /* Next struct in list. */
|
||||
} urlpos;
|
||||
|
||||
int
|
||||
has_proto(const char *url);
|
||||
int
|
||||
skip_uname(const char *url);
|
||||
void
|
||||
parse_dir(const char *path, char **dir, char **file);
|
||||
void
|
||||
path_simplify(char *path);
|
||||
char *uri_merge(const char *base, const char *link);
|
||||
int
|
||||
urlpath_length(const char *url);
|
||||
int
|
||||
skip_proto(const char *url);
|
||||
char *str_url(const urlinfo * u, int hide);
|
||||
int
|
||||
has_proto(const char *url);
|
||||
int
|
||||
skip_uname(const char *url);
|
||||
void
|
||||
parse_dir(const char *path, char **dir, char **file);
|
||||
void
|
||||
path_simplify(char *path);
|
||||
char *uri_merge(const char *base, const char *link);
|
||||
int
|
||||
urlpath_length(const char *url);
|
||||
int
|
||||
skip_proto(const char *url);
|
||||
char *str_url(const urlinfo * u, int hide);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* URL_H */
|
||||
#endif /* URL_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -35,48 +35,47 @@ typedef enum {
|
||||
} dlg_class;
|
||||
|
||||
class DL_Window {
|
||||
|
||||
public:
|
||||
DL_Window(urlinfo * url_data);
|
||||
~DL_Window();
|
||||
DL_Window(urlinfo * url_data);
|
||||
~DL_Window();
|
||||
|
||||
void dl_start(int num_connections, boolean ftpsearch);
|
||||
void my_cb();
|
||||
void dl_start(int num_connections, boolean ftpsearch);
|
||||
void my_cb();
|
||||
|
||||
void handle_info_thread();
|
||||
void handle_ftpsearch();
|
||||
void handle_download_thread();
|
||||
void handle_info_thread();
|
||||
void handle_ftpsearch();
|
||||
void handle_download_thread();
|
||||
|
||||
void start_download();
|
||||
void start_download();
|
||||
|
||||
void handle_joining_thread();
|
||||
void handle_dl_fatal_error();
|
||||
void cleanup(boolean erase_dlparts);
|
||||
void print_status(download_t * download, int quiet_mode);
|
||||
void handle_joining_thread();
|
||||
void handle_dl_fatal_error();
|
||||
void cleanup(boolean erase_dlparts);
|
||||
void print_status(download_t * download, int quiet_mode);
|
||||
|
||||
connection_t *connection;
|
||||
download_t *download;
|
||||
urlinfo u;
|
||||
boolean got_info;
|
||||
boolean got_dl;
|
||||
connection_t *connection;
|
||||
download_t *download;
|
||||
urlinfo u;
|
||||
boolean got_info;
|
||||
boolean got_dl;
|
||||
|
||||
dlwin_status_t status;
|
||||
dlwin_status_t status;
|
||||
|
||||
pthread_t info_thread;
|
||||
pthread_mutex_t getinfo_mutex;
|
||||
int num_connections;
|
||||
/*The time elapsed since the last update */
|
||||
struct timeval update_time;
|
||||
pthread_t info_thread;
|
||||
pthread_mutex_t getinfo_mutex;
|
||||
int num_connections;
|
||||
/*The time elapsed since the last update */
|
||||
struct timeval update_time;
|
||||
|
||||
private:
|
||||
void do_download();
|
||||
void handle_prev_download();
|
||||
boolean joining_thread_running;
|
||||
boolean do_ftpsearch;
|
||||
boolean using_ftpsearch;
|
||||
FTPS_Window *ftpsearch_win;
|
||||
int askUserResume(connection_t *connection, boolean resumeSupported);
|
||||
int askUserOverwrite(connection_t *connection);
|
||||
void do_download();
|
||||
void handle_prev_download();
|
||||
boolean joining_thread_running;
|
||||
boolean do_ftpsearch;
|
||||
boolean using_ftpsearch;
|
||||
FTPS_Window *ftpsearch_win;
|
||||
int askUserResume(connection_t *connection, boolean resumeSupported);
|
||||
int askUserOverwrite(connection_t *connection);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,9 +3,9 @@
|
||||
#define ftps_win_h
|
||||
#include "prozilla.h"
|
||||
/*
|
||||
class ftps_gui {
|
||||
public:
|
||||
ftps_gui();
|
||||
};
|
||||
*/
|
||||
class ftps_gui {
|
||||
public:
|
||||
ftps_gui();
|
||||
};
|
||||
*/
|
||||
#endif
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
@ -32,30 +32,30 @@
|
||||
|
||||
FTPS_Window::FTPS_Window ()
|
||||
{
|
||||
memset (&request, 0, sizeof (request));
|
||||
memset(&request, 0, sizeof(request));
|
||||
|
||||
request_running = FALSE;
|
||||
ping_running = FALSE;
|
||||
got_mirror_info = FALSE;
|
||||
request_running = FALSE;
|
||||
ping_running = FALSE;
|
||||
got_mirror_info = FALSE;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FTPS_Window::fetch_mirror_info (urlinfo * u, off_t file_size,
|
||||
char *ftps_loc,
|
||||
ftpsearch_server_type_t server_type,
|
||||
int num_req_mirrors)
|
||||
FTPS_Window::fetch_mirror_info(urlinfo * u, off_t file_size,
|
||||
char *ftps_loc,
|
||||
ftpsearch_server_type_t server_type,
|
||||
int num_req_mirrors)
|
||||
{
|
||||
assert (u->file);
|
||||
assert(u->file);
|
||||
|
||||
request = proz_ftps_request_init (u, file_size, ftps_loc,
|
||||
server_type, num_req_mirrors);
|
||||
PrintMessage("Attempting to get %d mirrors from %s\n\n",num_req_mirrors, ftps_loc);
|
||||
//proz_connection_set_msg_proc (request->connection,
|
||||
// ftps_win_message_proc, this);
|
||||
proz_get_complete_mirror_list (request);
|
||||
request = proz_ftps_request_init(u, file_size, ftps_loc,
|
||||
server_type, num_req_mirrors);
|
||||
PrintMessage("Attempting to get %d mirrors from %s\n\n", num_req_mirrors, ftps_loc);
|
||||
//proz_connection_set_msg_proc (request->connection,
|
||||
// ftps_win_message_proc, this);
|
||||
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
|
||||
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)
|
||||
{
|
||||
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;
|
||||
got_mirror_info = TRUE;
|
||||
|
||||
request_running = FALSE;
|
||||
got_mirror_info = TRUE;
|
||||
request->max_simul_pings = rt.max_simul_pings;
|
||||
request->ping_timeout.tv_sec = rt.max_ping_wait;
|
||||
request->ping_timeout.tv_usec = 0;
|
||||
|
||||
request->max_simul_pings = rt.max_simul_pings;
|
||||
request->ping_timeout.tv_sec = rt.max_ping_wait;
|
||||
request->ping_timeout.tv_usec = 0;
|
||||
//Launch the pinging thread
|
||||
PrintMessage("Got mirror info, %d server(s) found\n", request->num_mirrors);
|
||||
proz_mass_ping(request);
|
||||
ping_running = TRUE;
|
||||
return MASSPINGINPROGRESS;
|
||||
}
|
||||
return FTPSINPROGRESS;
|
||||
}
|
||||
|
||||
//Launch the pinging thread
|
||||
PrintMessage("Got mirror info, %d server(s) found\n", request->num_mirrors);
|
||||
proz_mass_ping (request);
|
||||
ping_running = TRUE;
|
||||
return MASSPINGINPROGRESS;
|
||||
}
|
||||
return FTPSINPROGRESS;
|
||||
}
|
||||
if (ping_running == TRUE)
|
||||
{
|
||||
print_status(request, rt.quiet_mode);
|
||||
|
||||
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)
|
||||
{
|
||||
ping_done = TRUE;
|
||||
ping_running = FALSE;
|
||||
proz_sort_mirror_list (request->mirrors,
|
||||
request->num_mirrors);
|
||||
|
||||
// We have a seprate func to display this
|
||||
print_status(request, FALSE);
|
||||
|
||||
return MASSPINGDONE;
|
||||
}
|
||||
return MASSPINGINPROGRESS;
|
||||
}
|
||||
return MASSPINGINPROGRESS;
|
||||
return MASSPINGDONE;
|
||||
}
|
||||
return MASSPINGINPROGRESS;
|
||||
}
|
||||
return MASSPINGINPROGRESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
FTPS_Window::cleanup ()
|
||||
FTPS_Window::cleanup()
|
||||
{
|
||||
if (request_running == TRUE)
|
||||
{
|
||||
proz_cancel_mirror_list_request (request);
|
||||
return;
|
||||
}
|
||||
if (request_running == TRUE)
|
||||
{
|
||||
proz_cancel_mirror_list_request(request);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ping_running == TRUE)
|
||||
{
|
||||
proz_cancel_mass_ping (request);
|
||||
return;
|
||||
}
|
||||
if (ping_running == TRUE)
|
||||
{
|
||||
proz_cancel_mass_ping(request);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
proz_cancel_mirror_list_request (window->request);
|
||||
}
|
||||
|
||||
if (window->ping_running == TRUE)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
pthread_mutex_lock (&request->access_mutex);
|
||||
ftp_mirror_stat_t status = request->mirrors[i].status;
|
||||
pthread_mutex_unlock (&request->access_mutex);
|
||||
switch (status)
|
||||
{
|
||||
case UNTESTED:
|
||||
DisplayInfo(i+1,1, "%-30.30s %s\n",
|
||||
request->mirrors[i].server_name,
|
||||
"NOT TESTED");
|
||||
break;
|
||||
case RESPONSEOK:
|
||||
DisplayInfo(i+1,1, "%-30.30s %dms\n",
|
||||
request->mirrors[i].server_name,
|
||||
request->mirrors[i].milli_secs);
|
||||
break;
|
||||
case NORESPONSE:
|
||||
case ERROR:
|
||||
DisplayInfo(i+1,1, "%-30.30s %s\n",
|
||||
request->mirrors[i].server_name,
|
||||
"NO REPONSE");
|
||||
break;
|
||||
default:
|
||||
DisplayInfo(i+1,1, "%-30.30s %s\n",
|
||||
request->mirrors[i].server_name,
|
||||
"Unkown condition!!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rt.display_mode == DISP_STDOUT)
|
||||
fprintf(stdout,"\n");
|
||||
for (int i = 0; i < request->num_mirrors; i++)
|
||||
{
|
||||
pthread_mutex_lock(&request->access_mutex);
|
||||
ftp_mirror_stat_t status = request->mirrors[i].status;
|
||||
pthread_mutex_unlock(&request->access_mutex);
|
||||
switch (status)
|
||||
{
|
||||
case UNTESTED:
|
||||
DisplayInfo(i + 1, 1, "%-30.30s %s\n",
|
||||
request->mirrors[i].server_name,
|
||||
"NOT TESTED");
|
||||
break;
|
||||
|
||||
}
|
||||
case RESPONSEOK:
|
||||
DisplayInfo(i + 1, 1, "%-30.30s %dms\n",
|
||||
request->mirrors[i].server_name,
|
||||
request->mirrors[i].milli_secs);
|
||||
break;
|
||||
|
||||
case NORESPONSE:
|
||||
case ERROR:
|
||||
DisplayInfo(i + 1, 1, "%-30.30s %s\n",
|
||||
request->mirrors[i].server_name,
|
||||
"NO REPONSE");
|
||||
break;
|
||||
|
||||
default:
|
||||
DisplayInfo(i + 1, 1, "%-30.30s %s\n",
|
||||
request->mirrors[i].server_name,
|
||||
"Unkown condition!!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rt.display_mode == DISP_STDOUT)
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef FTPSEARCH_WIN_H
|
||||
@ -29,27 +29,26 @@
|
||||
|
||||
class FTPS_Window {
|
||||
public:
|
||||
FTPS_Window();
|
||||
void fetch_mirror_info(urlinfo *u, off_t file_size, char *ftps_loc,
|
||||
ftpsearch_server_type_t server_type,
|
||||
int num_req_mirrors);
|
||||
FTPS_Window();
|
||||
void fetch_mirror_info(urlinfo *u, off_t file_size, char *ftps_loc,
|
||||
ftpsearch_server_type_t server_type,
|
||||
int num_req_mirrors);
|
||||
|
||||
void cleanup();
|
||||
void cleanup();
|
||||
|
||||
uerr_t callback();
|
||||
void ping_list();
|
||||
void print_status(ftps_request_t * request, int quiet_mode);
|
||||
uerr_t callback();
|
||||
void ping_list();
|
||||
void print_status(ftps_request_t * request, int quiet_mode);
|
||||
|
||||
ftps_request_t *request;
|
||||
ftps_request_t *request;
|
||||
|
||||
boolean request_running;
|
||||
boolean ping_running;
|
||||
boolean got_mirror_info;
|
||||
boolean ping_done;
|
||||
boolean exit_ftpsearch_button_pressed;
|
||||
boolean request_running;
|
||||
boolean ping_running;
|
||||
boolean got_mirror_info;
|
||||
boolean ping_done;
|
||||
boolean exit_ftpsearch_button_pressed;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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>
|
91
src/init.cpp
91
src/init.cpp
@ -1,27 +1,27 @@
|
||||
/******************************************************************************
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /*
|
||||
* HAVE_CONFIG_H
|
||||
*/
|
||||
#endif /*
|
||||
* HAVE_CONFIG_H
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -46,19 +46,19 @@ extern struct runtime rt;
|
||||
/* Sets the default config */
|
||||
void set_defaults()
|
||||
{
|
||||
|
||||
struct stat st;
|
||||
char cwd[PATH_MAX];
|
||||
|
||||
/*
|
||||
* Zero the structure which holds the config data
|
||||
*/
|
||||
memset(&rt, 0, sizeof(rt));
|
||||
|
||||
if (getcwd(cwd, sizeof(cwd)) == NULL)
|
||||
{
|
||||
proz_debug("Failed to get the current working directory");
|
||||
strcpy(cwd, ".");
|
||||
}
|
||||
{
|
||||
proz_debug("Failed to get the current working directory");
|
||||
strcpy(cwd, ".");
|
||||
}
|
||||
|
||||
if (rt.home_dir != 0)
|
||||
free(rt.home_dir);
|
||||
@ -67,25 +67,26 @@ void set_defaults()
|
||||
/*TODO what to do if the homedir is NULL */
|
||||
if (rt.config_dir != 0)
|
||||
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);
|
||||
/* Make the ~/.prozilla directory if necessary */
|
||||
|
||||
if (stat(rt.config_dir, &st) == -1)
|
||||
{
|
||||
/*error has hapenned */
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
/*Create the dir then */
|
||||
if (mkdir(rt.config_dir, S_IRWXU) != 0)
|
||||
{
|
||||
perror
|
||||
(_("unable to create the directory to store the config info in"));
|
||||
exit(0);
|
||||
}
|
||||
} else
|
||||
perror(_("Error while stating the config info directory"));
|
||||
}
|
||||
/*error has hapenned */
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
/*Create the dir then */
|
||||
if (mkdir(rt.config_dir, S_IRWXU) != 0)
|
||||
{
|
||||
perror
|
||||
(_("unable to create the directory to store the config info in"));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
perror(_("Error while stating the config info directory"));
|
||||
}
|
||||
|
||||
/*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
|
||||
*/
|
||||
rt.max_attempts = 0; /*TODO it is currently UNLIMITED */
|
||||
rt.retry_delay = 15; /*
|
||||
* delay in seconds
|
||||
*/
|
||||
rt.max_attempts = 0; /*TODO it is currently UNLIMITED */
|
||||
rt.retry_delay = 15; /*
|
||||
* delay in seconds
|
||||
*/
|
||||
|
||||
/*Default is to not log any debug info */
|
||||
rt.debug_mode = FALSE;
|
||||
rt.quiet_mode = TRUE;
|
||||
rt.libdebug_mode = TRUE;
|
||||
rt.ftp_search = FALSE;
|
||||
rt.min_search_size=128;
|
||||
rt.min_search_size = 128;
|
||||
rt.max_simul_pings = 5;
|
||||
rt.max_ping_wait = 8;
|
||||
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)
|
||||
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->passwd = strdup("");
|
||||
rt.http_proxy->type = HTTPPROXY;
|
||||
@ -154,7 +155,7 @@ void set_defaults()
|
||||
|
||||
if (rt.ftp_proxy != 0)
|
||||
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->passwd = strdup("");
|
||||
rt.ftp_proxy->type = HTTPPROXY;
|
||||
@ -201,7 +202,6 @@ void set_runtime_values()
|
||||
|
||||
void cleanuprt()
|
||||
{
|
||||
|
||||
if (rt.config_dir != 0)
|
||||
free(rt.config_dir);
|
||||
|
||||
@ -222,5 +222,4 @@ void cleanuprt()
|
||||
|
||||
if (rt.logfile_dir != 0)
|
||||
free(rt.logfile_dir);
|
||||
|
||||
}
|
||||
}
|
||||
|
344
src/interface.c
344
src/interface.c
@ -17,9 +17,9 @@
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /*
|
||||
* HAVE_CONFIG_H
|
||||
*/
|
||||
#endif /*
|
||||
* HAVE_CONFIG_H
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
@ -31,9 +31,9 @@
|
||||
#include <ncurses.h>
|
||||
#else
|
||||
#include <curses.h>
|
||||
#endif /*
|
||||
* HAVE_CURSES
|
||||
*/
|
||||
#endif /*
|
||||
* HAVE_CURSES
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
@ -47,7 +47,7 @@
|
||||
/* This is used to convert the connection.status enums to a user
|
||||
* friendly text message */
|
||||
/* the enums are defined in connection.h and are as belor
|
||||
*typedef enum {
|
||||
*typedef enum {
|
||||
* IDLE = 0,
|
||||
* CONNECTING,
|
||||
* LOGGININ,
|
||||
@ -57,26 +57,26 @@
|
||||
* CONREJECTED,
|
||||
* REMOTEFATAL,
|
||||
* LOCALFATAL
|
||||
*} dl_status;
|
||||
**} dl_status;
|
||||
*
|
||||
* And here are the texts for the above enums.
|
||||
*/
|
||||
*/
|
||||
const char *dl_status_txt[] = {
|
||||
"Idle",
|
||||
"Connecting",
|
||||
"Logging in",
|
||||
"Downloading",
|
||||
"Completed",
|
||||
"Idle",
|
||||
"Connecting",
|
||||
"Logging in",
|
||||
"Downloading",
|
||||
"Completed",
|
||||
/* I have decided to change the login failed message
|
||||
* to something else like "login rejected" because people
|
||||
* might get alarmed and abort the download rather than
|
||||
* letting prozilla handle it */
|
||||
"Login Denied",
|
||||
"Connect Refused",
|
||||
"Remote Fatal",
|
||||
"Local Fatal",
|
||||
"Timed Out",
|
||||
"Max attempts reached",
|
||||
"Login Denied",
|
||||
"Connect Refused",
|
||||
"Remote Fatal",
|
||||
"Local Fatal",
|
||||
"Timed Out",
|
||||
"Max attempts reached",
|
||||
};
|
||||
|
||||
#define CTRL(x) ((x) & 0x1F)
|
||||
@ -109,120 +109,117 @@ int messageCol = 0;
|
||||
* 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 */
|
||||
void curses_message(char *message)
|
||||
{
|
||||
short i;
|
||||
int x, y;
|
||||
attr_t attrs;
|
||||
/*
|
||||
* Lock the mutex
|
||||
*/
|
||||
pthread_mutex_lock(&curses_msg_mutex);
|
||||
short i;
|
||||
int x, y;
|
||||
attr_t attrs;
|
||||
|
||||
/*
|
||||
* Lock the mutex
|
||||
*/
|
||||
pthread_mutex_lock(&curses_msg_mutex);
|
||||
|
||||
|
||||
/*
|
||||
* get the cursor position
|
||||
*/
|
||||
getyx(stdscr, y, x);
|
||||
kwattr_get(stdscr, &attrs, &i, NULL);
|
||||
move(messageRow-1, 0);
|
||||
clrtoeol();
|
||||
move(messageRow, 0);
|
||||
clrtoeol();
|
||||
move(messageRow+1, 0);
|
||||
clrtoeol();
|
||||
attrset(COLOR_PAIR(MSG_PAIR) | A_BOLD);
|
||||
mvprintw(messageRow, 0, "%s", message);
|
||||
attrset(COLOR_PAIR(NULL_PAIR));
|
||||
/*
|
||||
* Unlock the mutex
|
||||
*/
|
||||
refresh();
|
||||
kwattr_set(stdscr, attrs, i, NULL);
|
||||
/*
|
||||
* set the cursor to whhere it was */
|
||||
|
||||
move(y, x);
|
||||
pthread_mutex_unlock(&curses_msg_mutex);
|
||||
/*
|
||||
* get the cursor position
|
||||
*/
|
||||
getyx(stdscr, y, x);
|
||||
kwattr_get(stdscr, &attrs, &i, NULL);
|
||||
move(messageRow - 1, 0);
|
||||
clrtoeol();
|
||||
move(messageRow, 0);
|
||||
clrtoeol();
|
||||
move(messageRow + 1, 0);
|
||||
clrtoeol();
|
||||
attrset(COLOR_PAIR(MSG_PAIR) | A_BOLD);
|
||||
mvprintw(messageRow, 0, "%s", message);
|
||||
attrset(COLOR_PAIR(NULL_PAIR));
|
||||
/*
|
||||
* Unlock the mutex
|
||||
*/
|
||||
refresh();
|
||||
kwattr_set(stdscr, attrs, i, NULL);
|
||||
/*
|
||||
* set the cursor to whhere it was */
|
||||
|
||||
move(y, x);
|
||||
pthread_mutex_unlock(&curses_msg_mutex);
|
||||
}
|
||||
|
||||
|
||||
/* Displays the mesasge and gets the users input for overwriting files*/
|
||||
int curses_query_user_input(const char *args, ...)
|
||||
{
|
||||
char p[MAX_MSG_SIZE+1];
|
||||
va_list vp;
|
||||
attr_t attrs;
|
||||
int x, y;
|
||||
int ch;
|
||||
int i;
|
||||
char p[MAX_MSG_SIZE + 1];
|
||||
va_list vp;
|
||||
attr_t attrs;
|
||||
int x, y;
|
||||
int ch;
|
||||
int i;
|
||||
|
||||
va_start(vp, args);
|
||||
vsnprintf(p,sizeof(p) , args, vp);
|
||||
va_end(vp);
|
||||
getyx(stdscr, y, x);
|
||||
kwattr_get(stdscr, &attrs, &i, NULL);
|
||||
va_start(vp, args);
|
||||
vsnprintf(p, sizeof(p), args, vp);
|
||||
va_end(vp);
|
||||
getyx(stdscr, y, x);
|
||||
kwattr_get(stdscr, &attrs, &i, NULL);
|
||||
|
||||
attrset(COLOR_PAIR(PROMPT_PAIR) | A_BOLD);
|
||||
move(19, 0);
|
||||
clrtoeol();
|
||||
move(20, 0);
|
||||
clrtoeol();
|
||||
move(21, 0);
|
||||
clrtoeol();
|
||||
mvprintw(19, 0, "%s", p);
|
||||
echo();
|
||||
refresh();
|
||||
do
|
||||
attrset(COLOR_PAIR(PROMPT_PAIR) | A_BOLD);
|
||||
move(19, 0);
|
||||
clrtoeol();
|
||||
move(20, 0);
|
||||
clrtoeol();
|
||||
move(21, 0);
|
||||
clrtoeol();
|
||||
mvprintw(19, 0, "%s", p);
|
||||
echo();
|
||||
refresh();
|
||||
do
|
||||
{
|
||||
napms(20);
|
||||
ch = getch();
|
||||
}
|
||||
while (ch == ERR);
|
||||
napms(20);
|
||||
ch = getch();
|
||||
} while (ch == ERR);
|
||||
|
||||
refresh();
|
||||
noecho();
|
||||
kwattr_set(stdscr, attrs, i, NULL);
|
||||
/*
|
||||
* set the cursor to where it was
|
||||
*/
|
||||
move(y, x);
|
||||
/*
|
||||
* the following strange line is for compatibility
|
||||
*/
|
||||
return islower(ch) ? toupper(ch) : ch;
|
||||
refresh();
|
||||
noecho();
|
||||
kwattr_set(stdscr, attrs, i, NULL);
|
||||
/*
|
||||
* set the cursor to where it was
|
||||
*/
|
||||
move(y, x);
|
||||
/*
|
||||
* the following strange line is for compatibility
|
||||
*/
|
||||
return islower(ch) ? toupper(ch) : ch;
|
||||
}
|
||||
|
||||
|
||||
void initCurses()
|
||||
{
|
||||
initscr();
|
||||
keypad(stdscr, TRUE);
|
||||
start_color();
|
||||
noecho();
|
||||
nodelay(stdscr, TRUE);
|
||||
init_pair(HIGHLIGHT_PAIR, COLOR_GREEN, COLOR_BLACK);
|
||||
init_pair(MSG_PAIR, COLOR_YELLOW, COLOR_BLUE);
|
||||
init_pair(WARN_PAIR, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(PROMPT_PAIR, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(SELECTED_PAIR, COLOR_WHITE, COLOR_BLUE);
|
||||
getmaxyx(stdscr,maxRow,maxCol);
|
||||
messageRow = maxRow - 2;
|
||||
messageCol = 1;
|
||||
initscr();
|
||||
keypad(stdscr, TRUE);
|
||||
start_color();
|
||||
noecho();
|
||||
nodelay(stdscr, TRUE);
|
||||
init_pair(HIGHLIGHT_PAIR, COLOR_GREEN, COLOR_BLACK);
|
||||
init_pair(MSG_PAIR, COLOR_YELLOW, COLOR_BLUE);
|
||||
init_pair(WARN_PAIR, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(PROMPT_PAIR, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(SELECTED_PAIR, COLOR_WHITE, COLOR_BLUE);
|
||||
getmaxyx(stdscr, maxRow, maxCol);
|
||||
messageRow = maxRow - 2;
|
||||
messageCol = 1;
|
||||
}
|
||||
|
||||
void shutdownCurses()
|
||||
{
|
||||
|
||||
endwin();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -231,22 +228,22 @@ void PrintMessage(const char *format, ...)
|
||||
va_list args;
|
||||
char message[MAX_MSG_SIZE + 1 + 1];
|
||||
|
||||
va_start(args, format);
|
||||
vsnprintf((char *) &message, MAX_MSG_SIZE, format, args);
|
||||
va_end(args);
|
||||
va_start(args, format);
|
||||
vsnprintf((char *)&message, MAX_MSG_SIZE, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (rt.display_mode == DISP_CURSES)
|
||||
{
|
||||
curses_message(message);
|
||||
{
|
||||
curses_message(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fwrite(message, 1, strlen(message), stdout) != strlen(message))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
delay_ms(500);
|
||||
{
|
||||
if (fwrite(message, 1, strlen(message), stdout) != strlen(message))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
delay_ms(500);
|
||||
}
|
||||
|
||||
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;
|
||||
char message[MAX_MSG_SIZE + 1 + 1];
|
||||
|
||||
va_start(args, format);
|
||||
vsnprintf((char *) &message, MAX_MSG_SIZE, format, args);
|
||||
va_end(args);
|
||||
va_start(args, format);
|
||||
vsnprintf((char *)&message, MAX_MSG_SIZE, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (rt.display_mode == DISP_CURSES)
|
||||
{
|
||||
attrset(COLOR_PAIR(NULL_PAIR) | A_BOLD);
|
||||
mvaddstr(row,col, message);
|
||||
attrset(COLOR_PAIR(NULL_PAIR));
|
||||
{
|
||||
attrset(COLOR_PAIR(NULL_PAIR) | A_BOLD);
|
||||
mvaddstr(row, col, message);
|
||||
attrset(COLOR_PAIR(NULL_PAIR));
|
||||
|
||||
refresh();
|
||||
refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fwrite(message, 1, strlen(message), stdout) != strlen(message))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (fwrite(message, 1, strlen(message), stdout) != strlen(message))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
// delay_ms(300);
|
||||
}
|
||||
|
||||
void DisplayCursesInfo(download_t * download )
|
||||
void DisplayCursesInfo(download_t * download)
|
||||
{
|
||||
char buf[1000];
|
||||
int i = 0;
|
||||
int line = 1;
|
||||
int secs_left;
|
||||
|
||||
// erase();
|
||||
refresh();
|
||||
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
|
||||
snprintf(buf, sizeof(buf), _("Connection Server Status Received"));
|
||||
mvprintw(line++,1, buf);
|
||||
refresh();
|
||||
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
|
||||
snprintf(buf, sizeof(buf), _("Connection Server Status Received"));
|
||||
mvprintw(line++, 1, buf);
|
||||
|
||||
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);
|
||||
bytes_got_last_time = total_bytes_got;
|
||||
start = 0;
|
||||
}
|
||||
|
||||
if (time_stamp + 1 == time(NULL))
|
||||
if (time_stamp + 1 == time(NULL))
|
||||
{
|
||||
current_dl_speed = total_bytes_got - bytes_got_last_time;
|
||||
time_stamp = time(NULL);
|
||||
@ -308,57 +306,57 @@ void DisplayCursesInfo(download_t * download )
|
||||
|
||||
for (i = 0; i < download->num_connections; i++)
|
||||
{
|
||||
snprintf(buf,sizeof(buf), _(" %2d %-25.25s %-15.15s %10.1fK of %.1fK"), i + 1,
|
||||
download->pconnections[i]->u.host,
|
||||
proz_connection_get_status_string(download->pconnections[i]),
|
||||
(float)proz_connection_get_total_bytes_got(download->
|
||||
pconnections[i])/1024,
|
||||
((float)download->pconnections[i]->main_file_size / 1024) / download->num_connections);
|
||||
mvprintw(line++,1, buf);
|
||||
snprintf(buf, sizeof(buf), _(" %2d %-25.25s %-15.15s %10.1fK of %.1fK"), i + 1,
|
||||
download->pconnections[i]->u.host,
|
||||
proz_connection_get_status_string(download->pconnections[i]),
|
||||
(float)proz_connection_get_total_bytes_got(download->
|
||||
pconnections[i]) / 1024,
|
||||
((float)download->pconnections[i]->main_file_size / 1024) / download->num_connections);
|
||||
mvprintw(line++, 1, buf);
|
||||
}
|
||||
|
||||
line = line + 2;
|
||||
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
|
||||
mvprintw(line++, 1, "%s", download->u.url);
|
||||
line++;
|
||||
line = line + 2;
|
||||
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
|
||||
mvprintw(line++, 1, "%s", download->u.url);
|
||||
line++;
|
||||
|
||||
attrset(COLOR_PAIR(HIGHLIGHT_PAIR));
|
||||
if (download->main_file_size > 0)
|
||||
mvprintw(line++,1,_("File Size = %lldK"),download->main_file_size / 1024);
|
||||
else
|
||||
mvprintw(line++,1,_("File Size = UNKNOWN"));
|
||||
attrset(COLOR_PAIR(HIGHLIGHT_PAIR));
|
||||
if (download->main_file_size > 0)
|
||||
mvprintw(line++, 1, _("File Size = %lldK"), download->main_file_size / 1024);
|
||||
else
|
||||
mvprintw(line++, 1, _("File Size = UNKNOWN"));
|
||||
|
||||
snprintf(buf,sizeof(buf), _("Total Bytes received %lld Kb (%.2f%%)"),
|
||||
total_bytes_got,
|
||||
(((float)total_bytes_got * 100) / ((float)download->main_file_size / 1024)));
|
||||
line++;
|
||||
mvprintw(line++,1, buf);
|
||||
snprintf(buf, sizeof(buf), _("Total Bytes received %lld Kb (%.2f%%)"),
|
||||
total_bytes_got,
|
||||
(((float)total_bytes_got * 100) / ((float)download->main_file_size / 1024)));
|
||||
line++;
|
||||
mvprintw(line++, 1, buf);
|
||||
|
||||
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);
|
||||
mvprintw(line++,1, buf);
|
||||
clrtoeol();
|
||||
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);
|
||||
mvprintw(line++, 1, buf);
|
||||
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)
|
||||
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)
|
||||
snprintf(buf,sizeof(buf), _("Time Remaining %d Minutes %d Seconds"), secs_left / 60,
|
||||
secs_left % 60);
|
||||
snprintf(buf, sizeof(buf), _("Time Remaining %d Minutes %d Seconds"), secs_left / 60,
|
||||
secs_left % 60);
|
||||
else
|
||||
snprintf(buf,sizeof(buf), _("Time Remaining %d Hours %d minutes"), secs_left / 3600,
|
||||
(secs_left % 3600) / 60);
|
||||
snprintf(buf, sizeof(buf), _("Time Remaining %d Hours %d minutes"), secs_left / 3600,
|
||||
(secs_left % 3600) / 60);
|
||||
|
||||
mvprintw(line++,1, buf);
|
||||
mvprintw(line++, 1, buf);
|
||||
clrtoeol();
|
||||
line++;
|
||||
|
||||
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
|
||||
if (download->resume_support)
|
||||
mvprintw(line++,1,_("Resume Supported"));
|
||||
mvprintw(line++, 1, _("Resume Supported"));
|
||||
else
|
||||
mvprintw(line++,1,_("Resume NOT Supported"));
|
||||
mvprintw(line++, 1, _("Resume NOT Supported"));
|
||||
}
|
||||
attrset(COLOR_PAIR(NULL_PAIR));
|
||||
refresh();
|
||||
|
@ -26,12 +26,12 @@ extern "C" {
|
||||
|
||||
/*definnitions about the ncurse colors that the app will use*/
|
||||
enum {
|
||||
NULL_PAIR = 0,
|
||||
HIGHLIGHT_PAIR,
|
||||
MSG_PAIR,
|
||||
WARN_PAIR,
|
||||
PROMPT_PAIR,
|
||||
SELECTED_PAIR
|
||||
NULL_PAIR = 0,
|
||||
HIGHLIGHT_PAIR,
|
||||
MSG_PAIR,
|
||||
WARN_PAIR,
|
||||
PROMPT_PAIR,
|
||||
SELECTED_PAIR
|
||||
};
|
||||
|
||||
void initCurses();
|
||||
|
871
src/main.cpp
871
src/main.cpp
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
@ -47,39 +47,39 @@ struct runtime rt;
|
||||
// structure for options parsing,
|
||||
|
||||
struct option long_opts[] = {
|
||||
/*
|
||||
* { name has_arg *flag val }
|
||||
*/
|
||||
{"resume", no_argument, NULL, 'r'},
|
||||
/*
|
||||
* { name has_arg *flag val }
|
||||
*/
|
||||
{ "resume", no_argument, NULL, 'r' },
|
||||
/* {"connections", required_argument, NULL, 'c'},*/
|
||||
{"license", no_argument, NULL, 'L'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"gtk", no_argument, NULL, 'g'},
|
||||
{"no-netrc", no_argument, NULL, 'n'},
|
||||
{"tries", required_argument, NULL, 't'},
|
||||
{"force", no_argument, NULL, 'f'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"output-document", required_argument, NULL, 'O'},
|
||||
{"directory-prefix", required_argument, NULL, 'P'},
|
||||
{"use-port", no_argument, NULL, 129},
|
||||
{"retry-delay", required_argument, NULL, 130},
|
||||
{"timeout", required_argument, NULL, 131},
|
||||
{"no-getch", no_argument, NULL, 132},
|
||||
{"debug", no_argument, NULL, 133},
|
||||
{"ftpsearch", no_argument, NULL, 's'},
|
||||
{"no-search", no_argument, NULL, 135},
|
||||
{"pt", required_argument, NULL, 136},
|
||||
{"pao", required_argument, NULL, 137},
|
||||
{"max-ftps-servers", required_argument, NULL, 138},
|
||||
{"max-bps", required_argument, NULL, 139},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{"no-curses", no_argument, NULL, 140},
|
||||
{"min-size",required_argument,NULL,141},
|
||||
{"ftpsid", required_argument, NULL,142},
|
||||
{0, 0, 0, 0}
|
||||
{ "license", no_argument, NULL, 'L' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "gtk", no_argument, NULL, 'g' },
|
||||
{ "no-netrc", no_argument, NULL, 'n' },
|
||||
{ "tries", required_argument, NULL, 't' },
|
||||
{ "force", no_argument, NULL, 'f' },
|
||||
{ "version", no_argument, NULL, 'v' },
|
||||
{ "output-document", required_argument, NULL, 'O' },
|
||||
{ "directory-prefix", required_argument, NULL, 'P' },
|
||||
{ "use-port", no_argument, NULL, 129 },
|
||||
{ "retry-delay", required_argument, NULL, 130 },
|
||||
{ "timeout", required_argument, NULL, 131 },
|
||||
{ "no-getch", no_argument, NULL, 132 },
|
||||
{ "debug", no_argument, NULL, 133 },
|
||||
{ "ftpsearch", no_argument, NULL, 's' },
|
||||
{ "no-search", no_argument, NULL, 135 },
|
||||
{ "pt", required_argument, NULL, 136 },
|
||||
{ "pao", required_argument, NULL, 137 },
|
||||
{ "max-ftps-servers", required_argument, NULL, 138 },
|
||||
{ "max-bps", required_argument, NULL, 139 },
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "no-curses", no_argument, NULL, 140 },
|
||||
{ "min-size", required_argument, NULL, 141 },
|
||||
{ "ftpsid", required_argument, NULL, 142 },
|
||||
{ 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;
|
||||
|
||||
@ -89,87 +89,87 @@ extern int nextchar;
|
||||
|
||||
/* displays the software license */
|
||||
void
|
||||
license (void)
|
||||
license(void)
|
||||
{
|
||||
fprintf (stderr,
|
||||
" Copyright (C) 2000 Kalum Somaratna\n"
|
||||
"\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"
|
||||
" the Free Software Foundation; either version 2, or (at your option)\n"
|
||||
" any later version.\n"
|
||||
"\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"
|
||||
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||
" GNU General Public License for more details.\n"
|
||||
"\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"
|
||||
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n");
|
||||
fprintf(stderr,
|
||||
" Copyright (C) 2000 Kalum Somaratna\n"
|
||||
"\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"
|
||||
" the Free Software Foundation; either version 2, or (at your option)\n"
|
||||
" any later version.\n"
|
||||
"\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"
|
||||
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||
" GNU General Public License for more details.\n"
|
||||
"\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"
|
||||
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n");
|
||||
}
|
||||
|
||||
|
||||
/* displays the help message */
|
||||
|
||||
void
|
||||
help (void)
|
||||
help(void)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Usage: proz [OPTIONS] file_url\n"
|
||||
"\n"
|
||||
"Ex: proz http://gnu.org/gnu.jpg\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -h, --help Give this help\n"
|
||||
" -r, --resume Resume an interrupted download\n"
|
||||
" -f, --force Never prompt the user when overwriting files\n"
|
||||
" -1 Force a single connection only\n"
|
||||
" -n, --no-netrc Don't use .netrc, get the user/password\n"
|
||||
" from the command line,otherwise use the\n"
|
||||
" anonymous login for FTP sessions\n"
|
||||
" --no-getch Instead of waiting for the user pressing a key,\n"
|
||||
" print the error to stdout and quit\n"
|
||||
" --debug Log debugging info to a file (default is debug.log)\n"
|
||||
" -v,--verbose Increase the amount of information sent to stdout\n"
|
||||
" --no-curses Don't use Curses, plain text to stdout\n"
|
||||
"\n"
|
||||
"Files:\n"
|
||||
" -O, --output-document=FILE write documents to FILE\n"
|
||||
"\n"
|
||||
"Directories:\n"
|
||||
" -P, --directory-prefix=DIR save the generated file to DIR/\n"
|
||||
"\n"
|
||||
"FTP Options:\n"
|
||||
" --use-port Force usage of PORT insted of PASV (default)\n"
|
||||
" for ftp transactions\n"
|
||||
"\n"
|
||||
"Download Options:\n"
|
||||
" -s, --ftpsearch Do a ftpsearch for faster mirrors\n"
|
||||
" --no-search Do a direct download (no ftpsearch)\n"
|
||||
" -k=n Use n connections instead of the default(4)\n"
|
||||
" --timeout=n Set the timeout for connections to n seconds\n"
|
||||
" (default 180)\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"
|
||||
" (default 15 seconds)\n"
|
||||
" --max-bps=n Limit bandwith consumed to n bps (0=unlimited)\n"
|
||||
"\n"
|
||||
"FTP Search Options:\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"
|
||||
" --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"
|
||||
" --ftpsid=n The ftpsearch server to use\n"
|
||||
" (0=filesearching.com\n"
|
||||
" 1=ftpsearch.elmundo.es\n"
|
||||
"\n"
|
||||
"Information Options:\n"
|
||||
" -L, --license Display software license\n"
|
||||
" -V, --version Display version number\n"
|
||||
"\n"
|
||||
"ProZilla homepage: http://prozilla.genesys.ro\n"
|
||||
"Please report bugs to <prozilla@genesys.ro>\n");
|
||||
fprintf(stderr,
|
||||
"Usage: proz [OPTIONS] file_url\n"
|
||||
"\n"
|
||||
"Ex: proz http://gnu.org/gnu.jpg\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -h, --help Give this help\n"
|
||||
" -r, --resume Resume an interrupted download\n"
|
||||
" -f, --force Never prompt the user when overwriting files\n"
|
||||
" -1 Force a single connection only\n"
|
||||
" -n, --no-netrc Don't use .netrc, get the user/password\n"
|
||||
" from the command line,otherwise use the\n"
|
||||
" anonymous login for FTP sessions\n"
|
||||
" --no-getch Instead of waiting for the user pressing a key,\n"
|
||||
" print the error to stdout and quit\n"
|
||||
" --debug Log debugging info to a file (default is debug.log)\n"
|
||||
" -v,--verbose Increase the amount of information sent to stdout\n"
|
||||
" --no-curses Don't use Curses, plain text to stdout\n"
|
||||
"\n"
|
||||
"Files:\n"
|
||||
" -O, --output-document=FILE write documents to FILE\n"
|
||||
"\n"
|
||||
"Directories:\n"
|
||||
" -P, --directory-prefix=DIR save the generated file to DIR/\n"
|
||||
"\n"
|
||||
"FTP Options:\n"
|
||||
" --use-port Force usage of PORT insted of PASV (default)\n"
|
||||
" for ftp transactions\n"
|
||||
"\n"
|
||||
"Download Options:\n"
|
||||
" -s, --ftpsearch Do a ftpsearch for faster mirrors\n"
|
||||
" --no-search Do a direct download (no ftpsearch)\n"
|
||||
" -k=n Use n connections instead of the default(4)\n"
|
||||
" --timeout=n Set the timeout for connections to n seconds\n"
|
||||
" (default 180)\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"
|
||||
" (default 15 seconds)\n"
|
||||
" --max-bps=n Limit bandwith consumed to n bps (0=unlimited)\n"
|
||||
"\n"
|
||||
"FTP Search Options:\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"
|
||||
" --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"
|
||||
" --ftpsid=n The ftpsearch server to use\n"
|
||||
" (0=filesearching.com\n"
|
||||
" 1=ftpsearch.elmundo.es\n"
|
||||
"\n"
|
||||
"Information Options:\n"
|
||||
" -L, --license Display software license\n"
|
||||
" -V, --version Display version number\n"
|
||||
"\n"
|
||||
"ProZilla homepage: http://prozilla.genesys.ro\n"
|
||||
"Please report bugs to <prozilla@genesys.ro>\n");
|
||||
}
|
||||
|
||||
|
||||
@ -177,381 +177,396 @@ help (void)
|
||||
/* Displays the version */
|
||||
|
||||
void
|
||||
version (void)
|
||||
version(void)
|
||||
{
|
||||
fprintf (stderr, _("%s. Version: %s\n"), PACKAGE_NAME, VERSION);
|
||||
fprintf(stderr, _("%s. Version: %s\n"), PACKAGE_NAME, VERSION);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
ms (const char *msg, void *cb_data)
|
||||
ms(const char *msg, void *cb_data)
|
||||
{
|
||||
PrintMessage("%s\n",msg);
|
||||
PrintMessage("%s\n", msg);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
delay_ms (700); //wait before checking the status again...
|
||||
dl_win->my_cb ();
|
||||
}
|
||||
//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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return((dl_win->status==DL_DONE) ? 1:-1);
|
||||
// delete (dl_win);
|
||||
return((dl_win->status == DL_DONE) ? 1 : -1);
|
||||
// delete (dl_win);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
int ret;
|
||||
char *opt_file = NULL;
|
||||
proz_init (argc, argv); //init libprozilla
|
||||
set_defaults (); //set some reasonable defaults
|
||||
load_prefs (); //load values from the config file
|
||||
int c;
|
||||
int ret;
|
||||
char *opt_file = NULL;
|
||||
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "?hvrfk:1Lt:VgsP:O:", long_opts,
|
||||
NULL)) != EOF)
|
||||
{
|
||||
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);
|
||||
}
|
||||
proz_init(argc, argv); //init libprozilla
|
||||
set_defaults(); //set some reasonable defaults
|
||||
load_prefs(); //load values from the config file
|
||||
|
||||
if (rt.num_connections == 0)
|
||||
{
|
||||
printf (_("Hey! How can I download anything with 0 (Zero)" " connections!?\n" "Please type proz --help for help\n"));
|
||||
exit (0);
|
||||
}
|
||||
while ((c =
|
||||
getopt_long(argc, argv, "?hvrfk:1Lt:VgsP:O:", long_opts,
|
||||
NULL)) != EOF)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'L':
|
||||
license();
|
||||
exit(0);
|
||||
|
||||
break;
|
||||
case 't':
|
||||
if (setargval (optarg, &rt.max_attempts) != 1)
|
||||
{
|
||||
/*
|
||||
* 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 'h':
|
||||
help();
|
||||
exit(0);
|
||||
|
||||
case 'g':
|
||||
/*
|
||||
* TODO solve this soon
|
||||
*/
|
||||
printf ("Error: GTK interface is not supported in "
|
||||
"the development version currently\n");
|
||||
exit (0);
|
||||
break;
|
||||
case 'V':
|
||||
version();
|
||||
exit(0);
|
||||
|
||||
case 129:
|
||||
/*
|
||||
* lets use PORT as the default then
|
||||
*/
|
||||
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 'r':
|
||||
rt.resume_mode = RESUME;
|
||||
break;
|
||||
|
||||
case 133:
|
||||
/* --debug option */
|
||||
rt.debug_mode = TRUE;
|
||||
rt.libdebug_mode=TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
rt.force_mode = TRUE;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
/* --verbose option */
|
||||
rt.quiet_mode = FALSE;
|
||||
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);
|
||||
}
|
||||
|
||||
case 's':
|
||||
/* --ftpsearch option */
|
||||
rt.ftp_search = TRUE;
|
||||
break;
|
||||
if (rt.num_connections == 0)
|
||||
{
|
||||
printf(_("Hey! How can I download anything with 0 (Zero)" " connections!?\n" "Please type proz --help for help\n"));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
case 135:
|
||||
/* --no-search option */
|
||||
rt.ftp_search = FALSE;
|
||||
break;
|
||||
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);
|
||||
}
|
||||
case 't':
|
||||
if (setargval(optarg, &rt.max_attempts) != 1)
|
||||
{
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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);
|
||||
}
|
||||
case 'n':
|
||||
/*
|
||||
* Don't use ~/.netrc"
|
||||
*/
|
||||
rt.use_netrc = FALSE;
|
||||
break;
|
||||
|
||||
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);
|
||||
}
|
||||
case 'O':
|
||||
/*
|
||||
* Output file name
|
||||
*/
|
||||
opt_file = kstrdup(optarg);
|
||||
break;
|
||||
|
||||
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);
|
||||
}
|
||||
case 'P':
|
||||
/*
|
||||
* Save the downloaded file to DIR
|
||||
*/
|
||||
rt.output_dir = kstrdup(optarg);
|
||||
break;
|
||||
|
||||
break;
|
||||
case '?':
|
||||
help();
|
||||
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);
|
||||
}
|
||||
case '1':
|
||||
rt.num_connections = 1;
|
||||
break;
|
||||
|
||||
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);
|
||||
}
|
||||
case 'g':
|
||||
/*
|
||||
* TODO solve this soon
|
||||
*/
|
||||
printf("Error: GTK interface is not supported in "
|
||||
"the development version currently\n");
|
||||
exit(0);
|
||||
break;
|
||||
|
||||
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 129:
|
||||
/*
|
||||
* lets use PORT as the default then
|
||||
*/
|
||||
rt.ftp_use_pasv = FALSE;
|
||||
break;
|
||||
|
||||
case 142:
|
||||
/* --ftpsid */
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
case 132:
|
||||
/* --no-getch option */
|
||||
rt.dont_prompt = TRUE;
|
||||
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:
|
||||
printf (_("Error: Invalid option\n"));
|
||||
exit (0);
|
||||
}
|
||||
}
|
||||
default:
|
||||
printf(_("Error: Invalid option\n"));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
set_runtime_values (); //tell libprozilla about any changed settings
|
||||
set_runtime_values(); //tell libprozilla about any changed settings
|
||||
|
||||
if (optind == argc)
|
||||
{
|
||||
help ();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Gettext stuff */
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
if (optind == argc)
|
||||
{
|
||||
help();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Gettext stuff */
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
|
||||
/*delete the ~/.prozilla/debug.log file if present at the start of each run */
|
||||
proz_debug_delete_log ();
|
||||
/*delete the ~/.prozilla/debug.log file if present at the start of each run */
|
||||
proz_debug_delete_log();
|
||||
|
||||
if (rt.display_mode == DISP_CURSES)
|
||||
initCurses();
|
||||
if (rt.display_mode == DISP_CURSES)
|
||||
initCurses();
|
||||
|
||||
/* 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++)
|
||||
{
|
||||
uerr_t err;
|
||||
urlinfo *url_data;
|
||||
url_data = (urlinfo *) malloc (sizeof (urlinfo));
|
||||
memset (url_data, 0, sizeof (urlinfo));
|
||||
/* 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++)
|
||||
{
|
||||
uerr_t err;
|
||||
urlinfo *url_data;
|
||||
url_data = (urlinfo *)malloc(sizeof(urlinfo));
|
||||
memset(url_data, 0, sizeof(urlinfo));
|
||||
|
||||
//parses and validates the command-line parm
|
||||
err = proz_parse_url (argv[i], url_data, 0);
|
||||
if (err != URLOK)
|
||||
{
|
||||
PrintMessage (_
|
||||
("%s does not seem to be a valid URL"),
|
||||
argv[optind]);
|
||||
proz_debug
|
||||
("%s does not seem to be a valid URL",
|
||||
argv[optind]);
|
||||
if(url_data)
|
||||
free(url_data);
|
||||
shutdown();
|
||||
exit (0);
|
||||
}
|
||||
//parses and validates the command-line parm
|
||||
err = proz_parse_url(argv[i], url_data, 0);
|
||||
if (err != URLOK)
|
||||
{
|
||||
PrintMessage(_
|
||||
("%s does not seem to be a valid URL"),
|
||||
argv[optind]);
|
||||
proz_debug
|
||||
("%s does not seem to be a valid URL",
|
||||
argv[optind]);
|
||||
if (url_data)
|
||||
free(url_data);
|
||||
shutdown();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (opt_file)
|
||||
url_data->file=opt_file;
|
||||
if (opt_file)
|
||||
url_data->file = opt_file;
|
||||
|
||||
PrintMessage("Starting.....");
|
||||
//In to %s\n",url_data->host);
|
||||
// start the download
|
||||
ret=open_new_dl_win (url_data, rt.ftp_search);
|
||||
/*If the download failed the return -1 */
|
||||
if(ret==-1)
|
||||
{
|
||||
if(url_data)
|
||||
free(url_data);
|
||||
if(dl_win)
|
||||
delete(dl_win);
|
||||
shutdown();
|
||||
return -1;
|
||||
}
|
||||
if(dl_win)
|
||||
delete(dl_win);
|
||||
if(url_data)
|
||||
free (url_data);
|
||||
}
|
||||
}
|
||||
PrintMessage("Starting.....");
|
||||
//In to %s\n",url_data->host);
|
||||
// start the download
|
||||
ret = open_new_dl_win(url_data, rt.ftp_search);
|
||||
/*If the download failed the return -1 */
|
||||
if (ret == -1)
|
||||
{
|
||||
if (url_data)
|
||||
free(url_data);
|
||||
if (dl_win)
|
||||
delete (dl_win);
|
||||
shutdown();
|
||||
return -1;
|
||||
}
|
||||
if (dl_win)
|
||||
delete (dl_win);
|
||||
if (url_data)
|
||||
free(url_data);
|
||||
}
|
||||
}
|
||||
|
||||
shutdown();
|
||||
|
||||
}
|
||||
|
||||
void shutdown(void)
|
||||
{
|
||||
|
||||
cleanuprt ();
|
||||
cleanuprt();
|
||||
|
||||
if (rt.display_mode == DISP_CURSES)
|
||||
shutdownCurses();
|
||||
|
||||
proz_shutdown ();
|
||||
|
||||
proz_shutdown();
|
||||
}
|
||||
|
22
src/main.h
22
src/main.h
@ -10,7 +10,7 @@
|
||||
//#define _(String) dgettext (PACKAGE,String)
|
||||
#define gettext_noop(String) (String)
|
||||
#ifndef HAVE_GNOME
|
||||
#define N_(String) gettext_noop (String)
|
||||
#define N_(String) gettext_noop(String)
|
||||
#endif
|
||||
/* Gettext */
|
||||
|
||||
@ -19,14 +19,14 @@
|
||||
|
||||
#define PRZCONFDIR ".prozilla"
|
||||
|
||||
typedef enum {
|
||||
RESUME
|
||||
} rto;
|
||||
typedef enum {
|
||||
RESUME
|
||||
} rto;
|
||||
|
||||
typedef enum {
|
||||
DISP_CURSES,
|
||||
DISP_STDOUT
|
||||
} DISPLAYMODE;
|
||||
typedef enum {
|
||||
DISP_CURSES,
|
||||
DISP_STDOUT
|
||||
} DISPLAYMODE;
|
||||
|
||||
struct runtime {
|
||||
int num_connections;
|
||||
@ -37,7 +37,7 @@ struct runtime {
|
||||
int use_netrc;
|
||||
int ftp_use_pasv;
|
||||
int max_attempts;
|
||||
int retry_delay; /*delay in seconds */
|
||||
int retry_delay; /*delay in seconds */
|
||||
/*
|
||||
* The timeout period for the connections
|
||||
*/
|
||||
@ -71,8 +71,8 @@ struct runtime {
|
||||
//int use_ftpsearch;
|
||||
int ftpsearch_server_id;
|
||||
//new options
|
||||
int resume_mode; //
|
||||
int dont_prompt; //don't prompt user, display message and die
|
||||
int resume_mode; //
|
||||
int dont_prompt; //don't prompt user, display message and die
|
||||
int display_mode; //curses, bare terminal, others...
|
||||
long min_search_size; //size in K
|
||||
};
|
||||
|
125
src/misc.cpp
125
src/misc.cpp
@ -4,103 +4,104 @@
|
||||
|
||||
int is_number(char *str)
|
||||
{
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
while (str[i])
|
||||
while (str[i])
|
||||
{
|
||||
if (isdigit(str[i]) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
if (isdigit(str[i]) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* TODO port these functions */
|
||||
char *kstrdup(const char *s)
|
||||
{
|
||||
char *s1;
|
||||
char *s1;
|
||||
|
||||
s1 = strdup(s);
|
||||
if (!s1)
|
||||
s1 = strdup(s);
|
||||
if (!s1)
|
||||
{
|
||||
// die("Not enough memory to continue: strdup failed");
|
||||
}
|
||||
return s1;
|
||||
|
||||
return s1;
|
||||
}
|
||||
/* Extracts a numurical argument from a option,
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
int setargval(char *optstr, int *num)
|
||||
{
|
||||
if (*optstr == '=')
|
||||
if (*optstr == '=')
|
||||
{
|
||||
if (is_number(optstr + 1) == 1)
|
||||
{
|
||||
*num = atoi(optstr + 1);
|
||||
return 1;
|
||||
} else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (is_number(optstr) == 1)
|
||||
{
|
||||
*num = atoi(optstr);
|
||||
return 1;
|
||||
|
||||
} else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (is_number(optstr + 1) == 1)
|
||||
{
|
||||
*num = atoi(optstr + 1);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_number(optstr) == 1)
|
||||
{
|
||||
*num = atoi(optstr);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int setlongargval(char *optstr, long *num)
|
||||
{
|
||||
if (*optstr == '=')
|
||||
if (*optstr == '=')
|
||||
{
|
||||
if (is_number(optstr + 1) == 1)
|
||||
{
|
||||
*num = atol(optstr + 1);
|
||||
return 1;
|
||||
} else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (is_number(optstr) == 1)
|
||||
{
|
||||
*num = atol(optstr);
|
||||
return 1;
|
||||
|
||||
} else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (is_number(optstr + 1) == 1)
|
||||
{
|
||||
*num = atol(optstr + 1);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_number(optstr) == 1)
|
||||
{
|
||||
*num = atol(optstr);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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_usec = (ms * 1000) % 1000000;
|
||||
tv_delay.tv_sec = ms / 1000;
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
616
src/prefs.cpp
616
src/prefs.cpp
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
@ -31,7 +31,7 @@
|
||||
#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 {
|
||||
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_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_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);
|
||||
@ -75,249 +75,251 @@ void set_search_size(int i, const char *const val, FILE * const fp);
|
||||
|
||||
|
||||
prefopt_t pref_opts[] = {
|
||||
{"threads", set_num_threads, 1},
|
||||
{"tries", set_max_attempts, 1},
|
||||
{"pasv", set_use_pasv, 1},
|
||||
{"retrydelay", set_retry_delay, 1},
|
||||
{"conntimeout", set_conn_timeout, 1},
|
||||
{"maxbpsperdl", set_max_bps_per_dl, 1},
|
||||
{"debug", set_debug_mode, 1},
|
||||
{"libdebug", set_libdebug_mode, 1},
|
||||
{"pragmanocache", set_http_no_cache, 1},
|
||||
{ "threads", set_num_threads, 1 },
|
||||
{ "tries", set_max_attempts, 1 },
|
||||
{ "pasv", set_use_pasv, 1 },
|
||||
{ "retrydelay", set_retry_delay, 1 },
|
||||
{ "conntimeout", set_conn_timeout, 1 },
|
||||
{ "maxbpsperdl", set_max_bps_per_dl, 1 },
|
||||
{ "debug", set_debug_mode, 1 },
|
||||
{ "libdebug", set_libdebug_mode, 1 },
|
||||
{ "pragmanocache", set_http_no_cache, 1 },
|
||||
// {"outputdir", set_output_dir, 1},
|
||||
{"httpproxy", set_http_proxy, 1},
|
||||
{"httpproxyuser", set_http_proxy_username, 1},
|
||||
{"httpproxypassword", set_http_proxy_passwd, 1},
|
||||
{"httpproxytype", set_http_proxy_type, 1},
|
||||
{"usehttpproxy", set_http_use_proxy, 1},
|
||||
{"ftpproxy", set_ftp_proxy, 1},
|
||||
{"ftpproxyuser", set_ftp_proxy_username, 1},
|
||||
{"ftpproxypassword", set_ftp_proxy_passwd, 1},
|
||||
{"ftpproxytype", set_ftp_proxy_type, 1},
|
||||
{"useftpproxy", set_ftp_use_proxy, 1},
|
||||
{"mirrorsreq", set_mirrors_req, 1},
|
||||
{"maxsimulpings", set_max_simul_pings, 1},
|
||||
{"maxpingwait", set_max_ping_wait, 1},
|
||||
{"defaultftpsearch", set_use_ftpsearch, 1},
|
||||
{"ftpsearchserverid", set_ftpsearch_server_id, 1},
|
||||
{"displaymode",set_display_mode, 1},
|
||||
{"minsearchsize",set_search_size, 1},
|
||||
{NULL, 0, 0}
|
||||
{ "httpproxy", set_http_proxy, 1 },
|
||||
{ "httpproxyuser", set_http_proxy_username, 1 },
|
||||
{ "httpproxypassword", set_http_proxy_passwd, 1 },
|
||||
{ "httpproxytype", set_http_proxy_type, 1 },
|
||||
{ "usehttpproxy", set_http_use_proxy, 1 },
|
||||
{ "ftpproxy", set_ftp_proxy, 1 },
|
||||
{ "ftpproxyuser", set_ftp_proxy_username, 1 },
|
||||
{ "ftpproxypassword", set_ftp_proxy_passwd, 1 },
|
||||
{ "ftpproxytype", set_ftp_proxy_type, 1 },
|
||||
{ "useftpproxy", set_ftp_use_proxy, 1 },
|
||||
{ "mirrorsreq", set_mirrors_req, 1 },
|
||||
{ "maxsimulpings", set_max_simul_pings, 1 },
|
||||
{ "maxpingwait", set_max_ping_wait, 1 },
|
||||
{ "defaultftpsearch", set_use_ftpsearch, 1 },
|
||||
{ "ftpsearchserverid", set_ftpsearch_server_id, 1 },
|
||||
{ "displaymode", set_display_mode, 1 },
|
||||
{ "minsearchsize", set_search_size, 1 },
|
||||
{ NULL, 0, 0 }
|
||||
};
|
||||
|
||||
void set_num_threads(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.num_connections);
|
||||
} else
|
||||
{
|
||||
rt.num_connections = atoi(val);
|
||||
if (rt.num_connections <= 0 || rt.num_connections > 30)
|
||||
rt.num_connections = 4;
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.num_connections);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.num_connections = atoi(val);
|
||||
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)
|
||||
{
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.max_attempts);
|
||||
} else
|
||||
{
|
||||
rt.max_attempts = atoi(val);
|
||||
if (rt.max_attempts < 0)
|
||||
rt.max_attempts = 0;
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.max_attempts);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.max_attempts = atoi(val);
|
||||
if (rt.max_attempts < 0)
|
||||
rt.max_attempts = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void set_retry_delay(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.retry_delay);
|
||||
} else
|
||||
{
|
||||
rt.retry_delay = atoi(val);
|
||||
if (rt.retry_delay < 0)
|
||||
rt.retry_delay = 15;
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.retry_delay);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.retry_delay = atoi(val);
|
||||
if (rt.retry_delay < 0)
|
||||
rt.retry_delay = 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void set_conn_timeout(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", (int) rt.timeout.tv_sec);
|
||||
} else
|
||||
{
|
||||
rt.timeout.tv_sec = atoi(val);
|
||||
rt.timeout.tv_usec = 0;
|
||||
{
|
||||
fprintf(fp, "%d", (int)rt.timeout.tv_sec);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.timeout.tv_sec = atoi(val);
|
||||
rt.timeout.tv_usec = 0;
|
||||
|
||||
if (rt.timeout.tv_sec < 0)
|
||||
rt.timeout.tv_sec = 90;
|
||||
}
|
||||
if (rt.timeout.tv_sec < 0)
|
||||
rt.timeout.tv_sec = 90;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void set_max_bps_per_dl(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", (int) rt.max_bps_per_dl);
|
||||
} else
|
||||
{
|
||||
rt.max_bps_per_dl = atoi(val);
|
||||
|
||||
if (rt.max_bps_per_dl < 0)
|
||||
rt.max_bps_per_dl = 0;
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", (int)rt.max_bps_per_dl);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.max_bps_per_dl = atoi(val);
|
||||
|
||||
if (rt.max_bps_per_dl < 0)
|
||||
rt.max_bps_per_dl = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void set_use_pasv(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.ftp_use_pasv);
|
||||
} else
|
||||
{
|
||||
rt.ftp_use_pasv = atoi(val);
|
||||
}
|
||||
|
||||
{
|
||||
fprintf(fp, "%d", rt.ftp_use_pasv);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.ftp_use_pasv = atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void set_debug_mode(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.debug_mode);
|
||||
} else
|
||||
{
|
||||
rt.debug_mode = atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.debug_mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.debug_mode = atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
void set_libdebug_mode(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.libdebug_mode);
|
||||
} else
|
||||
{
|
||||
rt.libdebug_mode = atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.libdebug_mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.libdebug_mode = atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
void set_http_no_cache(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.http_no_cache);
|
||||
} else
|
||||
{
|
||||
rt.http_no_cache = atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.http_no_cache);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.http_no_cache = atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
void set_output_dir(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%s", rt.output_dir);
|
||||
} else
|
||||
{
|
||||
free(rt.output_dir);
|
||||
rt.output_dir = strdup(val);
|
||||
}
|
||||
|
||||
{
|
||||
fprintf(fp, "%s", rt.output_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(rt.output_dir);
|
||||
rt.output_dir = strdup(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void set_http_proxy(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
uerr_t err;
|
||||
urlinfo url_data;
|
||||
|
||||
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);
|
||||
return;
|
||||
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);
|
||||
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)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%s", rt.http_proxy->username);
|
||||
} else
|
||||
{
|
||||
free(rt.http_proxy->username);
|
||||
rt.http_proxy->username = strdup(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%s", rt.http_proxy->username);
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%s", rt.http_proxy->passwd);
|
||||
} else
|
||||
{
|
||||
free(rt.http_proxy->passwd);
|
||||
rt.http_proxy->passwd = strdup(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%s", rt.http_proxy->passwd);
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", (int) rt.http_proxy->type);
|
||||
} else
|
||||
{
|
||||
rt.http_proxy->type = (proxy_type) atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", (int)rt.http_proxy->type);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.http_proxy->type = (proxy_type)atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void set_http_use_proxy(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.use_http_proxy);
|
||||
} else
|
||||
{
|
||||
rt.use_http_proxy = atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.use_http_proxy);
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
uerr_t err;
|
||||
urlinfo url_data;
|
||||
|
||||
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);
|
||||
return;
|
||||
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);
|
||||
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)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%s", rt.ftp_proxy->username);
|
||||
} else
|
||||
{
|
||||
free(rt.ftp_proxy->username);
|
||||
rt.ftp_proxy->username = strdup(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%s", rt.ftp_proxy->username);
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%s", rt.ftp_proxy->passwd);
|
||||
} else
|
||||
{
|
||||
free(rt.ftp_proxy->passwd);
|
||||
rt.ftp_proxy->passwd = strdup(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%s", rt.ftp_proxy->passwd);
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", (int) rt.ftp_proxy->type);
|
||||
} else
|
||||
{
|
||||
rt.ftp_proxy->type = (proxy_type) atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", (int)rt.ftp_proxy->type);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.ftp_proxy->type = (proxy_type)atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
void set_ftp_use_proxy(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.use_ftp_proxy);
|
||||
} else
|
||||
{
|
||||
rt.use_ftp_proxy = atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.use_ftp_proxy);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.use_ftp_proxy = atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void set_mirrors_req(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.ftps_mirror_req_n);
|
||||
} else
|
||||
{
|
||||
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 = 40;
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.ftps_mirror_req_n);
|
||||
}
|
||||
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 = 40;
|
||||
}
|
||||
}
|
||||
|
||||
void set_max_simul_pings(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.max_simul_pings);
|
||||
} else
|
||||
{
|
||||
rt.max_simul_pings= atoi(val);
|
||||
if (rt.max_simul_pings <= 0 || rt.max_simul_pings> 30)
|
||||
rt.max_simul_pings=5;
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.max_simul_pings);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.max_simul_pings = atoi(val);
|
||||
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)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.max_ping_wait);
|
||||
} else
|
||||
{
|
||||
rt.max_ping_wait= atoi(val);
|
||||
if (rt.max_ping_wait <= 0 || rt.max_ping_wait> 30)
|
||||
rt.max_ping_wait=5;
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.max_ping_wait);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.max_ping_wait = atoi(val);
|
||||
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)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.ftp_search);
|
||||
} else
|
||||
{
|
||||
rt.ftp_search = atoi(val);
|
||||
}
|
||||
|
||||
{
|
||||
fprintf(fp, "%d", rt.ftp_search);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.ftp_search = atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
void set_ftpsearch_server_id(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.ftpsearch_server_id);
|
||||
} else
|
||||
{
|
||||
rt.ftpsearch_server_id = atoi(val);
|
||||
if (rt.ftpsearch_server_id < 0)
|
||||
rt.ftpsearch_server_id = 0;
|
||||
else if (rt.ftpsearch_server_id > 1)
|
||||
rt.ftpsearch_server_id = 1;
|
||||
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.ftpsearch_server_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.ftpsearch_server_id = atoi(val);
|
||||
if (rt.ftpsearch_server_id < 0)
|
||||
rt.ftpsearch_server_id = 0;
|
||||
else if (rt.ftpsearch_server_id > 1)
|
||||
rt.ftpsearch_server_id = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void set_display_mode(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%d", rt.display_mode);
|
||||
} else
|
||||
{
|
||||
rt.display_mode = atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%d", rt.display_mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.display_mode = atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
void set_search_size(int i, const char *const val, FILE * const fp)
|
||||
{
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
fprintf(fp, "%ld", rt.min_search_size);
|
||||
} else
|
||||
{
|
||||
rt.min_search_size = atoi(val);
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%ld", rt.min_search_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.min_search_size = atoi(val);
|
||||
}
|
||||
}
|
||||
|
||||
void save_prefs()
|
||||
@ -503,24 +504,24 @@ void save_prefs()
|
||||
int i;
|
||||
|
||||
snprintf(config_fname, PATH_MAX, "%s/.prozilla/%s", rt.home_dir,
|
||||
"prozconfig");
|
||||
"prozconfig");
|
||||
|
||||
if ((fp = fopen(config_fname, "wt")) == NULL)
|
||||
{
|
||||
perror("could not save preferences file");
|
||||
proz_debug("could not save preferences file :- %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
{
|
||||
perror("could not save preferences file");
|
||||
proz_debug("could not save preferences file :- %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
fprintf(fp, "%s=", pref_opts[i].varname);
|
||||
(*pref_opts[i].proc) (i, NULL, fp);
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
{
|
||||
fprintf(fp, "%s=", pref_opts[i].varname);
|
||||
(*pref_opts[i].proc)(i, NULL, fp);
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
@ -533,44 +534,43 @@ void load_prefs()
|
||||
char *tok1, *tok2;
|
||||
|
||||
snprintf(config_fname, PATH_MAX, "%s/.prozilla/%s", rt.home_dir,
|
||||
"prozconfig");
|
||||
"prozconfig");
|
||||
|
||||
if ((fp = fopen(config_fname, "rt")) == NULL)
|
||||
{
|
||||
|
||||
if (errno == ENOENT) /*Create the file then if it doesnt exist */
|
||||
{
|
||||
save_prefs();
|
||||
return;
|
||||
}
|
||||
if (errno == ENOENT) /*Create the file then if it doesnt exist */
|
||||
{
|
||||
save_prefs();
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
perror(_("could not open preferences file for reading"));
|
||||
proz_debug("could not open preferences file :- %s", strerror(errno));
|
||||
return;
|
||||
else
|
||||
{
|
||||
perror(_("could not open preferences file for reading"));
|
||||
proz_debug("could not open preferences file :- %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
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)
|
||||
{
|
||||
if (pref_opts[i].proc != NULL)
|
||||
(*pref_opts[i].proc) (i, tok2, 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)
|
||||
{
|
||||
if (pref_opts[i].proc != NULL)
|
||||
(*pref_opts[i].proc)(i, tok2, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
26
src/prefs.h
26
src/prefs.h
@ -1,20 +1,20 @@
|
||||
/******************************************************************************
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
fltk prozilla - a front end for prozilla, a download accelerator library
|
||||
Copyright (C) 2001 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
******************************************************************************/
|
||||
#ifndef PREFS_H
|
||||
#define PREFS_H
|
||||
|
Loading…
Reference in New Issue
Block a user