Implemented directory outbound queueing

This commit is contained in:
Michiel Broek 2002-08-03 22:12:37 +00:00
parent ae5dd4bfbe
commit d3cf5b2a64
6 changed files with 708 additions and 570 deletions

View File

@ -29,7 +29,7 @@ v0.35.03 06-Jul-2002
Added routing tables for special cases. Most systems don't Added routing tables for special cases. Most systems don't
need this. need this.
The route test command now works exactly as netmails do. The route test command now works exactly as netmails do.
Implemented directory inbound tossing. Implemented directory inbound tossing and outbound queueing.
newuser: newuser:
Check for Unix accounts is now case sensitive. Check for Unix accounts is now case sensitive.

View File

@ -140,13 +140,13 @@ flock.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h flock.h
hatch.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbtic.h utic.h rollover.h hatch.h hatch.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbtic.h utic.h rollover.h hatch.h
mbdiff.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbdiff.h mbdiff.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbdiff.h
mgrutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/diesel.h sendmail.h rollover.h addpkt.h pack.h createm.h createf.h mgrutil.h mgrutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/diesel.h sendmail.h rollover.h addpkt.h pack.h createm.h createf.h mgrutil.h
pack.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbftn.h ../lib/clcomm.h ../lib/dbnode.h pack.h pack.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbftn.h ../lib/clcomm.h ../lib/dbnode.h dirsession.h pack.h
ptic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbtic.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbdupe.h ulock.h mover.h toberep.h tic.h utic.h addbbs.h magic.h forward.h rollover.h ptic.h magic.h createf.h virscan.h ptic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbtic.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbdupe.h ulock.h mover.h toberep.h tic.h utic.h addbbs.h magic.h forward.h rollover.h ptic.h magic.h createf.h virscan.h
sendmail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ../lib/dbmsgs.h addpkt.h rollover.h sendmail.h sendmail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ../lib/dbmsgs.h addpkt.h rollover.h sendmail.h
tracker.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbftn.h tracker.h tracker.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbftn.h tracker.h
addpkt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/dbnode.h ../lib/dbmsgs.h pack.h addpkt.h addpkt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/dbnode.h ../lib/dbmsgs.h pack.h addpkt.h
bwrite.o: ../config.h ../lib/libs.h ../lib/memwatch.h bwrite.h bwrite.o: ../config.h ../lib/libs.h ../lib/memwatch.h bwrite.h
forward.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbtic.h ../lib/diesel.h tic.h sendmail.h rollover.h mgrutil.h forward.h forward.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbtic.h ../lib/diesel.h tic.h sendmail.h rollover.h mgrutil.h forward.h dirsession.h
lhash.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h lhash.h lhash.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h lhash.h
mbfido.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbdupe.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbuser.h ../lib/dbftn.h ../lib/dbtic.h ../lib/msg.h flock.h tosspkt.h pack.h ulock.h tic.h fsort.h scan.h mbfido.h tracker.h notify.h rollover.h hatch.h scannews.h maketags.h makestat.h newspost.h rnews.h mgrutil.h backalias.h rfc2ftn.h dirsession.h mbfido.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbdupe.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbuser.h ../lib/dbftn.h ../lib/dbtic.h ../lib/msg.h flock.h tosspkt.h pack.h ulock.h tic.h fsort.h scan.h mbfido.h tracker.h notify.h rollover.h hatch.h scannews.h maketags.h makestat.h newspost.h rnews.h mgrutil.h backalias.h rfc2ftn.h dirsession.h
mkftnhdr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h atoul.h hash.h msgflags.h aliasdb.h mkftnhdr.h mkftnhdr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h atoul.h hash.h msgflags.h aliasdb.h mkftnhdr.h

View File

