/*************************************************************************** * Copyright (C) 2006 by Torben H. Nielsen * * torben@t-hoerup.dk * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include "daemon.h" #include "dblayer.h" #include "dlworker.h" #define VERSION "0.1" #define AUTHOR "Torben H. Nielsen" downloadd_config *CONFIG; void printversion(int terminate) { printf("downloadd - ftp/http download daemon v %s\n", VERSION); printf("(C) 2006 by %s\n\n", AUTHOR); if (terminate) exit(0); } void printusage() { printversion(0); printf("Usage: downloadd [options]...\n"); printf(" Option - description\n\n"); printf(" --help Print this screen\n"); printf(" --version Print version\n"); printf(" --debug Run the program in foreground and all log\n"); printf(" messages are redirected to stdout\n"); printf(" --config Specify which configuration file to use\n"); exit(0); } int main(int argc, char *argv[]) { dlrecord *record; char *configfile = 0; int i, res; char buf[120]; CONFIG = malloc(sizeof(downloadd_config)); CONFIG->debug = 1; // <- this should change to 0 at a later point for (i=1; idebug = 1; } else if (strcmp(argv[i], "--config") == 0) { i++; if (argv[i]) configfile = argv[i]; else printusage(); } else printusage(); } if (CONFIG->debug) log_message("Starting in debug mode"); read_config_file( configfile ); /* do not daemonize if we are in debug mode */ if (!CONFIG->debug) daemonize(); while (1) { record = malloc(sizeof(dlrecord)); res = nextdownload( record ); if (res) { sprintf(buf, "Saving %s to %s", record->URL, record->filename); log_message(buf); downloadfile( record ); } else { if (CONFIG->debug) log_message("No URLs to download"); } free(record); sleep(60); } }