home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
XFER.C
< prev
next >
Wrap
Text File
|
1992-05-05
|
38KB
|
1,745 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988-1991 by Wayne Bell
Distribution of the source code for WWIV, in any form, modified or unmodified,
without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
Distribution of compiled versions of WWIV is limited to copies compiled BY
THE AUTHOR. Distribution of any copies of WWIV not compiled by the author
is expressly prohibited.
*****************************************************************************/
#include "vars.h"
#pragma hdrstop
#include <dir.h>
#define SETREC(i) lseek(dlf,((long) (i))*((long)sizeof(uploadsrec)),SEEK_SET);
/* How far to indent extended descriptions */
#define INDENTION 24
/* Max # of lines for extended description */
#define MAX_LINES 10
/* If its OK to use the FSED for editing extended descriptions */
#define FSED_OK ((okfsed()) && (0))
/* If this is defined, the system will put in "ASK" if a file isn't there */
#define CHECK_FOR_EXISTANCE
/* the archive type to use */
#define ARC_NUMBER 0
int check_batch_queue(char *fn)
{
int i;
for (i=0; i<numbatch; i++) {
if (strcmp(fn,batch[i].filename)==0)
if (batch[i].sending)
return(1);
else
return(-1);
}
return(0);
}
int check_ul_event(int dn, uploadsrec *u)
{
char s[161];
if (syscfg.upload_c[0]) {
stuff_in(s,syscfg.upload_c,create_chain_file("CHAIN.TXT"),
directories[dn].path,stripfn(u->filename),"","");
run_external(s);
topscreen();
sprintf(s,"%s%s",directories[dn].path, stripfn(u->filename));
if (!exist(s)) {
sprintf(s,"File '%s' to %s deleted by UL event.",
u->filename, directories[dn].name);
sysoplog(s);
npr("File '%s' was deleted by upload event.\r\n",u->filename);
return(1);
}
}
return(0);
}
int okfn(char *s)
{
int i,l,ok;
unsigned char ch;
ok=1;
l=strlen(s);
if ((s[0]=='-') || (s[0]==' '))
ok=0;
for (i=0; i<l; i++) {
ch=s[i];
if ((ch==' ') || (ch=='/') || (ch=='\\') || (ch==':') ||
(ch=='>') || (ch=='<') || (ch=='|') || (ch=='+') ||
(ch==',') || (ch==';') || (ch>126))
ok=0;
}
return(ok);
}
char *make_abs_cmd(char *out)
{
char s[161],s1[161],*ss,*ss1;
strcpy(s1,out);
ss=strchr(s1,' ');
if (ss)
*ss=0;
strcpy(s,s1);
ss1=searchpath(s);
if (!ss1) {
sprintf(s,"%s.COM",s1);
ss1=searchpath(s);
}
if (!ss1) {
sprintf(s,"%s.EXE",s1);
ss1=searchpath(s);
}
if (!ss1) {
sprintf(s,"%s.BAT",s1);
ss1=searchpath(s);
}
if (ss1)
strcpy(s,ss1);
else {
strcpy(s,cdir);
strcat(s,s1);
}
if (ss) {
strcat(s," ");
strcat(s,ss+1);
}
strcpy(out,s);
return(out);
}
void get_arc_cmd(char *out, char *arcfn, int cmd, char *ofn)
{
char *ss,*ss1,s[161],s1[161];
int i;
out[0]=0;
ss=strchr(arcfn,'.');
if (ss==NULL)
return;
++ss;
ss1=strchr(ss,'.');
while (ss1!=NULL) {
ss=ss1;
++ss1;
ss1=strchr(ss,'.');
}
for (i=0; i<4; i++)
if (stricmp(ss,syscfg.arcs[i].extension)==0) {
switch(cmd) {
case 0: strcpy(s,syscfg.arcs[i].arcl); break;
case 1: strcpy(s,syscfg.arcs[i].arce); break;
case 2: strcpy(s,syscfg.arcs[i].arca); break;
}
if (s[0]==0)
return;
stuff_in(out,s,arcfn,ofn,"","","");
make_abs_cmd(out);
return;
}
}
int list_arc_out(char *fn, char *dir)
{
char s[161],s1[81];
int i=0;
sprintf(s1,"%s%s",dir,fn);
get_arc_cmd(s,s1,0,"");
if (!okfn(fn))
s[0]=0;
if (exist(s1) && (s[0]!=0)) {
nl();
nl();
npr("1Archive listing for3 %s1:\r\n",fn);
nl();
i=do_external(s,1);
nl();
} else {
nl();
outs("6Unknown archive: ");
pl(fn);
nl();
i=0;
}
return(i);
}
int ratio_ok()
{
int ok=1;
char s[101];
if (!(thisuser.exempt & exempt_ratio))
if ((syscfg.req_ratio>0.0001) && (ratio()<syscfg.req_ratio)) {
ok=0;
nl();
nl();
sprintf(s,"1Your up/download ratio is6 %-5.3f1. You need a ratio of 6%-5.3f 1to download.",
ratio(), syscfg.req_ratio);
pl(s);
nl();
}
if (!(thisuser.exempt & exempt_post))
if ((syscfg.post_call_ratio>0.0001) && (post_ratio()<syscfg.post_call_ratio)) {
ok=0;
nl();
nl();
sprintf(s,"1Your post/call ratio is 6%-5.3f1. You need a ratio of 6%-5.3f to download.",
post_ratio(), syscfg.post_call_ratio);
pl(s);
nl();
}
return(ok);
}
int dcs()
{
if (cs())
return(1);
if (thisuser.dsl>=100)
return(1);
else
return(0);
}
void dliscan1(int dn)
{
char s[81];
int i;
uploadsrec u;
long l;
sprintf(s,"%s%s.DIR",syscfg.datadir,directories[dn].filename);
dlf=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
i=filelength(dlf)/sizeof(uploadsrec);
if (i==0) {
memset(&u, 0, sizeof(uploadsrec));
strcpy(u.filename,"|MARKER|");
time(&l);
u.daten=l;
SETREC(0);
write(dlf,(void *)&u,sizeof(uploadsrec));
} else {
SETREC(0);
read(dlf,(void *)&u,sizeof(uploadsrec));
if (strcmp(u.filename,"|MARKER|")) {
numf=u.numbytes;
memset(&u, 0, sizeof(uploadsrec));
strcpy(u.filename,"|MARKER|");
time(&l);
u.daten=l;
u.numbytes = numf;
SETREC(0);
write(dlf, &u, sizeof(uploadsrec));
}
}
numf=u.numbytes;
this_date = u.daten;
dir_dates[dn]=this_date;
sprintf(s,"%s%s.EXT",syscfg.datadir,directories[dn].filename);
edlf=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
}
void dliscan_hash(int dn)
{
char s[81];
int i,dlf;
uploadsrec u;
if ((dn>=num_dirs) || (dir_dates[dn]))
return;
sprintf(s,"%s%s.DIR",syscfg.datadir,directories[dn].filename);
dlf=open(s,O_RDWR | O_BINARY);
if (dlf<0) {
time(&(dir_dates[dn]));
return;
}
i=filelength(dlf)/sizeof(uploadsrec);
if (i<1) {
time(&(dir_dates[dn]));
} else {
SETREC(0);
read(dlf,(void *)&u,sizeof(uploadsrec));
if (strcmp(u.filename,"|MARKER|")==0) {
dir_dates[dn]=u.daten;
} else {
time(&(dir_dates[dn]));
}
}
close(dlf);
}
void dliscan()
{
dliscan1(udir[curdir].subnum);
}
void closedl()
{
if (dlf>0) {
close(dlf);
dlf=-1;
}
if (edlf>0) {
close(edlf);
edlf=-1;
}
}
void add_extended_description(char *fn, char *desc)
{
ext_desc_type ed;
strcpy(ed.name,fn);
ed.len=strlen(desc);
lseek(edlf,0L,SEEK_END);
write(edlf,&ed,sizeof(ext_desc_type));
write(edlf,desc,ed.len);
}
void delete_extended_description(char *fn)
{
ext_desc_type ed;
long r,w,l1;
char *ss=NULL;
r=w=0;
if ((ss=malloca(10240L))==NULL)
return;
l1=filelength(edlf);
while (r<l1) {
lseek(edlf,r,SEEK_SET);
read(edlf,&ed,sizeof(ext_desc_type));
if (ed.len<10000) {
read(edlf,ss,ed.len);
if (strcmp(fn,ed.name)) {
if (r!=w) {
lseek(edlf,w,SEEK_SET);
write(edlf,&ed,sizeof(ext_desc_type));
write(edlf,ss,ed.len);
}
w +=(sizeof(ext_desc_type) + ed.len);
}
}
r += (sizeof(ext_desc_type) + ed.len);
}
farfree(ss);
chsize(edlf,w);
}
char *read_extended_description(char *fn)
{
ext_desc_type ed;
long l,l1;
char *ss=NULL;
l=0;
l1=filelength(edlf);
while (l<l1) {
lseek(edlf,l,SEEK_SET);
l += (long) read(edlf,&ed,sizeof(ext_desc_type));
if (strcmp(fn,ed.name)==0) {
ss=malloca((long) ed.len+10);
if (ss) {
read(edlf,ss,ed.len);
ss[ed.len]=0;
}
return(ss);
} else
l += (long) ed.len;
}
return(NULL);
}
void print_extended(char *fn, int *abort, unsigned char numlist, int indent)
{
char *ss;
int next=0;
unsigned char numl=0;
int cpos=0;
char ch,s[81];
int i,fc;
fc=thisuser.sysstatus & sysstatus_funky_colors;
ss=read_extended_description(fn);
if (ss) {
ch=10;
while ((ss[cpos]) && (!(*abort)) && (numl<numlist)) {
if ((ch==10) && (indent)) {
if (okansi()) {
if (fc)
sprintf(s,"3│\x1b[%dC1",INDENTION);
else
sprintf(s,"│\x1b[%dC",INDENTION);
} else {
outstr(":");
for (i=0; i<INDENTION; i++)
s[i]=32;
s[INDENTION]=0;
}
osan(s,abort,&next);
}
ch=ss[cpos++];
if ((ch==13) && (indent)) {
while (!(wherex()>=77))
outstr(" ");
if (okansi()) {
if (fc)
outstr("3│");
else
outstr("│");
} else
outstr(":");
}
outchr(ch);
checka(abort,&next);
if (ch==10)
++numl;
else {
if ((ch!=13) && (wherex()>=77)) {
while (!(wherex()>=77))
outstr(" ");
if (fc)
ansic(3);
if (okansi())
outstr("│");
else
outstr(":");
osan("\r\n",abort,&next);
ch=10;
}
}
}
if (wherex())
nl();
}
farfree(ss);
}
void modify_extended_description(char **sss)
{
char s[161],s1[161];
int f,ii,i,i1,i2;
if (*sss)
ii=1;
else
ii=0;
do {
if (ii) {
nl();
if (FSED_OK)
prt(3,"Modify the extended description5? ");
else
prt(7,"Enter a new extended description1? ");
if (!yn())
return;
} else {
nl();
prt(7,"Enter an extended description1? ");
if (!yn())
return;
}
if (FSED_OK) {
sprintf(s,"%sEXTENDED.DSC", syscfg.tempdir);
if (*sss) {
f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
write(f,*sss,strlen(*sss));
close(f);
farfree(*sss);
*sss=NULL;
} else
unlink(s);
i=thisuser.screenchars;
if (thisuser.screenchars>(76-INDENTION))
thisuser.screenchars=76-INDENTION;
i1=external_edit("extended.dsc",syscfg.tempdir,(int) thisuser.defed-1,MAX_LINES);
thisuser.screenchars=i;
if (i1) {
if ((*sss=malloca(10240))==NULL)
return;
f=open(s,O_RDWR | O_BINARY);
read(f,*sss,(int) filelength(f));
(*sss)[filelength(f)]=0;
close(f);
}
} else {
if (*sss)
farfree(*sss);
if ((*sss=malloca(10240))==NULL)
return;
*sss[0]=0;
i=1;
nl();
sprintf(s,"1Enter up to 3%d 1lines, 3%d 1chars each.",MAX_LINES,78-INDENTION);
pl(s);
nl();
s[0]=0;
i1=thisuser.screenchars;
if (thisuser.screenchars>(76-INDENTION))
thisuser.screenchars=76-INDENTION;
do {
ansic(2);
npr("%d: ",i);
ansic(0);
s1[0]=0;
inli(s1,s,90,1);
i2=strlen(s1);
if (i2 && (s1[i2-1]==1))
s1[i2-1]=0;
if (s1[0]) {
strcat(s1,"\r\n");
strcat(*sss,s1);
}
} while ((i++<10) && (s1[0]));
thisuser.screenchars=i1;
if (*sss[0]==0) {
farfree(*sss);
*sss=NULL;
}
}
prt(3,"Is this what you want5? ");
i=!yn();
if (i) {
farfree(*sss);
*sss=NULL;
}
} while (i);
}
void align(char *s)
{
char f[40],e[40],s1[20],*s2;
int i,i1,i2;
i1=0;
if (s[0]=='.')
i1=1;
for (i=0; i<strlen(s); i++)
if ((s[i]=='\\') || (s[i]=='/') || (s[i]==':') || (s[i]=='<') ||
(s[i]=='>') || (s[i]=='|'))
i1=1;
if (i1) {
strcpy(s," . ");
return;
}
s2=strchr(s,'.');
if (s2==NULL) {
e[0]=0;
} else {
strcpy(e,&(s2[1]));
e[3]=0;
s2[0]=0;
}
strcpy(f,s);
for (i=strlen(f); i<8; i++)
f[i]=32;
f[8]=0;
i1=0;
i2=0;
for (i=0; i<8; i++) {
if (f[i]=='*')
i1=1;
if (f[i]==' ')
i2=1;
if (i2)
f[i]=' ';
if (i1)
f[i]='?';
}
for (i=strlen(e); i<3; i++)
e[i]=32;
e[3]=0;
i1=0;
for (i=0; i<3; i++) {
if (e[i]=='*')
i1=1;
if (i1)
e[i]='?';
}
for (i=0; i<12; i++)
s1[i]=32;
strcpy(s1,f);
s1[8]='.';
strcpy(&(s1[9]),e);
strcpy(s,s1);
for (i=0; i<12; i++)
s[i]=upcase(s[i]);
}
int compare(char *s1, char *s2)
{
int ok,i;
ok=1;
for (i=0; i<12; i++)
if ((s1[i]!=s2[i]) && (s1[i]!='?') && (s2[i]!='?'))
ok=0;
return(ok);
}
void printinfo(uploadsrec *u, int *abort)
{
char s[85],s1[40],s2[81];
int i,next,fc;
fc=thisuser.sysstatus & sysstatus_funky_colors;
if (fc)
ansic(3);
if (okansi())
strcpy(s,"│ ");
else
strcpy(s,": ");
osan(s,abort,&next);
strncpy(s,u->filename,8);
s[8]=0;
if (fc)
ansic(2);
osan(s,abort,&next);
strncpy(s,&((u->filename)[8]),4);
s[4]=0;
if (fc)
ansic(2);
osan(s,abort,&next);
if (fc)
ansic(3);
if (okansi())
osan(" │ ",abort,&next);
else
osan(" : ",abort,&next);
ltoa((((u->numbytes)+1023)/1024),s1,10);
strcat(s1,"k");
#ifdef CHECK_FOR_EXISTANCE
strcpy(s2,directories[udir[curdir].subnum].path);
strcat(s2,u->filename);
if (!exist(s2))
strcpy(s1,"REQ");
#endif
for (i=0; i<5-strlen(s1); i++)
s[i]=32;
s[i]=0;
strcat(s,s1);
if (fc)
ansic(5);
osan(s,abort,&next);
if (fc)
ansic(3);
if (okansi())
osan(" │ ",abort,&next);
else
osan(" : ",abort,&next);
if (fc)
ansic(1);
if (okansi())
if (fc)
sprintf(s,"%-51.51s 3│",u->description);
else
sprintf(s,"%-51.51s │",u->description);
else
sprintf(s,"%-51.51s :",u->description);
pla(s,abort);
if ((!*abort) && (thisuser.num_extended) && (u->mask & mask_extended))
print_extended(u->filename,abort,thisuser.num_extended,1);
if (!(*abort))
++num_listed;
}
void printtitle(int *abort)
{
char s[81],s1[20],s2[101];
int i,i1,fc;
fc=thisuser.sysstatus & sysstatus_funky_colors;
nl();
nl();
npr("5Area:7 [1%s7]",directories[udir[curdir].subnum].name," - ",udir[curdir].keys,"");
nl();
if (okansi()) {
if (fc)
ansic(3);
pla("┌──────────────┬───────┬─────────────────────────────────────────────────────┐",abort);
if (fc)
sprintf(s2,"3│ 2Filename.Ext 3│ 5Size 3 │ 1Description Total Files: %3d 3│",numf);
else
sprintf(s2,"│ Filename.Ext │ Size │ Description Total Files: %3d │",numf);
pla(s2,abort);
if (fc)
ansic(3);
pla("├──────────────┼───────┼─────────────────────────────────────────────────────┤",abort);
} else {
pla("+--------------+-------+-----------------------------------------------------+",abort);
sprintf(s2,": Filename.Ext : Size : Description Total Files: %3d :",numf);
pla(s2,abort);
pla("+--------------+-------+-----------------------------------------------------+",abort);
}
}
void file_mask(char *s)
{
nl();
helpl=9;
prt(1,"File mask3: ");
input(s,12);
if (s[0]==0)
strcpy(s,"*.*");
if (strchr(s,'.')==NULL)
strcat(s,".*");
align(s);
nl();
}
void listfiles()
{
char s[81];
int i,abort,fc;
uploadsrec u;
fc=thisuser.sysstatus & sysstatus_funky_colors;
dliscan();
file_mask(s);
abort=0;
num_listed=0;
printtitle(&abort);
for (i=1; (i<=numf) && (!abort) && (!hangup); i++) {
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
if (compare(s,u.filename))
printinfo(&u,&abort);
}
closedl();
if (!abort) {
if (fc)
ansic(3);
if (okansi())
pla("└──────────────┴───────┴─────────────────────────────────────────────────────┘",&abort);
else
pla("+--------------+-------+-----------------------------------------------------+",&abort);
nl();
sprintf(s,"3[ 2Files listed:1 %d",num_listed);
outstr(s);
pl(" 3]");
nl();
}
}
void nscandir(int d, int *abort,int title)
{
int i,od,dt,fc,pc;
uploadsrec u;
char s[81];
fc=thisuser.sysstatus & sysstatus_funky_colors;
od=curdir;
curdir=d;
dt=title;
pc=0;
dliscan();
for (i=1; (i<=numf) && (!(*abort)) && (!hangup); i++) {
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
if (u.daten>=nscandate) {
if (dt) {
printtitle(abort);
dt=0;
pc=1;
}
printinfo(&u,abort);
}
}
if ((pc) && (!(*abort))) {
if (fc)
ansic(3);
if (okansi())
pl("└──────────────┴───────┴─────────────────────────────────────────────────────┘");
else
pl("+--------------+-------+-----------------------------------------------------+");
nl();
pc=0;
}
closedl();
curdir=od;
}
void nscanall()
{
int abort,i,i1;
char s[81];
abort=0;
num_listed=0;
for (i=0; (i<64) && (!abort) && (udir[i].subnum!=-1); i++) {
i1=udir[i].subnum;
if (i1>=32) {
if (thisuser.nscn2 & (1L << (i1-32)))
nscandir(i,&abort,1);
} else {
if (thisuser.nscn1 & (1L << i1))
nscandir(i,&abort,1);
}
}
if ((num_listed) && (!abort)) {
nl();
nl();
sprintf(s,"1Files listed:7 %d",num_listed);
pl(s);
nl();
}
}
void searchall()
{
int i,i1,pts,abort,pty,ocd,pc,fc;
char s[81],s1[81];
uploadsrec u;
fc=thisuser.sysstatus & sysstatus_funky_colors;
abort=0;
ocd=curdir;
pc=0;
nl();
nl();
pl("Search all directories.");
file_mask(s);
num_listed=0;
for (i=0; (i<64) && (!abort) && (!hangup) && (udir[i].subnum!=-1); i++) {
i1=udir[i].subnum;
pts=0;
if (i1>=32) {
if (thisuser.nscn2 & (1L << (i1-32)))
pts=1;
} else {
if (thisuser.nscn1 & (1L << i1))
pts=1;
}
pts=1;
/* remove pts=1 to search only marked directories */
if (pts) {
curdir=i;
dliscan();
pty=1;
for (i1=1; (i1<=numf) && (!abort) && (!hangup); i1++) {
SETREC(i1);
read(dlf,(void *)&u,sizeof(uploadsrec));
if (compare(s,u.filename)) {
if (pty) {
printtitle(&abort);
pty=0;
pc=1;
}
printinfo(&u,&abort);
}
}
if (pc) {
if (fc)
ansic(3);
if (okansi())
pla("└──────────────┴───────┴─────────────────────────────────────────────────────┘",&abort);
else
pla("+--------------+-------+-----------------------------------------------------+",&abort);
nl();
pc=0;
}
closedl();
}
}
curdir=ocd;
if ((num_listed) && (!abort)) {
nl();
nl();
sprintf(s,"Files listed: %d",num_listed);
pl(s);
nl();
}
}
int recno(char *s)
{
int i;
uploadsrec u;
i=1;
if (numf<1)
return(-1);
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
while ((i<numf) && (compare(s,u.filename)==0)) {
++i;
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
}
if (compare(s,u.filename))
return(i);
else
return(-1);
}
int nrecno(char *s,int i1)
{
int i;
uploadsrec u;
i=i1+1;
if ((numf<1) || (i1>=numf))
return(-1);
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
while ((i<numf) && (compare(s,u.filename)==0)) {
++i;
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
}
if (compare(s,u.filename))
return(i);
else
return(-1);
}
int printfileinfo(uploadsrec *u, int dn)
{
char s[81];
double d;
int i,abort;
d=((double) (((u->numbytes)+127)/128)) *
(1620.0) /
((double) (modem_speed));
npr("1Filename : %s\r\n", stripfn(u->filename));
npr("2Description: %s\r\n", u->description);
npr("3File size : %dk\r\n", ((u->numbytes)+1023)/1024);
npr("5Apprx. time: %s\r\n", ctim(d));
npr("7Uploaded on: %s\r\n", u->date);
npr("1Uploaded by: %s\r\n", u->upby);
npr("2Times D/L'd: %d\r\n", u->numdloads);
nl();
abort=0;
if (u->mask & mask_extended) {
pl("3Extended Description: ");
print_extended(u->filename,&abort,255,0);
}
sprintf(s,"%s%s",directories[dn].path,u->filename);
if (!exist(s)) {
nl();
pl("1->7MUST BE REQUESTED1<-");
nl();
prt(1,"Request file?");
if (yn()) {
sprintf(irt,"File Request5: 1%s", stripfn(u->filename));
irt_name[0]=0;
email(1,0,1,0);
return(-1);
}
}
if (nsl()>=d)
return(1);
else
return(0);
}
void upload(int dn)
{
directoryrec d;
uploadsrec u,u1;
int i,i1,i2,ok,xfer,f;
char s[255],s1[81],*ss;
long l;
double ti;
dliscan1(dn);
d=directories[dn];
if (numf>=d.maxfiles) {
nl();
nl();
pl("3This directory is currently full5.");
nl();
closedl();
return;
}
if ((d.mask & mask_no_uploads) && (!dcs())) {
nl();
nl();
pl("3Uploads are not allowed5.");
nl();
closedl();
return;
}
nl();
l=(long)freek1(d.path);
sprintf(s,"7Upload 1- 3%ldk free5.",l);
pl(s);
nl();
if (l<100) {
pl("3Not enough disk space to upload here5.");
nl();
closedl();
return;
}
prt(1,"What's the filename3? ");
input(s,12);
if (!okfn(s))
s[0]=0;
align(s);
if (strchr(s,'?')) {
closedl();
return;
}
if (d.mask & mask_archive) {
ok=0;
s1[0]=0;
for (i=0; i<4; i++) {
if (syscfg.arcs[i].extension[0] && syscfg.arcs[i].extension[0]!=' ') {
if (s1[0])
strcat(s1,", ");
strcat(s1,syscfg.arcs[i].extension);
if (strcmp(s+9,syscfg.arcs[i].extension)==0)
ok=1;
}
}
if (!ok) {
nl();
pl("3Sorry, all uploads to this dir must");
pl("3be archived. Supported types are:");
pl(s1);
nl();
closedl();
return;
}
}
strcpy(u.filename,s);
u.ownerusr=usernum;
u.ownersys=0;
u.numdloads=0;
u.filetype=0;
u.mask=0;
strcpy(u.upby,nam1(&thisuser,usernum,syscfg.systemnumber));
strcpy(u.date,date());
nl();
ok=1;
xfer=1;
if (check_batch_queue(u.filename)) {
ok=0;
nl();
pl("1That file is already in the batch queue.");
nl();
} else {
sprintf(s1,"3Upload 1'5%s1' 3to 5%s1? ",s,d.name);
if (strcmp(s," . "))
prt(5,s1);
else
ok=0;
}
if ((ok) && (yn())) {
sprintf(s1,"%s%s",d.path,s);
if (exist(s1)) {
if (dcs()) {
xfer=0;
nl();
nl();
pl("1File already exists7.");
prt(3,"Add to database anyway5? ");
if (yn()==0)
ok=0;
} else {
nl();
nl();
pl("3That file is already here5.");
nl();
ok=0;
}
} else
if (!incom) {
nl();
pl("3File isn't already there5.");
pl("3Can't upload locally5.");
nl();
ok=0;
}
if ((d.mask & mask_PD) && (ok)) {
nl();
prt(3,"Is this program PD5/3Shareware5? ");
if (!yn()) {
nl();
pl("3This directory is for Public Domain/");
pl("3Shareware programs ONLY. Please do not");
pl("3upload other programs. If you have");
pl("3trouble with this policy, please contact");
pl("3the sysop.");
nl();
sprintf(s,"Wanted to upload '%s'",u.filename);
add_ass(5,s);
ok=0;
} else
u.mask=mask_PD;
}
if (ok) {
nl();
pl("1Please enter a one line description5.");
outstr(": ");
inputl(u.description,51);
nl();
ss=NULL;
modify_extended_description(&ss);
if (ss) {
add_extended_description(u.filename,ss);
u.mask |= mask_extended;
farfree(ss);
}
nl();
if (xfer) {
ti=timer();
receive_file(s1,&ok,&u.filetype, u.filename, dn);
ti=timer()-ti;
if (ti<0)
ti += 24.0*3600.0;
thisuser.extratime += ti;
}
if (ok) {
if (ok==1) {
f=open(s1,O_RDONLY | O_BINARY);
if (f<0) {
ok=0;
nl();
nl();
pl("DOS error - File not found.");
nl();
if (u.mask & mask_extended)
delete_extended_description(u.filename);
}
if (ok && syscfg.upload_c[0]) {
close(f);
pl("7Please wait1...");
if (check_ul_event(dn,&u)) {
if (u.mask & mask_extended)
delete_extended_description(u.filename);
ok=0;
} else {
f=open(s1,O_RDONLY | O_BINARY);
}
}
}
if (ok) {
if (ok==1) {
l=filelength(f);
u.numbytes=l;
close(f);
++thisuser.uploaded;
thisuser.uk += ((l+1023)/1024);
} else
u.numbytes=0;
time(&l);
u.daten=l;
for (i=numf; i>=1; i--) {
SETREC(i);
read(dlf,(void *)&u1,sizeof(uploadsrec));
SETREC(i+1);
write(dlf,(void *)&u1,sizeof(uploadsrec));
}
SETREC(1);
write(dlf,(void *)&u,sizeof(uploadsrec));
++numf;
SETREC(0);
read(dlf, &u1, sizeof(uploadsrec));
u1.numbytes=numf;
u1.daten=l;
dir_dates[dn]=l;
SETREC(0);
write(dlf,(void *)&u1,sizeof(uploadsrec));
if (ok==1) {
++status.uptoday;
save_status();
sprintf(s,"+%s uploaded on %s",u.filename,directories[dn].name);
sysoplog(s);
nl();
nl();
pl("1File uploaded3.");
nl();
/* npr("1Your ratio is now7:5 %-6.3f\r\n", ratio());*/
nl();
nl();
if (useron)
topscreen();
}
}
} else {
nl();
nl();
pl("6File transmission aborted.");
nl();
if (u.mask & mask_extended)
delete_extended_description(u.filename);
}
}
}
closedl();
}
/****************************************************************************/
int try_to_download(char *s, int dn,int title)
{
int i,ok,sent,abort=0,next=0,i1;
uploadsrec u;
char s1[81];
dliscan1(dn);
i=recno(s);
if (i<=0) {
closedl();
abort=next=0;
checka(&abort,&next);
if (abort)
return(-1);
else
return(0);
}
ok=1;
while ((i>0) && (ok) && (!hangup)) {
if (!ratio_ok()) {
closedl();
return(-1);
}
tleft(1);
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
nl();
if (title)
npr("1Directory 3:5 %s\r\n",directories[dn].name);
i1=printfileinfo(&u,dn);
{
if ((i1) || (strncmp(u.filename,"WWIV4",5)==0)) {
sprintf(s1,"%s%s",directories[dn].path,u.filename);
sent=0;
abort=0;
if (i1==-1)
send_file(s1,&sent,&abort,u.filetype,u.filename,dn, -2L);
else
send_file(s1,&sent,&abort,u.filetype,u.filename,dn, u.numbytes);
if (sent) {
++thisuser.downloaded;
thisuser.dk += (int) ((u.numbytes+1023)/1024);
++u.numdloads;
SETREC(i);
write(dlf,(void *)&u,sizeof(uploadsrec));
sprintf(s1,"Leeched'%s'",u.filename);
sysoplog(s1);
nl();
nl();
/* npr("1Your ratio is now7: 5%-6.3f\r\n", ratio());*/
if (syscfg.sysconfig & sysconfig_log_dl) {
sprintf(s1,"%s downloaded '%s' on %s",
nam(&thisuser,usernum), u.filename, date());
ssm(u.ownerusr,0,s1);
}
if (useron)
topscreen();
}
} else {
nl();
nl();
pl("6Not enough time left to D/L.");
nl();
}
}
if (abort)
ok=0;
else
i=nrecno(s,i);
}
closedl();
if (abort)
return(-1);
else
return(1);
}
/****************************************************************************/
void download()
{
char s[81];
int dn;
nl();
pl("1Download 3-");
nl();
prt(1,"What's the filename5? ");
input(s,12);
if (s[0]==0)
return;
if (strchr(s,'.')==NULL)
strcat(s,".*");
align(s);
if (try_to_download(s,udir[curdir].subnum,0)==0) {
nl();
pl("6Searching all directories.");
nl();
dn=0;
while ((dn<64) && (udir[dn].subnum!=-1)) {
if (try_to_download(s,udir[dn].subnum,1)<0)
dn=100;
else
dn++;
}
}
}
void setldate()
{
struct date d;
struct time t;
char s[81];
int m,dd,y;
nl();
nl();
unixtodos(nscandate,&d,&t);
nl();
sprintf(s,"3Current limiting date 1= 5%02d/%02d/%02d",d.da_mon,d.da_day,(d.da_year-1900));
pl(s);
nl();
pl("1Enter new limiting date in the format3:");
pl(" 1MM7/1DD7/1YY");
outstr("3:");
input(s,8);
m=atoi(s);
dd=atoi(&(s[3]));
y=atoi(&(s[6]))+1900;
if ((strlen(s)==8) && (m>0) && (m<=12) && (dd>0) && (dd<32) && (y>=1980)) {
t.ti_min=0;
t.ti_hour=0;
t.ti_hund=0;
t.ti_sec=0;
d.da_year=y;
d.da_day=dd;
d.da_mon=m;
sprintf(s,"3Current limiting date 1= 5%02d/%02d/%02d",m,dd,(y-1900));
nl();
pl(s);
nl();
nscandate=dostounix(&d,&t);
}
}
void finddescription()
{
uploadsrec u;
int i,i1,i2,abort,pty,d,ocd,pts,pc,fc;
char s[81],s1[81];
fc=thisuser.sysstatus & sysstatus_funky_colors;
nl();
nl();
pl("Find description -");
nl();
pl("Enter string to search for in file description:");
outstr(":");
input(s1,51);
if (s1[0]==0)
return;
ocd=curdir;
abort=0;
num_listed=0;
for (i=0; (i<64) && (!abort) && (!hangup) && (udir[i].subnum!=-1); i++) {
i1=udir[i].subnum;
pts=0;
if (i1>=32) {
if (thisuser.nscn2 & (1L << (i1-32)))
pts=1;
} else {
if (thisuser.nscn1 & (1L << i1))
pts=1;
}
pts=1;
/* remove pts=1 to search only marked directories */
if (pts) {
curdir=i;
dliscan();
pty=1;
pc=0;
for (i1=1; (i1<=numf) && (!abort) && (!hangup); i1++) {
SETREC(i1);
read(dlf,(void *)&u,sizeof(uploadsrec));
strcpy(s,u.description);
for (i2=0; i2<strlen(s); i2++)
s[i2]=upcase(s[i2]);
if (strstr(s,s1)!=NULL) {
if (pty) {
printtitle(&abort);
pty=0;
pc=1;
}
printinfo(&u,&abort);
}
}
if ((pc) && (!abort)) {
if (fc)
ansic(3);
if (okansi())
pla("└──────────────┴───────┴─────────────────────────────────────────────────────┘",&abort);
else
pla("+--------------+-------+-----------------------------------------------------+",&abort);
nl();
pc=0;
}
closedl();
}
}
curdir=ocd;
if ((num_listed) && (!abort)) {
nl();
nl();
sprintf(s,"Files listed: %d",num_listed);
pl(s);
nl();
}
}
void arc_l()
{
char s[81],s1[81],s2[81];
int i,abort,next,i1;
uploadsrec u;
nl();
prt(1,"File for listing5: ");
input(s,12);
if (strchr(s,'.')==NULL)
strcat(s,".*");
if (!okfn(s))
s[0]=0;
align(s);
dliscan();
abort=0;
next=0;
i=recno(s);
do {
if (i>0) {
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
i1=list_arc_out(stripfn(u.filename),directories[udir[curdir].subnum].path);
if (i1)
abort=1;
checka(&abort,&next);
i=nrecno(s,i);
}
} while ((i>0) && (!hangup) && (!abort));
closedl();
}
/****************************************************************************/
void yourinfodl()
{
nl();
nl();
npr("1Uploads : %ldk in %d files\r\n",thisuser.uk, thisuser.uploaded);
npr("3Downloads: %ldk in %d files\r\n",thisuser.dk, thisuser.downloaded);
/* npr("5Ratio : %-6.3f\r\n",ratio());*/
npr("5Your DSL : %d\r\n",thisuser.dsl);
npr("7Your P/C : %-5.3f\r\n",post_ratio(),syscfg.post_call_ratio);
nl();
}
void l_config_nscan()
{
int i,abort,i1;
char s[81], s2[81];
abort=0;
nl();
pl("1Dirs to n5-1scan marked with 3'5*3'");
nl();
for (i=0; (i<64) && (udir[i].subnum!=-1) && (!abort); i++) {
i1=udir[i].subnum;
if (i1<32) {
if ((1L << (i1)) & thisuser.nscn1)
strcpy(s,"5* ");
else
strcpy(s," ");
} else {
if ((1L << (i1-32)) & thisuser.nscn2)
strcpy(s,"5* ");
else
strcpy(s," ");
}
sprintf(s2,"%s%s. %s",s,udir[i].keys, directories[i1].name);
pla(s2,&abort);
}
nl();
nl();
}
void config_nscan()
{
char *s;
int i,done,i1;
l_config_nscan();
done=0;
do {
nl();
pl("1Enter directory identifier5, 1? to list5, 1or Q to Quit");
prt(3,"Config5: ");
s=mmkey(1);
if (s[0])
for (i=0; i<64; i++)
if (strcmp(udir[i].keys,s)==0) {
i1=udir[i].subnum;
if (i1<32)
thisuser.nscn1 ^= ((1L) << i1);
else
thisuser.nscn2 ^= ((1L) << (i1-32));
}
if (strcmp(s,"Q")==0)
done=1;
if (strcmp(s,"?")==0)
l_config_nscan();
} while ((!done) && (!hangup));
}
void xfer_defaults()
{
char s[81],s1[81],ch;
int i,i1,i2,done;
done=0;
do {
outchr(12);
pl("7[117]5. 3Set N-Scan Directories5.");
pl("7[127]5. 3Set Default Protocol5.");
sprintf(s,"7[137]5. 3N-Scan Transfer after Message Base (%s)5.",
thisuser.sysstatus & sysstatus_nscan_file_system?"Yes":"No");
pl(s);
sprintf(s,"7[147]5. 3Number of lines of extended description to print (%d line%s)5.",
thisuser.num_extended,thisuser.num_extended==1?"":"s");
pl(s);
pl("7[1Q7]5. 3Quit5.");
nl();
prt(1,"Which3? ");
helpl=32;
ch=onek("Q1234");
switch(ch) {
case 'Q':
done=1;
break;
case '1':
helpl=24;
config_nscan();
break;
case '2':
nl();
nl();
pl("1Enter your default protocol5, 10 for none5.");
nl();
helpl=40;
i=get_protocol(xf_down);
if (i>=0)
thisuser.defprot=i;
break;
case '3':
nl();
nl();
pl("3Do you want to perform a newscan of all selected transfer");
outstr("3directories after an N-scan of the message base5? ");
if (thisuser.sysstatus & sysstatus_nscan_file_system)
thisuser.sysstatus -= sysstatus_nscan_file_system;
if (yn())
thisuser.sysstatus += sysstatus_nscan_file_system;
break;
case '4':
nl();
nl();
pl("3How many lines of an extended description");
pl("3do you want to see when listing files 5(107-1105)");
npr("5(1Currently set to 3%d 1lines5)\r\n",thisuser.num_extended);
prt(5,"? ");
helpl=41;
input(s,3);
if (s[0]) {
i=atoi(s);
if ((i>=0) && (i<=10))
thisuser.num_extended=i;
}
break;
}
} while ((!done) && (!hangup));
}
void removefile()
{
int i,i1,ok,rm,abort,rdlp;
char ch,s[81],s1[81];
uploadsrec u;
userrec uu;
dliscan();
nl();
pl("1Enter filename to remove5.");
outstr("5:1");
mpl(12);
input(s,12);
if (s[0]==0) {
closedl();
return;
}
if (strchr(s,'.')==NULL)
strcat(s,".*");
align(s);
i=recno(s);
abort=0;
while ((!hangup) && (i>0) && (!abort)) {
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
if ((dcs()) || ((u.ownersys==0) && (u.ownerusr==usernum))) {
nl();
if (check_batch_queue(u.filename)) {
pl("1That file is in the batch queue5; 1remove it from there5.");
nl();
} else {
printfileinfo(&u,udir[curdir].subnum);
prt(1,"Remove 5(3Y5/3N5/3Q5) 1: ");
ch=onek("QNY");
if (ch=='Q')
abort=1;
if (ch=='Y') {
rdlp=1;
if (dcs()) {
prt(1,"Delete file too5? ");
rm=yn();
if (rm) {
prt(1,"Remove DL points5? ");
rdlp=yn();
}
} else
rm=1;
if (rm) {
sprintf(s1,"%s%s",directories[udir[curdir].subnum].path,u.filename);
unlink(s1);
if ((rdlp) && (u.ownersys==0)) {
read_user(u.ownerusr,&uu);
if ((uu.inact & inact_deleted)==0) {
--uu.uploaded;
uu.uk -= ((u.numbytes+1023)/1024);
write_user(u.ownerusr,&uu);
}
close_user();
}
}
if (u.mask & mask_extended)
delete_extended_description(u.filename);
sprintf(s1,"-%s Removed off of %s",u.filename,
directories[udir[curdir].subnum].name);
sysoplog(s1);
for (i1=i; i1<numf; i1++) {
SETREC(i1+1);
read(dlf,(void *)&u,sizeof(uploadsrec));
SETREC(i1);
write(dlf,(void *)&u,sizeof(uploadsrec));
}
--i;
--numf;
SETREC(0);
read(dlf, &u, sizeof(uploadsrec));
u.numbytes=numf;
SETREC(0);
write(dlf,(void *)&u,sizeof(uploadsrec));
}
}
}
i=nrecno(s,i);
}
closedl();
}