home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 4
/
CDPD_IV.bin
/
networking
/
uucp
/
amigauucpsrc
/
bms
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-29
|
12KB
|
511 lines
/*
* MAIN.C
*
* BMS [destinations...] keywords/options
*/
#include "defs.h"
#include <config.h>
#include <version.h>
#include <lib_protos.h>
#include <owndevunit.h>
Prototype void ResolveDestList(void);
Prototype void PrintHelp(void);
Prototype void InstallBMS(void);
Prototype void CleanupBMS(void);
Prototype void myexit(void);
Prototype long HelpOpt;
Prototype long InstallOpt;
Prototype long BatchOpt;
Prototype char *RegisterOpt;
Prototype char *PathOpt;
Prototype char *AliasOpt;
Prototype char *RenameOpt;
Prototype char *ToOpt;
Prototype long StatusOpt;
Prototype long VerboseOpt;
Prototype long AllOpt;
Prototype long FilesOpt;
Prototype long StatsOpt;
Prototype long ActiveOpt;
Prototype long VarsOpt;
Prototype long CleanupOpt;
Prototype long DebugOpt;
Prototype char *DequeueOpt;
Prototype char *MessageOpt;
Prototype char *StopOpt;
Prototype char *StartOpt;
Prototype char *DestroyOpt;
Prototype char *RetryOpt;
Prototype char *GetOpt;
Prototype char *PutOpt;
Prototype char *ListOpt;
Prototype char *AddFileAccOpt;
Prototype char *RemFileAccOpt;
Prototype char *ResFileAccOpt;
Prototype long MaxRxBpd;
Prototype long MaxTxBpd;
Prototype long MaxRxBpw;
Prototype long MaxTxBpw;
Prototype long MaxRxMail;
Prototype long MaxTxMail;
Prototype long MinMail;
Prototype long MirRxBpd;
Prototype long MirTxBpd;
Prototype long CacBwPerc;
Prototype long ReqSwamp;
Prototype long MirSwamp;
Prototype long ExitCode;
Prototype List DestList;
Prototype List RegList;
Prototype char TmpBuf1[512];
Prototype char TmpBuf2[512];
Prototype DBHan *Db;
Prototype RegNode *DefRN;
long HelpOpt;
long InstallOpt;
long BatchOpt;
char *RegisterOpt;
char *PathOpt;
char *AliasOpt;
char *RenameOpt;
char *ToOpt;
long StatusOpt;
long VerboseOpt;
long AllOpt;
long FilesOpt; /* status files */
long StatsOpt; /* statistics */
long ActiveOpt; /* statistics */
long VarsOpt; /* status variables */
long CleanupOpt;
long DebugOpt;
char *DequeueOpt;
char *MessageOpt;
char *StopOpt;
char *StartOpt;
char *RetryOpt;
char *DestroyOpt;
char *GetOpt;
char *PutOpt;
char *ListOpt;
char *AddFileAccOpt;
char *RemFileAccOpt;
char *ResFileAccOpt;
long MaxRxBpd;
long MaxTxBpd;
long MaxRxBpw;
long MaxTxBpw;
long MaxRxMail;
long MaxTxMail;
long MinMail;
long MirRxBpd;
long MirTxBpd;
long CacBwPerc;
long ReqSwamp;
long MirSwamp;
long ExitCode;
List DestList;
List RegList;
char TmpBuf1[512];
char TmpBuf2[512];
DBHan *Db;
RegNode *DefRN;
IDENT(".01");
struct Library *OwnDevUnitBase;
typedef struct CmdTable {
char *ct_Name;
short ct_Args;
short ct_Int;
short ct_IsCmd;
void *ct_Data;
} CmdTable;
CmdTable CmdAry[] = {
"help", 0, 0, 1, &HelpOpt,
"install", 0, 0, 1, &InstallOpt,
"batch", 0, 0, 1, &BatchOpt,
"register", 1, 0, 1, &RegisterOpt,
"retpath", 1, 0, 0, &PathOpt,
"alias", 1, 0, 1, &AliasOpt,
"rename", 1, 0, 1, &RenameOpt,
"to", 1, 0, 0, &ToOpt,
"status", 0, 0, 1, &StatusOpt,
"vars", 0, 0, 0, &VarsOpt,
"files", 0, 0, 0, &FilesOpt,
"stats", 0, 0, 0, &StatsOpt,
"active", 0, 0, 0, &ActiveOpt,
"all", 0, 0, 0, &AllOpt,
"debug", 0, 0, 0, &DebugOpt,
"verbose", 0, 0, 0, &VerboseOpt,
"cleanup", 0, 0, 1, &CleanupOpt,
"dequeue", 1, 0, 1, &DequeueOpt,
"message", 1, 0, 0, &MessageOpt,
"stop", 1, 0, 1, &StopOpt,
"start", 1, 0, 1, &StartOpt,
"retry", 1, 0, 1, &RetryOpt,
"destroy", 1, 0, 1, &DestroyOpt,
"get", 1, 0, 1, &GetOpt,
"put", 1, 0, 1, &PutOpt,
"list", 1, 0, 1, &ListOpt,
"addfile", 1, 0, 1, &AddFileAccOpt,
"remfile", 1, 0, 1, &RemFileAccOpt,
"restrict", 1, 0, 1, &ResFileAccOpt,
"MAXRXBPD", 1, 1, 1, &MaxRxBpd,
"MAXTXBPD", 1, 1, 1, &MaxTxBpd,
"MAXRXBPW", 1, 1, 1, &MaxRxBpw,
"MAXTXBPW", 1, 1, 1, &MaxTxBpw,
"MAXRXMAIL", 1, 1, 1, &MaxRxMail,
"MAXTXMAIL", 1, 1, 1, &MaxTxMail,
"MINMAIL", 1, 1, 1, &MinMail,
"MIRRXBPD", 1, 1, 1, &MirRxBpd,
"MIRTXBPD", 1, 1, 1, &MirTxBpd,
"CACBWPERC", 1, 1, 1, &CacBwPerc,
"REQSWAMP", 1, 1, 1, &ReqSwamp,
"MIRSWAMP", 1, 1, 1, &MirSwamp
};
main(ac, av)
char *av[];
{
short i;
NewList(&DestList);
NewList(&RegList);
StatusOpt = 99;
for (i = 1; i < ac; ++i) {
char *ptr = av[i];
CmdTable *ct;
if (strnicmp(ptr, "D=", 2) == 0) {
AddTail(&DestList, MakeNode(ptr + 2));
continue;
}
for (ct = CmdAry; ct < CmdAry + arysize(CmdAry); ++ct) {
if (stricmp(ptr, ct->ct_Name) == 0) {
break;
}
}
if (ct == CmdAry + arysize(CmdAry)) {
bmslog("Main", "Unrecognized Keyword: %s", ptr);
continue;
}
if (ct->ct_IsCmd && StatusOpt == 99)
StatusOpt = 0;
if (ct->ct_Args) {
if ((ptr = av[++i]) == NULL) {
bmslog("Main", "Expected argument for %s", av[i-1]);
--i;
continue;
}
if (ct->ct_Int)
*(long *)ct->ct_Data = strtol(ptr, NULL, 0);
else
*(char **)ct->ct_Data = ptr;
} else {
++*(long *)ct->ct_Data;
}
}
atexit(myexit);
if ((OwnDevUnitBase = OpenLibrary(ODU_NAME, 0)) == NULL) {
printf("Unable to open %s\n", ODU_NAME);
exit(20);
}
/*
* Handle special options (before database is setup)
*/
if (HelpOpt)
PrintHelp();
if (InstallOpt)
InstallBMS();
if (CleanupOpt)
CleanupBMS();
LoadBMSTopLevel();
ResolveDestList();
/*
* Initialize state machine table
*/
InitGet();
InitPut();
InitList();
InitRegister();
InitDequeue();
InitStop();
InitStart();
InitMirror();
/*
* Handle normal options
*/
if (BatchOpt)
BatchBMS();
if (RegisterOpt) {
RegisterBMS(RegisterOpt, PathOpt, AliasOpt);
AliasOpt = NULL;
PathOpt = NULL;
}
if (AliasOpt)
AliasBMS(AliasOpt);
if (RenameOpt) {
RenameBMS(RenameOpt, ToOpt);
ToOpt = NULL;
}
if (GetOpt) {
GetBMS(GetOpt, ToOpt); /* XXX remove ToOpt get crash */
ToOpt = NULL;
}
if (PutOpt) {
PutBMS(PutOpt, ToOpt);
ToOpt = NULL;
}
if (ListOpt)
ListBMS(ListOpt);
if (AddFileAccOpt)
AddFileBMS(AddFileAccOpt);
if (RemFileAccOpt)
RemFileBMS(RemFileAccOpt);
if (ResFileAccOpt)
ResFileBMS(ResFileAccOpt);
if (StatusOpt)
StatusBMS();
if (DequeueOpt) {
DequeueBMS(DequeueOpt, MessageOpt);
MessageOpt = NULL;
}
if (StopOpt)
StopBMS(StopOpt);
if (StartOpt)
StartBMS(StartOpt);
if (DestroyOpt)
DestroyBMS(DestroyOpt);
if (RetryOpt)
RetryBMS(RetryOpt);
ModifyVariables();
if (ToOpt)
bmslog("Main", "TO option does not apply");
if (MessageOpt)
bmslog("Main", "MESSAGE option does not apply");
return(ExitCode);
}
void
myexit(void)
{
if (Db) {
SaveBMSDataBase();
CloseDataBase(Db);
Db = NULL;
}
dbc_atexit();
UnLockFiles();
if (OwnDevUnitBase) {
CloseLibrary(OwnDevUnitBase);
OwnDevUnitBase = NULL;
}
}
/*
* Resolve DestList. DestList contains simple Node structures,
* find RegNode references and flag. If no nodes in DestList then
* flag default RegNode.
*
* For a destination of * (D=*), all nodes except the default are
* modified
*/
void
ResolveDestList(void)
{
Node *node;
RegNode *rn;
for (rn = GetHead(&RegList); rn; rn = GetSucc(&rn->rn_Node)) {
if (rn->rn_Node.ln_Name == NULL)
break;
}
if ((DefRN = rn) == NULL) {
bmslog("ResolveDest", "DEFAULTS NOT FOUND!");
exit(10);
}
for (node = GetHead(&DestList); node; node = GetSucc(node)) {
for (rn = GetHead(&RegList); rn; rn = GetSucc(&rn->rn_Node)) {
if ((rn->rn_Flags & GF_NODISP) && AllOpt == 0)
continue;
if (rn->rn_Node.ln_Name && stricmp(node->ln_Name, rn->rn_Node.ln_Name) == 0) {
rn->rn_Flags |= GF_MARKED;
break;
}
if (rn->rn_Alias && stricmp(node->ln_Name, rn->rn_Alias) == 0) {
rn->rn_Flags |= GF_MARKED;
break;
}
if (rn->rn_Node.ln_Name && stricmp(node->ln_Name, "*") == 0)
rn->rn_Flags |= GF_MARKED;
}
for (rn = GetHead(&RegList); rn; rn = GetSucc(&rn->rn_Node)) {
if (rn->rn_Flags & GF_MARKED)
break;
}
if (rn) {
rn->rn_Flags |= GF_MARKED;
} else {
bmslog("ResolveDest", "Node '%s' not found", node->ln_Name);
exit(10);
}
}
if (GetHead(&DestList) == NULL)
DefRN->rn_Flags |= GF_MARKED;
}
/*
* Display some form of help
*/
void
PrintHelp()
{
srand(time(NULL));
if ((rand() & 63) == 0) {
puts("Help! I'm being held hostage on a hard disk platter!");
return;
}
printf(
"BMS RELEASE %s\n"
"See documentation for operation\n\n"
"BMS STATUS [VARS] [FILES] [STATS] [ACTIVE] [ALL] [DEBUG]\n"
"BMS HELP\n"
"BMS INSTALL\n"
"BMS BATCH\n",
Ident
);
printf(
"BMS REGISTER dest_path RETPATH ret_path [ALIAS alias]\n"
"BMS D=dest ALIAS newalias\n"
"BMS RENAME dest TO new_dest_path\n"
"BMS CLEANUP\n"
);
printf(
"BMS DEQUEUE <id> MESSAGE \"message\"\n"
"BMS DESTROY <id>\n"
"BMS STOP <id>\n"
"BMS START <id>\n"
"BMS RETRY <id>\n"
);
printf(
"BMS D=dest GET remote_file TO local_file\n"
"BMS D=dest PUT local_file TO remote_file\n"
"BMS D=dest LIST <directory/ALL>\n"
"BMS [D=dest] ADDFILE file/dir_name\n"
"BMS [D=dest] REMFILE file/dir_name\n"
"BMS [D=dest] RESTRICT file/dir_name\n"
);
printf(
"BMS [D=dest] <VARIABLE> value\n"
" MAXRXBPD MAXTXBPD MAXRXBPW MAXTXBPW\n"
" MAXRXMAIL MAXTXMAIL MINMAIL\n"
" MIRRXBPD MIRTXBPD CACBWPERC\n"
" REQSWAMP MIRSWAMP\n"
);
}
/*
* Install the BMS system
*/
void
InstallBMS()
{
RegNode *rn;
bmslog("Install", "Begin Install");
mkdir("BMS:Tmp");
mkdir("BMS:Pub");
if (Db = OpenDataBase("BMS:BMS.DB", "r")) {
CloseDataBase(Db);
Db = NULL;
if (getyn("BMS Database Exists! delete it?", NO) == NO)
return;
remove("BMS:BMS.DB");
}
Db = OpenDataBase("BMS:BMS.DB", "w");
if (Db == NULL) {
bmslog("Install", "Unable to create BMS:BMS.DB");
return;
}
/*
* Create a dummy entry to hold global defaults. This is a
* registration node with ln_Name = NULL
*/
rn = AllocRegNode();
rn->rn_Alias = zstrdup("default");
rn->rn_Comm.com_Flags = GF_MODIFIED;
rn->rn_Comm.com_TOTime = -1;
/*
* Inititalize default parameters
*/
rn->rn_Param.pm_MaxRxBpd = 100000; /* receive bytes per day */
rn->rn_Param.pm_MaxTxBpd = 100000; /* transmit bytes per day */
rn->rn_Param.pm_MaxRxBpw = 400000; /* receive bytes per week */
rn->rn_Param.pm_MaxTxBpw = 400000; /* transmit bytes per week */
rn->rn_Param.pm_MaxRxMail= 56000; /* rx mail message size */
rn->rn_Param.pm_MaxTxMail= 56000; /* tx mail message size */
rn->rn_Param.pm_MinMail = 15000; /* worst case breakdown */
rn->rn_Param.pm_MirRxBpd = 30000; /* mirror bandwidth receive */
rn->rn_Param.pm_MirTxBpd = 50000; /* mirror bandwidth transmit */
rn->rn_Param.pm_CacBwPerc= 10; /* 10% of bandwidth */
rn->rn_Param.pm_ReqSwamp = 10; /* swamp factor */
rn->rn_Param.pm_MirSwamp = 20; /* swamp factor */
rn->rn_Param.pm_Flags = GF_MODIFIED;
AllocFileAccess(rn, "UUPUB:");
AllocFileAccess(rn, "BMS:PUB");
SaveBMSDataBase();
UnLoadBMSDataBase();
bmslog("Install", "End Install");
CloseDataBase(Db);
Db = NULL;
}
void
CleanupBMS()
{
bmslog("Cleanup", "Begin");
CleanDataBase("BMS:BMS.DB");
bmslog("Cleanup", "End");
}