@ -45,7 +45,6 @@ extern int do_unprot;
/* /*
* Check for lock, return TRUE if node is locked. * Check for lock, return TRUE if node is locked.
*/ */
int islocked(char *, int, int);
int islocked(char *lockfile, int chklck, int waitclr) int islocked(char *lockfile, int chklck, int waitclr)
{ {
int i; int i;
@ -104,7 +103,6 @@ int islocked(char *lockfile, int chklck, int waitclr)
* Create a 1 byte lockfile if create is TRUE. * Create a 1 byte lockfile if create is TRUE.
* Returns FALSE if failed. * Returns FALSE if failed.
*/ */
int setlock(char *, int);
int setlock(char *lockfile, int create) int setlock(char *lockfile, int create)
{ {
FILE *fp; FILE *fp;
@ -130,7 +128,6 @@ int setlock(char *lockfile, int create)
/* /*
* Removing lockfile * Removing lockfile
*/ */
void remlock(char *, int);
void remlock(char *lockfile, int create) void remlock(char *lockfile, int create)
{ {
if (create) { if (create) {

View File

@ -4,7 +4,9 @@
/* $Id$ */ /* $Id$ */
void dirinbound(void); int islocked(char *, int, int); /* Is directory locked */
int setlock(char *, int); /* Lock directory */
void remlock(char *, int); /* Unlock directory */
void dirinbound(void); /* Process nodes */
#endif #endif

View File

@ -44,289 +44,322 @@
#include "rollover.h" #include "rollover.h"
#include "mgrutil.h" #include "mgrutil.h"
#include "forward.h" #include "forward.h"
#include "dirsession.h"
void ForwardFile(fidoaddr Node, fa_list *sbl) void ForwardFile(fidoaddr Node, fa_list *sbl)
{ {
char *subject = NULL, *temp, *fwdfile = NULL, *ticfile = NULL, fname[PATH_MAX], *ticname; char *subject = NULL, *temp, *fwdfile = NULL, *ticfile = NULL, fname[PATH_MAX], *ticname, flavor;
FILE *fp, *fi, *net; FILE *fp, *fi, *net;
char flavor; faddr *dest, *routeto, *Fa, *Temp, *ba;
faddr *dest, *routeto, *Fa, *Temp, *ba; int i, z, n;
int i, z, n; time_t now, ftime;
time_t now, ftime; fa_list *tmp;
fa_list *tmp;
if (!SearchNode(Node)) { if (!SearchNode(Node)) {
WriteError("TIC forward in %s, node %s not in setup but defined in area setup", TIC.TicIn.Area, aka2str(Node)); WriteError("TIC forward in %s, node %s not in setup but defined in area setup", TIC.TicIn.Area, aka2str(Node));
return; return;
} }
Syslog('+', "Forward file to %s, %s netmail", aka2str(Node), nodes.Message?"with":"without"); Syslog('+', "Forward file to %s, %s netmail", aka2str(Node), nodes.Message?"with":"without");
/*
* Hier moet een nieuwe SEEN-BY check komen, maar dan wel zo dat
* de net toegevoegde seenby niet getest wordt.
*/
/*
* If Costsharing active for this node
*/
if (nodes.Billing) {
/* /*
* Hier moet een nieuwe SEEN-BY check komen, maar dan wel zo dat * Check if this node has enough credits for this file.
* de net toegevoegde seenby niet getest wordt.
*/ */
T_File.Cost = TIC.FileCost + (TIC.FileCost * nodes.AddPerc / 1000);
/* if ((nodes.Credit < (nodes.StopLevel + T_File.Cost)) && (!TIC.Charge)) {
* If Costsharing active for this node Syslog('!', "No forward to %s, not enough credit left", aka2str(Node));
*/ exit;
if (nodes.Billing) {
/*
* Check if this node has enough credits for this file.
*/
T_File.Cost = TIC.FileCost + (TIC.FileCost * nodes.AddPerc / 1000);
if ((nodes.Credit < (nodes.StopLevel + T_File.Cost)) && (!TIC.Charge)) {
Syslog('!', "No forward to %s, not enough credit left", aka2str(Node));
exit;
}
/*
* Check if we are passing the warning level
*/
if ((nodes.Credit > nodes.WarnLevel) && ((nodes.Credit - T_File.Cost) <= nodes.WarnLevel)) {
Syslog('+', "Low credit warning to %s", aka2str(Node));
/* CREATE NETMAIL */
}
} }
fwdfile = calloc(PATH_MAX, sizeof(char));
/* /*
* Create the full filename * Check if we are passing the warning level
*/ */
if (TIC.SendOrg) { if ((nodes.Credit > nodes.WarnLevel) && ((nodes.Credit - T_File.Cost) <= nodes.WarnLevel)) {
sprintf(fwdfile, "%s/%s", TIC.Inbound, TIC.RealName); Syslog('+', "Low credit warning to %s", aka2str(Node));
subject = xstrcpy(TIC.RealName); /* CREATE NETMAIL */
}
}
fwdfile = calloc(PATH_MAX, sizeof(char));
/*
* Create the full filename
*/
if (TIC.SendOrg) {
sprintf(fwdfile, "%s/%s", TIC.Inbound, TIC.RealName);
subject = xstrcpy(TIC.RealName);
} else {
sprintf(fwdfile, "%s/%s", TIC.BBSpath, TIC.NewName);
subject = xstrcpy(TIC.NewName);
}
flavor = 'f';
if (nodes.Crash)
flavor = 'c';
if (nodes.Hold)
flavor = 'h';
if (nodes.RouteVia.zone)
routeto = fido2faddr(nodes.RouteVia);
else
routeto = fido2faddr(Node);
dest = fido2faddr(Node);
if (nodes.Session_out == S_DIR) {
if (islocked(nodes.Dir_out_clock, nodes.Dir_out_chklck, nodes.Dir_out_waitclr)) {
/*
* Not good, should go to a queue
*/
attach(*routeto, fwdfile, LEAVE, flavor);
} else { } else {
sprintf(fwdfile, "%s/%s", TIC.BBSpath, TIC.NewName); if (! setlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck)) {
subject = xstrcpy(TIC.NewName); /*
* Not good again
*/
attach(*routeto, fwdfile, LEAVE, flavor);
} else {
/*
* Node locked, copy file to destination directory
*/
ticfile = calloc(PATH_MAX, sizeof(char));
sprintf(ticfile, "%s/%s", nodes.Dir_out_path, subject);
if (file_cp(fwdfile, ticfile))
WriteError("$Can't copy %s to %s", fwdfile, ticfile);
else
chmod(ticfile, 0660);
free(ticfile);
}
} }
} else {
flavor = 'f';
if (nodes.Crash)
flavor = 'c';
if (nodes.Hold)
flavor = 'h';
if (nodes.RouteVia.zone)
routeto = fido2faddr(nodes.RouteVia);
else
routeto = fido2faddr(Node);
dest = fido2faddr(Node);
attach(*routeto, fwdfile, LEAVE, flavor); attach(*routeto, fwdfile, LEAVE, flavor);
}
ticfile = calloc(PATH_MAX, sizeof(char)); ticfile = calloc(PATH_MAX, sizeof(char));
ticname = calloc(15, sizeof(char)); ticname = calloc(15, sizeof(char));
if (nodes.Tic) { if (nodes.Tic) {
sprintf(ticname, "%08lx.tic", sequencer()); sprintf(ticname, "%08lx.tic", sequencer());
subject = xstrcat(subject, (char *)" "); subject = xstrcat(subject, (char *)" ");
subject = xstrcat(subject, ticname); subject = xstrcat(subject, ticname);
sprintf(ticfile, "%s/%s", CFG.ticout, ticname); if (nodes.Session_out == S_DIR)
sprintf(ticfile, "%s/%s", nodes.Dir_out_path, ticname);
else
sprintf(ticfile, "%s/%s", CFG.ticout, ticname);
}
free(ticname);
/*
* Send netmail message if the node has it turned on.
*/
if (nodes.Message) {
Temp = fido2faddr(Node);
if ((net = SendMgrMail(Temp, CFG.ct_KeepMgr, TRUE, (char *)"Filemgr", subject, NULL)) != NULL) {
if ((fi = OpenMacro("forward.tic", nodes.Language, FALSE)) != NULL) {
ftime = TIC.FileDate;
MacroVars("a", "s", TIC.TicIn.Area);
MacroVars("b", "s", tic.Comment);
MacroVars("c", "d", TIC.FileCost);
MacroVars("d", "s", fgroup.Comment);
MacroVars("f", "s", TIC.TicIn.FullName);
MacroVars("g", "d", TIC.FileSize);
MacroVars("h", "d", (TIC.FileSize / 1024));
MacroVars("i", "s", TIC.TicIn.Crc);
MacroVars("j", "s", TIC.TicIn.Origin);
MacroVars("m", "s", rfcdate(ftime));
MacroVars("n", "s", TIC.TicIn.Desc);
MacroVars("s", "s", nodes.Sysop);
if (TIC.SendOrg)
MacroVars("e", "s", TIC.RealName);
else
MacroVars("e", "s", TIC.NewName);
if (strlen(TIC.TicIn.Magic))
MacroVars("k", "s", TIC.TicIn.Magic);
if (strlen(TIC.TicIn.Replace))
MacroVars("l", "s", TIC.TicIn.Replace);
MacroRead(fi, net);
fprintf(net, "%s\r", TearLine());
CloseMail(net, Temp);
}
} else {
WriteError("$Can't create netmail");
} }
free(ticname); tidy_faddr(Temp);
}
free(subject);
/* /*
* Send netmail message if the node has it turned on. * If we need a .TIC file, start creating it.
*/ */
if (nodes.Message) { if (nodes.Tic) {
Temp = fido2faddr(Node); mkdirs(ticfile, 0770);
if ((net = SendMgrMail(Temp, CFG.ct_KeepMgr, TRUE, (char *)"Filemgr", subject, NULL)) != NULL) { if ((fp = fopen(ticfile, "a+")) != NULL) {
if ((fi = OpenMacro("forward.tic", nodes.Language, FALSE)) != NULL) { fprintf(fp, "Area %s\r\n", TIC.TicIn.Area);
ftime = TIC.FileDate; fprintf(fp, "Origin %s\r\n", TIC.TicIn.Origin);
MacroVars("a", "s", TIC.TicIn.Area); Fa = fido2faddr(tic.Aka);
MacroVars("b", "s", tic.Comment); fprintf(fp, "From %s\r\n", ascfnode(Fa, 0x0f));
MacroVars("c", "d", TIC.FileCost); free(Fa);
MacroVars("d", "s", fgroup.Comment); if (strlen(TIC.TicIn.Replace))
MacroVars("f", "s", TIC.TicIn.FullName); fprintf(fp, "Replaces %s\r\n", TIC.TicIn.Replace);
MacroVars("g", "d", TIC.FileSize); if (strlen(TIC.TicIn.Magic))
MacroVars("h", "d", (TIC.FileSize / 1024)); fprintf(fp, "Magic %s\r\n", TIC.TicIn.Magic);
MacroVars("i", "s", TIC.TicIn.Crc);
MacroVars("j", "s", TIC.TicIn.Origin); if ((TIC.PassThru) || (TIC.SendOrg))
MacroVars("m", "s", rfcdate(ftime)); subject = xstrcpy(TIC.RealName);
MacroVars("n", "s", TIC.TicIn.Desc); else
MacroVars("s", "s", nodes.Sysop); subject = xstrcpy(TIC.NewName);
if (TIC.SendOrg) /*
MacroVars("e", "s", TIC.RealName); * Create 8.3 filename if this is a long filename. In normal
else * cases mbcico will transmit the long filename to the other
MacroVars("e", "s", TIC.NewName); * node. If they can't process the TIC files which has a short
if (strlen(TIC.TicIn.Magic)) * 8.3 filename and they have a long filename in the inbound
MacroVars("k", "s", TIC.TicIn.Magic); * then in mbsetup these nodes need to be set to 8.3 filenames.
if (strlen(TIC.TicIn.Replace)) * The mailer will then transmit the file with a 8.3 name.
MacroVars("l", "s", TIC.TicIn.Replace); * Thank the inventors of the 8.3 filenames for this.
MacroRead(fi, net); */
fprintf(net, "%s\r", TearLine()); temp = xstrcpy(subject);
CloseMail(net, Temp); name_mangle(temp);
fprintf(fp, "File %s\r\n", temp);
fprintf(fp, "Fullname %s\r\n", subject);
free(temp);
free(subject);
fprintf(fp, "Size %ld\r\n", (long)(TIC.FileSize));
fprintf(fp, "Desc %s\r\n", TIC.TicIn.Desc);
fprintf(fp, "Crc %s\r\n", TIC.TicIn.Crc);
if (nodes.AdvTic) {
fprintf(fp, "To %s, %s\r\n", nodes.Sysop, ascfnode(dest, 0x1f));
fprintf(fp, "Areadesc %s\r\n", tic.Comment);
fprintf(fp, "Fdn %s\r\n", fgroup.Comment);
/*
* According to Harald Harms this field must
* be multiplied with 100.
*/
if (TIC.FileCost && nodes.Billing)
fprintf(fp, "Cost %ld.00\r\n", T_File.Cost);
if (TIC.TicIn.TotLDesc)
for (i = 0; i < TIC.TicIn.TotLDesc; i++)
fprintf(fp, "LDesc %s\r\n", TIC.TicIn.LDesc[i]);
}
fprintf(fp, "Created by MBSE BBS %s %s\r\n", VERSION, SHORTRIGHT);
if (TIC.TicIn.TotPath)
for (i = 0; i < TIC.TicIn.TotPath; i++)
fprintf(fp, "Path %s\r\n", TIC.TicIn.Path[i]);
/*
* Add our system to the path
*/
now = time(NULL);
subject = ctime(&now);
Striplf(subject);
ba = bestaka_s(dest);
fprintf(fp, "Path %s %lu %s %s\r\n", ascfnode(ba, 0x1f), mktime(localtime(&now)), subject, tzname[0]);
tidy_faddr(ba);
if (nodes.AdvTic) {
/*
* In advanced TIC mode we send multiple seenby
* addresses on one line in stead of one line
* per system.
*/
z = 0;
n = 0;
subject = xstrcpy((char *)"Seenby");
for (tmp = sbl; tmp; tmp = tmp->next) {
if (strlen(subject) > 70) {
fprintf(fp, "%s\r\n", subject);
z = 0;
n = 0;
free(subject);
subject = xstrcpy((char *)"Seenby ");
} else {
subject = xstrcat(subject, (char *)" ");
}
if (z != tmp->addr->zone) {
subject = xstrcat(subject, ascfnode(tmp->addr, 0x0e));
z = tmp->addr->zone;
} else {
if (n != tmp->addr->net) {
subject = xstrcat(subject, ascfnode(tmp->addr, 0x06));
n = tmp->addr->net;
} else {
subject = xstrcat(subject, ascfnode(tmp->addr, 0x02));
}
}
}
if (strlen(subject) > 7) {
fprintf(fp, "%s\r\n", subject);
free(subject);
} }
} else { } else {
WriteError("$Can't create netmail");
}
tidy_faddr(Temp);
}
free(subject);
/*
* If we need a .TIC file, start creating it.
*/
if (nodes.Tic) {
mkdirs(ticfile, 0770);
if ((fp = fopen(ticfile, "a+")) != NULL) {
fprintf(fp, "Area %s\r\n", TIC.TicIn.Area);
fprintf(fp, "Origin %s\r\n", TIC.TicIn.Origin);
Fa = fido2faddr(tic.Aka);
fprintf(fp, "From %s\r\n", ascfnode(Fa, 0x0f));
free(Fa);
if (strlen(TIC.TicIn.Replace))
fprintf(fp, "Replaces %s\r\n", TIC.TicIn.Replace);
if (strlen(TIC.TicIn.Magic))
fprintf(fp, "Magic %s\r\n", TIC.TicIn.Magic);
if ((TIC.PassThru) || (TIC.SendOrg))
subject = xstrcpy(TIC.RealName);
else
subject = xstrcpy(TIC.NewName);
/*
* Create 8.3 filename if this is a long filename. In normal
* cases mbcico will transmit the long filename to the other
* node. If they can't process the TIC files which has a short
* 8.3 filename and they have a long filename in the inbound
* then in mbsetup these nodes need to be set to 8.3 filenames.
* The mailer will then transmit the file with a 8.3 name.
* Thank the inventors of the 8.3 filenames for this.
*/
temp = xstrcpy(subject);
name_mangle(temp);
fprintf(fp, "File %s\r\n", temp);
fprintf(fp, "Fullname %s\r\n", subject);
free(temp);
free(subject);
fprintf(fp, "Size %ld\r\n", (long)(TIC.FileSize));
fprintf(fp, "Desc %s\r\n", TIC.TicIn.Desc);
fprintf(fp, "Crc %s\r\n", TIC.TicIn.Crc);
if (nodes.AdvTic) {
fprintf(fp, "To %s, %s\r\n", nodes.Sysop, ascfnode(dest, 0x1f));
fprintf(fp, "Areadesc %s\r\n", tic.Comment);
fprintf(fp, "Fdn %s\r\n", fgroup.Comment);
/*
* According to Harald Harms this field must
* be multiplied with 100.
*/
if (TIC.FileCost && nodes.Billing)
fprintf(fp, "Cost %ld.00\r\n", T_File.Cost);
if (TIC.TicIn.TotLDesc)
for (i = 0; i < TIC.TicIn.TotLDesc; i++)
fprintf(fp, "LDesc %s\r\n", TIC.TicIn.LDesc[i]);
}
fprintf(fp, "Created by MBSE BBS %s %s\r\n", VERSION, SHORTRIGHT);
if (TIC.TicIn.TotPath)
for (i = 0; i < TIC.TicIn.TotPath; i++)
fprintf(fp, "Path %s\r\n", TIC.TicIn.Path[i]);
/*
* Add our system to the path
*/
now = time(NULL);
subject = ctime(&now);
Striplf(subject);
ba = bestaka_s(dest);
fprintf(fp, "Path %s %lu %s %s\r\n", ascfnode(ba, 0x1f),
mktime(localtime(&now)), subject, tzname[0]);
tidy_faddr(ba);
if (nodes.AdvTic) {
/*
* In advanced TIC mode we send multiple seenby
* addresses on one line in stead of one line
* per system.
*/
z = 0;
n = 0;
subject = xstrcpy((char *)"Seenby");
for (tmp = sbl; tmp; tmp = tmp->next) {
if (strlen(subject) > 70) {
fprintf(fp, "%s\r\n", subject);
z = 0;
n = 0;
free(subject);
subject = xstrcpy((char *)"Seenby ");
} else {
subject = xstrcat(subject, (char *)" ");
}
if (z != tmp->addr->zone) {
subject = xstrcat(subject, ascfnode(tmp->addr, 0x0e));
z = tmp->addr->zone;
} else {
if (n != tmp->addr->net) {
subject = xstrcat(subject, ascfnode(tmp->addr, 0x06));
n = tmp->addr->net;
} else {
subject = xstrcat(subject, ascfnode(tmp->addr, 0x02));
}
}
}
if (strlen(subject) > 7) {
fprintf(fp, "%s\r\n", subject);
free(subject);
}
} else {
/*
* Old style seenby lines
*/
for (tmp = sbl; tmp; tmp = tmp->next) {
fprintf(fp, "Seenby %s\r\n", ascfnode(tmp->addr, 0x0f));
}
}
/*
* Now append all passthru ticlines
*/
if (TIC.TicIn.Unknowns)
for (i = 0; i < TIC.TicIn.Unknowns; i++)
fprintf(fp, "%s\r\n", TIC.TicIn.Unknown[i]);
fprintf(fp, "Pw %s\r\n", nodes.Fpasswd);
fclose(fp);
attach(*routeto, ticfile, KFS, flavor);
} else {
WriteError("$Can't create %s", ticfile);
}
}
if (TIC.Charge && nodes.Billing) {
nodes.Credit -= TIC.FileCost;
Syslog('-', "Cost: %d Left: %d", TIC.FileCost, nodes.Credit);
/* /*
* Add an entry to the billing file, each node has his own * Old style seenby lines
* billing file.
*/ */
sprintf(fname, "%s/tmp/%d.%d.%d.%d.bill", getenv("MBSE_ROOT"), for (tmp = sbl; tmp; tmp = tmp->next) {
nodes.Aka[0].zone, nodes.Aka[0].net, nodes.Aka[0].node, nodes.Aka[0].point); fprintf(fp, "Seenby %s\r\n", ascfnode(tmp->addr, 0x0f));
if ((fp = fopen(fname, "a+")) != NULL) {
memset(&bill, 0, sizeof(bill));
bill.Node = nodes.Aka[0];
strcpy(bill.FileName, TIC.NewName);
strcpy(bill.FileEcho, TIC.TicIn.Area);
bill.Size = TIC.FileSize;
bill.Cost = TIC.FileCost;
fwrite(&bill, sizeof(bill), 1, fp);
fclose(fp);
} else {
WriteError("$Can't create %s", fname);
} }
}
/*
* Now append all passthru ticlines
*/
if (TIC.TicIn.Unknowns)
for (i = 0; i < TIC.TicIn.Unknowns; i++)
fprintf(fp, "%s\r\n", TIC.TicIn.Unknown[i]);
fprintf(fp, "Pw %s\r\n", nodes.Fpasswd);
fclose(fp);
if (nodes.Session_out == S_DIRECT)
attach(*routeto, ticfile, KFS, flavor);
} else {
WriteError("$Can't create %s", ticfile);
} }
}
if (TIC.Charge && nodes.Billing) {
nodes.Credit -= TIC.FileCost;
Syslog('-', "Cost: %d Left: %d", TIC.FileCost, nodes.Credit);
/* /*
* Update the nodes statistic counters * Add an entry to the billing file, each node has his own
* billing file.
*/ */
StatAdd(&nodes.FilesSent, 1L); sprintf(fname, "%s/tmp/%d.%d.%d.%d.bill", getenv("MBSE_ROOT"),
StatAdd(&nodes.F_KbSent, T_File.SizeKb); nodes.Aka[0].zone, nodes.Aka[0].net, nodes.Aka[0].node, nodes.Aka[0].point);
UpdateNode(); if ((fp = fopen(fname, "a+")) != NULL) {
SearchNode(Node); memset(&bill, 0, sizeof(bill));
free(ticfile); bill.Node = nodes.Aka[0];
free(fwdfile); strcpy(bill.FileName, TIC.NewName);
tidy_faddr(routeto); strcpy(bill.FileEcho, TIC.TicIn.Area);
bill.Size = TIC.FileSize;
bill.Cost = TIC.FileCost;
fwrite(&bill, sizeof(bill), 1, fp);
fclose(fp);
} else {
WriteError("$Can't create %s", fname);
}
}
if (nodes.Session_out == S_DIR)
remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck);
/*
* Update the nodes statistic counters
*/
StatAdd(&nodes.FilesSent, 1L);
StatAdd(&nodes.F_KbSent, T_File.SizeKb);
UpdateNode();
SearchNode(Node);
free(ticfile);
free(fwdfile);
tidy_faddr(routeto);
} }

View File

@ -38,12 +38,17 @@
#include "../lib/dbftn.h" #include "../lib/dbftn.h"
#include "../lib/clcomm.h" #include "../lib/clcomm.h"
#include "../lib/dbnode.h" #include "../lib/dbnode.h"
#include "dirsession.h"
#include "pack.h" #include "pack.h"
extern int do_quiet; /* Quiet flag */ extern int do_quiet; /* Quiet flag */
static char *dow[] = {(char *)"su", (char *)"mo", (char *)"tu", (char *)"we",
(char *)"th", (char *)"fr", (char *)"sa"};
/* /*
* Pack queued arcmail mail for a node. If the node is locked, the mail won't * Pack queued arcmail mail for a node. If the node is locked, the mail won't
* be packed, and the queue stays as it is. The mail will then be packed * be packed, and the queue stays as it is. The mail will then be packed
@ -51,227 +56,296 @@ extern int do_quiet; /* Quiet flag */
*/ */
int pack_queue(char *name) int pack_queue(char *name)
{ {
FILE *fp; FILE *fp;
faddr noden; faddr noden, *bestaka;
fidoaddr nodenr; fidoaddr nodenr;
char flavor, nr, oldnr, maxnr; char flavor, nr, oldnr, maxnr, *ext, srcfile[128], *arcfile, *pktfile;
char srcfile[128], *arcfile, *pktfile; int Attach, fage;
int Attach, fage; long fsize;
long fsize; time_t Now;
time_t Now; struct tm *ptm;
sprintf(srcfile, "%s", name); sprintf(srcfile, "%s", name);
/*
* Get the nodenumber from the filename
*/
noden.domain = NULL;
noden.name = NULL;
noden.zone = atoi(strtok(name, "."));
noden.net = atoi(strtok(NULL, "."));
noden.node = atoi(strtok(NULL, "."));
noden.point = atoi(strtok(NULL, "."));
if (SearchFidonet(noden.zone))
noden.domain = xstrcpy(fidonet.domain);
memset(&nodenr, 0, sizeof(nodenr));
nodenr.zone = noden.zone;
nodenr.net = noden.net;
nodenr.node = noden.node;
nodenr.point = noden.point;
sprintf(nodenr.domain, "%s", noden.domain);
if (!SearchNode(nodenr)) {
WriteError("Downlink %s not found", aka2str(nodenr));
if (noden.domain)
free(noden.domain);
return FALSE;
}
/*
* If we route via another aka, change everything.
*/
if (nodes.RouteVia.zone) {
Syslog('p', "Route Via %s", aka2str(nodes.RouteVia));
noden.zone = nodes.RouteVia.zone;
noden.net = nodes.RouteVia.net;
noden.node = nodes.RouteVia.node;
noden.point = nodes.RouteVia.point;
if (noden.domain)
free(noden.domain);
noden.domain = xstrcpy(nodes.RouteVia.domain);
/* /*
* Get the nodenumber from the filename * Load routevia noderecord to get the correct flavor.
* If there is no noderecord, reload the old one.
*/ */
noden.domain = NULL; if (!SearchNode(nodes.RouteVia))
noden.name = NULL; SearchNode(nodenr);
noden.zone = atoi(strtok(name, ".")); }
noden.net = atoi(strtok(NULL, "."));
noden.node = atoi(strtok(NULL, "."));
noden.point = atoi(strtok(NULL, "."));
if (SearchFidonet(noden.zone))
noden.domain = xstrcpy(fidonet.domain);
memset(&nodenr, 0, sizeof(nodenr)); Syslog('+', "Pack ARCmail for %s, via %s", aka2str(nodenr), ascfnode(&noden, 0x1f));
nodenr.zone = noden.zone;
nodenr.net = noden.net;
nodenr.node = noden.node;
nodenr.point = noden.point;
sprintf(nodenr.domain, "%s", noden.domain);
if (!SearchNode(nodenr)) { if (!do_quiet) {
WriteError("Downlink %s not found", aka2str(nodenr)); printf("\rAdding ARCmail for %s ", ascfnode(&noden, 0x1f));
if (noden.domain) fflush(stdout);
free(noden.domain); }
return FALSE;
}
/* if (getarchiver((char *)"ZIP")) {
* If we route via another aka, change everything. flavor = 'f';
*/ if (nodes.Crash)
if (nodes.RouteVia.zone) { flavor = 'c';
Syslog('p', "Route Via %s", aka2str(nodes.RouteVia)); if (nodes.Hold)
noden.zone = nodes.RouteVia.zone; flavor = 'h';
noden.net = nodes.RouteVia.net; } else {
noden.node = nodes.RouteVia.node; WriteError("Archiver ZIP not found");
noden.point = nodes.RouteVia.point; if (noden.domain)
if (noden.domain) free(noden.domain);
free(noden.domain); return FALSE;
noden.domain = xstrcpy(nodes.RouteVia.domain); }
/*
* Load routevia noderecord to get the correct flavor.
* If there is no noderecord, reload the old one.
*/
if (!SearchNode(nodes.RouteVia))
SearchNode(nodenr);
}
Syslog('+', "Pack ARCmail for %s, via %s", aka2str(nodenr), ascfnode(&noden, 0x1f)); /*
* Generate ARCmail filename and .PKT filename,
*/
arcfile = calloc(PATH_MAX, sizeof(char));
if (nodes.Session_out == S_DIR) {
if (!do_quiet) { Now = time(NULL);
printf("\rAdding ARCmail for %s ", ascfnode(&noden, 0x1f)); ptm = localtime(&Now);
fflush(stdout); ext = dow[ptm->tm_wday];
}
if (getarchiver((char *)"ZIP")) { if (!nodes.ARCmailCompat && (nodes.Aka[0].zone != noden.zone)) {
flavor = 'f'; /*
if (nodes.Crash) * Generate ARCfile name from the CRC of the ASCII string
flavor = 'c'; * of the node address.
if (nodes.Hold) */
flavor = 'h'; sprintf(arcfile, "%s/%08lx.%s0", nodes.Dir_out_path, StringCRC32(ascfnode(&noden, 0x1f)), ext);
} else { } else {
WriteError("Archiver ZIP not found"); bestaka = bestaka_s(&noden);
if (noden.domain)
free(noden.domain); if (noden.point) {
return FALSE; sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff,
((bestaka->node) - (noden.node) + (noden.point)) & 0xffff, ext);
} else if (bestaka->point) {
/*
* Inserted the next code for if we are a point,
* I hope this is ARCmail 0.60 compliant. 21-May-1999
*/
sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff,
((bestaka->node) - (noden.node) - (bestaka->point)) & 0xffff, ext);
} else {
sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff,
((bestaka->node) - (noden.node)) &0xffff, ext);
}
} }
Syslog('m', "Arcmail file %s", arcfile);
/* } else {
* Generate ARCmail filename and .PKT filename,
*/
arcfile = calloc(PATH_MAX, sizeof(char));
sprintf(arcfile, "%s", arcname(&noden, nodes.Aka[0].zone, nodes.ARCmailCompat)); sprintf(arcfile, "%s", arcname(&noden, nodes.Aka[0].zone, nodes.ARCmailCompat));
pktfile = calloc(40, sizeof(char)); }
sprintf(pktfile, "%08lx.pkt", sequencer()); pktfile = calloc(40, sizeof(char));
sprintf(pktfile, "%08lx.pkt", sequencer());
if (nodelock(&noden)) { if (nodes.Session_out == S_DIR) {
if (islocked(nodes.Dir_out_clock, nodes.Dir_out_chklck, nodes.Dir_out_waitclr)) {
Syslog('+', "Mail stays in queue, will be added later");
if (noden.domain)
free(noden.domain);
free(arcfile);
free(pktfile);
return FALSE;
} else {
if (! setlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck)) {
Syslog('+', "Mail stays in queue, will be added later"); Syslog('+', "Mail stays in queue, will be added later");
if (noden.domain) if (noden.domain)
free(noden.domain); free(noden.domain);
free(arcfile); free(arcfile);
free(pktfile); free(pktfile);
return FALSE; return FALSE;
}
} }
} else {
if (rename(srcfile, pktfile)) { if (nodelock(&noden)) {
WriteError("$Can't rename %s to %s", srcfile, pktfile); Syslog('+', "Mail stays in queue, will be added later");
nodeulock(&noden); if (noden.domain)
if (noden.domain) free(noden.domain);
free(noden.domain); free(arcfile);
free(arcfile); free(pktfile);
free(pktfile); return FALSE;
return FALSE;
} }
}
/* if (rename(srcfile, pktfile)) {
* Add zero word at the end of the .pkt file WriteError("$Can't rename %s to %s", srcfile, pktfile);
*/ if (nodes.Session_out == S_DIR)
if ((fp = fopen(pktfile, "a+")) == NULL) { remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck);
WriteError("$Can't open %s", pktfile);
nodeulock(&noden);
if (noden.domain)
free(noden.domain);
free(arcfile);
free(pktfile);
return FALSE;
}
putc('\0', fp);
putc('\0', fp);
fsync(fileno(fp));
fclose(fp);
/*
* Check the size of the existing archive if there is a size limit.
* Change to new archive names if the existing is too large.
* If the archive size is zero, it's an already sent archive, the
* number will be bumped also.
* If the archive is older then 6 days, the name is also bumped.
* Do this until we find a new name or if the last digit is a '9' or 'z'.
* Purge archives older then toss_days.
*/
nr = oldnr = '0';
Now = time(NULL);
if (nodes.ARCmailAlpha)
maxnr = 'z';
else else
maxnr = '9'; nodeulock(&noden);
Attach = FALSE; if (noden.domain)
free(noden.domain);
free(arcfile);
free(pktfile);
return FALSE;
}
for (;;) { /*
fsize = file_size(arcfile); * Add zero word at the end of the .pkt file
fage = (int)((Now - file_time(arcfile)) / 86400); */
if ((fp = fopen(pktfile, "a+")) == NULL) {
WriteError("$Can't open %s", pktfile);
if (nodes.Session_out == S_DIR)
remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck);
else
nodeulock(&noden);
if (noden.domain)
free(noden.domain);
free(arcfile);
free(pktfile);
return FALSE;
}
putc('\0', fp);
putc('\0', fp);
fsync(fileno(fp));
fclose(fp);
if (fsize == -1L) { /*
Attach = TRUE; * Check the size of the existing archive if there is a size limit.
break; * Change to new archive names if the existing is too large.
} * If the archive size is zero, it's an already sent archive, the
* number will be bumped also.
* If the archive is older then 6 days, the name is also bumped.
* Do this until we find a new name or if the last digit is a '9' or 'z'.
* Purge archives older then toss_days.
*/
nr = oldnr = '0';
Now = time(NULL);
if (nodes.ARCmailAlpha)
maxnr = 'z';
else
maxnr = '9';
Attach = FALSE;
if (fsize == 0L) { for (;;) {
if ((fage > 6) && (nr < maxnr)) { fsize = file_size(arcfile);
/* fage = (int)((Now - file_time(arcfile)) / 86400);
* Remove truncated ARCmail files older then 6 days.
*/
unlink(arcfile);
fsize = -1L;
Attach = TRUE;
break;
}
/*
* Increase filename extension if there is a truncated file of today.
*/
nr++;
if (nr == ('9' +1))
nr = 'a';
arcfile[strlen(arcfile) -1] = nr;
} else if (CFG.maxarcsize && (fsize > (CFG.maxarcsize * 1024)) && (nr < maxnr)) { if (fsize == -1L) {
/* Attach = TRUE;
* Use a new ARCmail file if the last one is too big. break;
*/ }
nr++;
if (nr == ('9' +1))
nr = 'a';
arcfile[strlen(arcfile) -1] = nr;
}
fsize = file_size(arcfile); if (fsize == 0L) {
fage = (int)((Now - file_time(arcfile)) / 86400); if ((fage > 6) && (nr < maxnr)) {
/*
* Remove truncated ARCmail files older then 6 days.
*/
unlink(arcfile);
fsize = -1L;
Attach = TRUE;
break;
}
/*
* Increase filename extension if there is a truncated file of today.
*/
nr++;
if (nr == ('9' +1))
nr = 'a';
arcfile[strlen(arcfile) -1] = nr;
if ((fsize > 0L) && (fage > 6) && (nr < maxnr)) { } else if (CFG.maxarcsize && (fsize > (CFG.maxarcsize * 1024)) && (nr < maxnr)) {
/* /*
* If there is ARCmail of a week old or older, add mail * Use a new ARCmail file if the last one is too big.
* to a new ARCmail bundle. */
*/ nr++;
nr++; if (nr == ('9' +1))
if (nr == ('9' +1)) nr = 'a';
nr = 'a'; arcfile[strlen(arcfile) -1] = nr;
arcfile[strlen(arcfile) -1] = nr;
}
if (oldnr == nr)
break;
else
oldnr = nr;
} }
fsize = file_size(arcfile); fsize = file_size(arcfile);
if (execute(archiver.marc, arcfile, pktfile, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { fage = (int)((Now - file_time(arcfile)) / 86400);
unlink(pktfile);
} else { if ((fsize > 0L) && (fage > 6) && (nr < maxnr)) {
sync(); /*
sleep(1); * If there is ARCmail of a week old or older, add mail
Syslog('+', "Create ARCmail failed, trying again after sync()"); * to a new ARCmail bundle.
if (execute(archiver.marc, arcfile, pktfile, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { */
unlink(pktfile); nr++;
} else { if (nr == ('9' +1))
WriteError("Can't add %s to ARCmail archive", pktfile); nr = 'a';
} arcfile[strlen(arcfile) -1] = nr;
} }
/* if (oldnr == nr)
* Attach file to .flo break;
*/ else
if (Attach) oldnr = nr;
attach(noden, arcfile, TFS, flavor); }
fsize = file_size(arcfile);
if (execute(archiver.marc, arcfile, pktfile, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
unlink(pktfile);
} else {
sync();
sleep(1);
Syslog('+', "Create ARCmail failed, trying again after sync()");
if (execute(archiver.marc, arcfile, pktfile, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
unlink(pktfile);
} else {
WriteError("Can't add %s to ARCmail archive", pktfile);
}
}
if (nodes.Session_out == S_DIR) {
/*
* Change filemode so downlink has rights to the file.
*/
chmod(arcfile, 0660);
}
/*
* Attach file to .flo, not for FTP or Directory sessions.
*/
if (Attach && nodes.Session_out == S_DIRECT)
attach(noden, arcfile, TFS, flavor);
if (nodes.Session_out == S_DIR)
remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck);
else
nodeulock(&noden); nodeulock(&noden);
if (noden.domain) if (noden.domain)
free(noden.domain); free(noden.domain);
free(arcfile); free(arcfile);
free(pktfile); free(pktfile);
return TRUE; return TRUE;
} }
@ -282,95 +356,128 @@ int pack_queue(char *name)
*/ */
int add_queue(char *name) int add_queue(char *name)
{ {
faddr noden; faddr noden;
char flavor; char flavor, srcfile[128], *outfile, *buf;
char srcfile[128], *outfile; FILE *inf, *ouf;
char *buf; int bread;
FILE *inf, *ouf;
int bread;
sprintf(srcfile, "%s", name); sprintf(srcfile, "%s", name);
/* /*
* Get the nodenumber from the filename * Get the nodenumber from the filename
*/ */
noden.domain = NULL; noden.domain = NULL;
noden.name = NULL; noden.name = NULL;
noden.zone = atoi(strtok(name, ".")); noden.zone = atoi(strtok(name, "."));
noden.net = atoi(strtok(NULL, ".")); noden.net = atoi(strtok(NULL, "."));
noden.node = atoi(strtok(NULL, ".")); noden.node = atoi(strtok(NULL, "."));
noden.point = atoi(strtok(NULL, ".")); noden.point = atoi(strtok(NULL, "."));
if (SearchFidonet(noden.zone)) if (SearchFidonet(noden.zone))
noden.domain = xstrcpy(fidonet.domain); noden.domain = xstrcpy(fidonet.domain);
Syslog('+', "Add Netmail for %s", ascfnode(&noden, 0x1f)); Syslog('+', "Add Netmail for %s", ascfnode(&noden, 0x1f));
if (!do_quiet) { if (!do_quiet) {
printf("\rAdding Netmail for %s ", ascfnode(&noden, 0x1f)); printf("\rAdding Netmail for %s ", ascfnode(&noden, 0x1f));
fflush(stdout); fflush(stdout);
} }
outfile = calloc(128, sizeof(char)); outfile = calloc(PATH_MAX, sizeof(char));
if (strstr(srcfile, ".iii")) if (strstr(srcfile, ".iii"))
flavor = 'i'; flavor = 'i';
else if (strstr(srcfile, ".ccc")) else if (strstr(srcfile, ".ccc"))
flavor = 'c'; flavor = 'c';
else if (strstr(srcfile, ".hhh")) else if (strstr(srcfile, ".hhh"))
flavor = 'h'; flavor = 'h';
else
flavor = 'f';
if (nodes.Session_out == S_DIR) {
if (flavor == 'f')
flavor = 'o';
if (noden.point)
sprintf(outfile, "%s/%08x.%cut", nodes.Dir_out_path, noden.point, flavor);
else else
flavor = 'f'; sprintf(outfile, "%s/%04x%04x.%cut", nodes.Dir_out_path, noden.net, noden.node, flavor);
} else {
sprintf(outfile, "%s", pktname(&noden, flavor)); sprintf(outfile, "%s", pktname(&noden, flavor));
Syslog('p', "Outfile: %s", outfile); }
Syslog('p', "Outfile: %s", outfile);
if (nodelock(&noden)) { if (nodes.Session_out == S_DIR) {
Syslog('+', "Mail stays in queue, will be added later"); if (islocked(nodes.Dir_out_clock, nodes.Dir_out_chklck, nodes.Dir_out_waitclr)) {
free(outfile); Syslog('+', "Mail stays in queue, will be added later");
if (noden.domain) if (noden.domain)
free(noden.domain);
return FALSE;
}
/*
* Now we must see if there is already mail in the outbound.
* If that's the case, we must skip the .pkt header from the queue
* because there is already a .pkt header also, append to the
* outbound 2 bytes before the end of file, this is the zero word.
*/
if ((inf = fopen(srcfile, "r")) != NULL) {
if (access(outfile, R_OK) == -1) {
ouf = fopen(outfile, "w"); /* create new */
Syslog('p', "Create new %s", outfile);
} else {
ouf = fopen(outfile, "r+"); /* open R/W */
fseek(ouf, -2, SEEK_END); /* b4 0 word */
fseek(inf, 58, SEEK_SET); /* skip header */
Syslog('p', "Append to %s", outfile);
}
if (ouf != NULL) {
buf = malloc(16384);
do {
bread = fread(buf, 1, 16384, inf);
fwrite(buf, 1, bread, ouf);
} while (bread);
free(buf);
putc('\0', ouf);
putc('\0', ouf);
fsync(fileno(ouf));
fclose(ouf);
fclose(inf);
unlink(srcfile);
} else {
WriteError("$Can't open %s", outfile);
fclose(inf);
}
}
nodeulock(&noden);
if (noden.domain)
free(noden.domain); free(noden.domain);
free(outfile); return FALSE;
return TRUE; } else {
if (! setlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck)) {
Syslog('+', "Mail stays in queue, will be added later");
if (noden.domain)
free(noden.domain);
return FALSE;
}
}
} else {
if (nodelock(&noden)) {
Syslog('+', "Mail stays in queue, will be added later");
free(outfile);
if (noden.domain)
free(noden.domain);
return FALSE;
}
}
/*
* Now we must see if there is already mail in the outbound.
* If that's the case, we must skip the .pkt header from the queue
* because there is already a .pkt header also, append to the
* outbound 2 bytes before the end of file, this is the zero word.
*/
if ((inf = fopen(srcfile, "r")) != NULL) {
if (access(outfile, R_OK) == -1) {
ouf = fopen(outfile, "w"); /* create new */
Syslog('p', "Create new %s", outfile);
} else {
ouf = fopen(outfile, "r+"); /* open R/W */
fseek(ouf, -2, SEEK_END); /* b4 0 word */
fseek(inf, 58, SEEK_SET); /* skip header */
Syslog('p', "Append to %s", outfile);
}
if (ouf != NULL) {
buf = malloc(16384);
do {
bread = fread(buf, 1, 16384, inf);
fwrite(buf, 1, bread, ouf);
} while (bread);
free(buf);
putc('\0', ouf);
putc('\0', ouf);
fsync(fileno(ouf));
fclose(ouf);
fclose(inf);
unlink(srcfile);
} else {
WriteError("$Can't open %s", outfile);
fclose(inf);
}
}
if (nodes.Session_out == S_DIR) {
/*
* Change filemode so downlink has rights to the file.
*/
chmod(outfile, 0660);
}
if (nodes.Session_out == S_DIR)
remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck);
else
nodeulock(&noden);
if (noden.domain)
free(noden.domain);
free(outfile);
return TRUE;
} }
@ -380,53 +487,52 @@ int add_queue(char *name)
*/ */
void packmail() void packmail()
{ {
char *temp; char *temp;
struct dirent *de; struct dirent *de;
DIR *dp; DIR *dp;
if (!diskfree(CFG.freespace)) if (!diskfree(CFG.freespace))
return; return;
IsDoing("Packing mail"); IsDoing("Packing mail");
if (!do_quiet) { if (!do_quiet) {
colour(9, 0); colour(9, 0);
printf("Packing mail\n"); printf("Packing mail\n");
colour(3, 0); colour(3, 0);
} }
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/tmp", getenv("MBSE_ROOT")); sprintf(temp, "%s/tmp", getenv("MBSE_ROOT"));
if (chdir(temp) == -1) { if (chdir(temp) == -1) {
WriteError("$Error chdir to %s", temp); WriteError("$Error chdir to %s", temp);
free(temp);
return;
}
if ((dp = opendir(temp)) == NULL) {
WriteError("$Error opendir %s", temp);
free(temp);
return;
}
/*
* Scan the $MBSE_ROOT/tmp directory for .qqq or .nnn files
*/
while ((de = readdir(dp))) {
if (strstr(de->d_name, ".qqq"))
pack_queue(de->d_name);
if (strstr(de->d_name, ".nnn") || strstr(de->d_name, ".iii") ||
strstr(de->d_name, ".ccc") || strstr(de->d_name, ".hhh"))
add_queue(de->d_name);
}
closedir(dp);
free(temp); free(temp);
return;
}
if (!do_quiet) { if ((dp = opendir(temp)) == NULL) {
printf("\r \r"); WriteError("$Error opendir %s", temp);
fflush(stdout); free(temp);
} return;
}
/*
* Scan the $MBSE_ROOT/tmp directory for .qqq or .nnn files
*/
while ((de = readdir(dp))) {
if (strstr(de->d_name, ".qqq"))
pack_queue(de->d_name);
if (strstr(de->d_name, ".nnn") || strstr(de->d_name, ".iii") || strstr(de->d_name, ".ccc") || strstr(de->d_name, ".hhh"))
add_queue(de->d_name);
}
closedir(dp);
free(temp);
if (!do_quiet) {
printf("\r \r");
fflush(stdout);
}
} }