This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbfido/mbaff.c

203 lines
4.5 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Announce new files and FileFind
*
*****************************************************************************
2002-01-07 19:16:03 +00:00
* Copyright (C) 1997-2002
2001-08-17 05:46:24 +00:00
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS 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, or (at your option) any
* later version.
*
* MBSE BBS 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 MBSE BBS; see the file COPYING. If not, write to the Free
2003-08-15 20:05:34 +00:00
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
2001-08-17 05:46:24 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2001-08-17 05:46:24 +00:00
#include "../lib/libs.h"
#include "../lib/structs.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2001-08-17 05:46:24 +00:00
#include "../lib/records.h"
#include "../lib/common.h"
#include "../lib/clcomm.h"
#include "../lib/dbcfg.h"
#include "../lib/msg.h"
2002-10-20 20:58:55 +00:00
#include "../lib/mberrors.h"
2001-08-17 05:46:24 +00:00
#include "announce.h"
#include "filefind.h"
#include "mbaff.h"
int do_announce = FALSE; /* Announce flag */
int do_filefind = FALSE; /* FileFind flag */
extern int do_quiet; /* Suppress screen output */
2001-08-17 05:46:24 +00:00
extern int show_log; /* Show logging */
time_t t_start; /* Start time */
time_t t_end; /* End time */
void ProgName(void)
{
2003-08-03 14:42:12 +00:00
if (do_quiet)
return;
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
colour(15, 0);
printf("\nMBAFF: MBSE BBS %s Announce new files and FileFind\n", VERSION);
colour(14, 0);
printf(" %s\n", COPYRIGHT);
2001-08-17 05:46:24 +00:00
}
void die(int onsig)
{
2003-08-03 14:42:12 +00:00
signal(onsig, SIG_IGN);
if (onsig) {
if (onsig <= NSIG)
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
else
WriteError("Terminated with error %d", onsig);
}
ulockprogram((char *)"mbaff");
t_end = time(NULL);
Syslog(' ', "MBAFF finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) {
colour(7, 0);
printf("\n");
}
ExitClient(onsig);
2001-08-17 05:46:24 +00:00
}
int main(int argc, char **argv)
{
2003-08-03 14:42:12 +00:00
int i, Mail = FALSE;
char *cmd;
struct passwd *pw;
struct tm *t;
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
InitConfig();
TermInit(1);
t_start = time(NULL);
t = localtime(&t_start);
Diw = t->tm_wday;
Miy = t->tm_mon;
umask(002);
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
/*
* Catch all signals we can, and ignore the rest.
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else
signal(i, SIG_IGN);
}
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
if (argc < 2)
Help();
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
cmd = xstrcpy((char *)"Command line: mbaff");
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
for (i = 1; i < argc; i++) {
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
if (!strncmp(argv[i], "a", 1))
do_announce = TRUE;
if (!strncmp(argv[i], "f", 1))
do_filefind = TRUE;
if (!strncmp(argv[i], "-q", 2))
do_quiet = TRUE;
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
}
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
ProgName();
pw = getpwuid(getuid());
2003-09-09 19:39:51 +00:00
InitClient(pw->pw_name, (char *)"mbaff", CFG.location, CFG.logfile,
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
Syslog(' ', " ");
Syslog(' ', "MBAFF v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
if (!do_quiet)
printf("\n");
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
if (!diskfree(CFG.freespace))
die(MBERR_DISK_FULL);
if (lockprogram((char *)"mbaff")) {
if (!do_quiet)
printf("Can't lock mbaff, abort.\n");
die(MBERR_NO_PROGLOCK);
}
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
memset(&MsgBase, 0, sizeof(MsgBase));
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
if (do_announce)
if (Announce())
Mail = TRUE;
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
if (do_filefind)
if (Filefind())
Mail = TRUE;
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
if (Mail) {
CreateSema((char *)"mailout");
CreateSema((char *)"msglink");
}
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
die(MBERR_OK);
return 0;
2001-08-17 05:46:24 +00:00
}
void Help(void)
{
do_quiet = FALSE;
ProgName();
colour(11, 0);
printf("\nUsage: mbaff [command] <options>\n\n");
colour(9, 0);
printf(" Commands are:\n\n");
colour(3, 0);
printf(" a announce Announce new files\n");
printf(" f filefind FileFind service\n");
colour(9, 0);
printf("\n Options are:\n\n");
colour(3, 0);
printf(" -q -quiet Quiet mode\n");
colour(7, 0);
printf("\n");
2002-10-20 20:58:55 +00:00
die(MBERR_COMMANDLINE);
2001-08-17 05:46:24 +00:00
}