uncrustify sources
This commit is contained in:
1012
src/download_win.cpp
1012
src/download_win.cpp
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,7 @@ typedef enum {
|
||||
} dlwin_status_t;
|
||||
|
||||
|
||||
//The running dialog type
|
||||
//The running dialog type
|
||||
typedef enum {
|
||||
DLG_GENERIC,
|
||||
DLG_URLNSFOD,
|
||||
@@ -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);
|
||||
|
||||
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);
|
||||
|
||||
// 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>
|
||||
105
src/init.cpp
105
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
|
||||
* 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 */
|
||||
|
||||
@@ -103,49 +104,49 @@ void set_defaults()
|
||||
|
||||
|
||||
/*
|
||||
* The default no of connections and maximum redirections allowed
|
||||
* The default no of connections and maximum redirections allowed
|
||||
*/
|
||||
rt.num_connections = 4;
|
||||
rt.max_redirections = 10;
|
||||
/* Uses PASV by default
|
||||
/* Uses PASV by default
|
||||
*/
|
||||
rt.ftp_use_pasv = libprozrtinfo.ftp_use_pasv;
|
||||
/*
|
||||
* The force option, off by default when enabled
|
||||
* The force option, off by default when enabled
|
||||
* cause Prozilla not to prompt the user about overwriting existent
|
||||
* files etc..
|
||||
*/
|
||||
rt.force_mode = FALSE;
|
||||
/*
|
||||
* .netrc options
|
||||
* .netrc options
|
||||
*/
|
||||
rt.use_netrc = TRUE;
|
||||
|
||||
|
||||
/*
|
||||
* The max number of trys and the delay between each
|
||||
* The max number of trys and the delay between each
|
||||
*/
|
||||
rt.max_attempts = 0; /*TODO it is currently UNLIMITED */
|
||||
rt.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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/* Declarations for initialising runtime variables
|
||||
|
||||
Copyright (C) 2000 Kalum Somaratna
|
||||
Copyright (C) 2000 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
380
src/interface.c
380
src/interface.c
@@ -1,25 +1,25 @@
|
||||
/* The file contins routines for managing curses
|
||||
Copyright (C) 2000 Kalum Somaratna
|
||||
|
||||
/* The file contins routines for managing curses
|
||||
Copyright (C) 2000 Kalum Somaratna
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#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,37 +57,37 @@
|
||||
* 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",
|
||||
/* I have decided to change the login failed message
|
||||
"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
|
||||
* 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)
|
||||
|
||||
|
||||
//static int top_con = 0; // the connection that is on the top of the display
|
||||
|
||||
//static int top_con = 0; // the connection that is on the top of the display
|
||||
|
||||
#define MAX_CON_VIEWS 4
|
||||
|
||||
/*
|
||||
* needed for the message(...) function
|
||||
* needed for the message(...) function
|
||||
*/
|
||||
pthread_mutex_t curses_msg_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
char message_buffer[MAX_MSG_SIZE];
|
||||
@@ -105,124 +105,121 @@ int messageRow = 0;
|
||||
int messageCol = 0;
|
||||
|
||||
|
||||
/* because of different args for different ncurses, I had to write these
|
||||
* my self
|
||||
/* because of different args for different ncurses, I had to write these
|
||||
* 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 */
|
||||
/*
|
||||
* 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);
|
||||
|
||||
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,111 +251,112 @@ 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;
|
||||
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;
|
||||
|
||||
if (start == 1)
|
||||
total_bytes_got = proz_download_get_total_bytes_got(download) / 1024;
|
||||
|
||||
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);
|
||||
bytes_got_last_time = total_bytes_got;
|
||||
}
|
||||
|
||||
|
||||
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++;
|
||||
|
||||
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);
|
||||
line = line + 2;
|
||||
attrset(COLOR_PAIR(HIGHLIGHT_PAIR) | A_BOLD);
|
||||
mvprintw(line++, 1, "%s", download->u.url);
|
||||
line++;
|
||||
|
||||
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();
|
||||
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"));
|
||||
|
||||
if ((secs_left = proz_download_get_est_time_left(download)) != -1)
|
||||
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();
|
||||
|
||||
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();
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/* Declarations for the interface
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
@@ -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();
|
||||
|
||||
875
src/main.cpp
875
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 */
|
||||
|
||||
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 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 (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 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;
|
||||
|
||||
break;
|
||||
case 132:
|
||||
/* --no-getch option */
|
||||
rt.dont_prompt = TRUE;
|
||||
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();
|
||||
|
||||
/* 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));
|
||||
if (rt.display_mode == DISP_CURSES)
|
||||
initCurses();
|
||||
|
||||
//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);
|
||||
}
|
||||
/* 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));
|
||||
|
||||
if (opt_file)
|
||||
url_data->file=opt_file;
|
||||
//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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
shutdown();
|
||||
|
||||
}
|
||||
|
||||
void shutdown(void)
|
||||
{
|
||||
|
||||
cleanuprt ();
|
||||
cleanuprt();
|
||||
|
||||
if (rt.display_mode == DISP_CURSES)
|
||||
shutdownCurses();
|
||||
|
||||
proz_shutdown ();
|
||||
|
||||
proz_shutdown();
|
||||
}
|
||||
|
||||
30
src/main.h
30
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,27 +19,27 @@
|
||||
|
||||
#define PRZCONFDIR ".prozilla"
|
||||
|
||||
typedef enum {
|
||||
RESUME
|
||||
} rto;
|
||||
|
||||
typedef enum {
|
||||
DISP_CURSES,
|
||||
DISP_STDOUT
|
||||
} DISPLAYMODE;
|
||||
|
||||
typedef enum {
|
||||
RESUME
|
||||
} rto;
|
||||
|
||||
typedef enum {
|
||||
DISP_CURSES,
|
||||
DISP_STDOUT
|
||||
} DISPLAYMODE;
|
||||
|
||||
struct runtime {
|
||||
int num_connections;
|
||||
int max_redirections;
|
||||
/*
|
||||
* whether to use the netrc file
|
||||
* whether to use the netrc file
|
||||
*/
|
||||
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
|
||||
* The timeout period for the connections
|
||||
*/
|
||||
struct timeval timeout;
|
||||
int itimeout;
|
||||
@@ -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
|
||||
};
|
||||
|
||||
129
src/misc.cpp
129
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
|
||||
*/
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user