home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
XFERTMP.C
< prev
next >
Wrap
Text File
|
1991-12-26
|
12KB
|
507 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);
/* the archive type to use */
#define ARC_NUMBER 0
/* .ZIP structures and defines */
#define ZIP_LOCAL_SIG 0x04034b50
#define ZIP_CENT_START_SIG 0x02014b50
#define ZIP_CENT_END_SIG 0x06054b50
typedef struct {
unsigned long signature; /* 0x04034b50 */
unsigned short extract_ver;
unsigned short flags;
unsigned short comp_meth;
unsigned short mod_time;
unsigned short mod_date;
unsigned long crc_32;
unsigned long comp_size;
unsigned long uncomp_size;
unsigned short filename_len;
unsigned short extra_length;
} zip_local_header;
typedef struct {
unsigned long signature; /* 0x02014b50 */
unsigned short made_ver;
unsigned short extract_ver;
unsigned short flags;
unsigned short comp_meth;
unsigned short mod_time;
unsigned short mod_date;
unsigned long crc_32;
unsigned long comp_size;
unsigned long uncomp_size;
unsigned short filename_len;
unsigned short extra_len;
unsigned short comment_len;
unsigned short disk_start;
unsigned short int_attr;
unsigned long ext_attr;
unsigned long rel_ofs_header;
} zip_central_dir;
typedef struct {
unsigned long signature; /* 0x06054b50 */
unsigned short disk_num;
unsigned short cent_dir_disk_num;
unsigned short total_entries_this_disk;
unsigned short total_entries_total;
unsigned long central_dir_size;
unsigned long ofs_cent_dir;
unsigned short comment_len;
} zip_end_dir;
/* strings not to allow in a .zip file to extract from */
char *bad_words[] = {
"COMMAND",
"\\",
":",
">",
"<",
"|",
"..",
NULL,
};
long bad_filename(char *fn)
{
int i;
strupr(fn);
for (i=0; bad_words[i]; i++) {
if (strstr(fn,bad_words[i])) {
npr("Can't extract from that because it has '%s'.\r\n",fn);
return(1);
}
}
return(0);
}
long check_for_files_zip(char *fn)
{
int f;
long l,sig,len;
zip_local_header zl;
zip_central_dir zc;
zip_end_dir ze;
char s[161];
#define READ_FN(ln) {read(f,s,ln); s[ln]=0;}
f=open(fn,O_RDWR | O_BINARY);
if (f>0) {
l=0;
len=filelength(f);
while (l<len) {
lseek(f,l,SEEK_SET);
read(f,&sig, 4);
lseek(f,l,SEEK_SET);
switch(sig) {
case ZIP_LOCAL_SIG:
read(f,&zl, sizeof(zl));
READ_FN(zl.filename_len);
if (bad_filename(s)) {
close(f);
return(1);
}
l += sizeof(zl);
l += zl.comp_size + zl.filename_len + zl.extra_length;
break;
case ZIP_CENT_START_SIG:
read(f,&zc, sizeof(zc));
READ_FN(zc.filename_len);
if (bad_filename(s)) {
close(f);
return(1);
}
l += sizeof(zc);
l += zc.filename_len + zc.extra_len;
break;
case ZIP_CENT_END_SIG:
read(f,&ze, sizeof(ze));
close(f);
return(0);
default:
close(f);
npr("1Error examining that; can't extract from it.\r\n");
return(1);
}
}
close(f);
return(0);
}
npr("1file not found3: %s\r\n",fn);
return(1);
}
int check_for_files(char *fn)
{
char *ss;
ss=strrchr(fn,'.');
if (ss) {
if (stricmp(ss+1,"ZIP")==NULL) {
return(check_for_files_zip(fn));
} else if (stricmp(ss+1,"ARC")==NULL) {
/* no processing for .ARC files yet */
} else {
/* unknown archive type; let it through. */
}
} else {
/* no extension? */
npr("No extension.\r\n");
return(1);
}
return(0);
}
void download_temp_arc()
{
char s[81],s1[81];
long numbytes;
double d;
int i,f,sent,abort;
if (!ratio_ok())
return;
sprintf(s1,"%sTEMP.%s",syscfg.tempdir,syscfg.arcs[ARC_NUMBER].extension);
f=open(s1,O_RDWR | O_BINARY);
if (f<0) {
nl();
nl();
pl("1There is no temporary archive file.");
nl();
return;
}
numbytes=filelength(f);
close(f);
if (numbytes==0L) {
nl();
nl();
pl("1There is no temporary archive file.");
nl();
return;
}
d=((double) (((numbytes)+127)/128)) *
(1620.0) /
((double) (modem_speed));
if (d<=nsl()) {
npr("Approx. time: %s\r\n",ctim(d));
sent=0;
abort=0;
sprintf(s,"TEMP.%s",syscfg.arcs[ARC_NUMBER].extension);
send_file(s1,&sent,&abort,0,s,-1,numbytes);
if (sent) {
++thisuser.downloaded;
thisuser.dk += ((numbytes+1023)/1024);
sprintf(s1,"Downloaded %ldk of temporary file",(numbytes+1023)/1024);
sysoplog(s1);
nl();
nl();
npr("1Your ratio is now3:6 %-6.3f\r\n",ratio());
if (useron)
topscreen();
}
} else {
nl();
nl();
pl("6Not enough time left to D/L.");
nl();
}
}
void add_temp_arc()
{
char s[255],s1[81],s2[81],s3[81];
int i;
nl();
pl("3Enter filename to add to temporary");
pl("3archive file. May contain wildcards.");
prt(2,": ");
input(s,12);
if (!okfn(s))
return;
if (s[0]==0)
return;
if (strchr(s,'.')==NULL)
strcat(s,".*");
strcpy(s2,stripfn(s));
for (i=0; i<strlen(s2); i++)
if ((s2[i]=='|') || (s2[i]=='>') || (s2[i]=='<') || (s2[i]==';') || (s2[i]==' ') ||
(s2[i]==':') || (s2[i]=='/') || (s2[i]=='\\'))
return;
sprintf(s1,"%sTEMP.%s",syscfg.tempdir,syscfg.arcs[ARC_NUMBER].extension);
sprintf(s3,"%s%s",syscfg.tempdir,s2);
get_arc_cmd(s,s1,2,s3);
if (s[0]) {
sprintf(s1,"1Added3 '%s' 1to temporary archive",s2);
sysoplog(s1);
do_external(s,0);
} else
pl("1Sorry, can't add to temp archive.");
}
void del_temp()
{
char s[81],s1[81];
nl();
prt(1,"Filename to delete3: ");
input(s1,12);
if (!okfn(s1))
return;
if (s1[0]) {
if (strchr(s1,'.')==NULL)
strcat(s1,".*");
remove_from_temp(s1,syscfg.tempdir, 1);
}
}
void list_temp_dir()
{
int i,i1,f1,abort;
char s[81],s1[81];
struct ffblk ff;
uploadsrec u;
sprintf(s1,"%s*.*",syscfg.tempdir);
f1=findfirst(s1,&ff,0);
nl();
pl("1Files in temporary directory3:");
nl();
i1=0;
abort=0;
while ((f1==0) && (!hangup) && (!abort)) {
strcpy(s,(ff.ff_name));
align(s);
sprintf(s1,"%12s %-8ld",s,ff.ff_fsize);
pla(s1, &abort);
f1=findnext(&ff);
i1=1;
}
if (!i1)
pl("6None.");
nl();
if ((!abort) && (!hangup)) {
sprintf(s,"Free space: %ldk.",(long) freek1(syscfg.tempdir));
pl(s);
nl();
}
}
void temp_extract()
{
int i,i1,i2,i3,ok,abort,ok1;
char s[255],s1[255],s2[81],s3[255],s4[129];
uploadsrec u,u1;
dliscan();
nl();
pl("3Extract to temporary directory1:");
nl();
prt(1,"What's the filename3? ");
input(s,12);
if ((!okfn(s)) || (s[0]==0)) {
closedl();
return;
}
if (strchr(s,'.')==NULL)
strcat(s,".*");
align(s);
i=recno(s);
ok=1;
while ((i>0) && (ok) && (!hangup)) {
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
sprintf(s2,"%s%s",directories[udir[curdir].subnum].path,u.filename);
get_arc_cmd(s1,s2,1,"");
if ((s1[0]) && (exist(s2))) {
nl();
nl();
abort=0;
printinfo(&u,&abort);
nl();
cd_to(directories[udir[curdir].subnum].path);
get_dir(s4,1);
strcat(s4,stripfn(u.filename));
cd_to(cdir);
if (!check_for_files(s4)) {
do {
prt(1,"Extract what 5(1?=list,Q=abort5)3 ? ");
input(s1,12);
if (s1[0]==0)
ok1=0;
else
ok1=1;
if (!okfn(s1))
ok1=0;
if (strcmp(s1,"?")==0) {
list_arc_out(stripfn(u.filename),directories[udir[curdir].subnum].path);
s1[0]=0;
}
if (strcmp(s1,"Q")==0) {
ok=0;
s1[0]=0;
}
i2=0;
for (i1=0; i1<strlen(s1); i1++)
if ((s1[i1]=='|') || (s1[i1]=='>') || (s1[i1]=='<') || (s1[i1]==';') || (s1[i1]==' '))
i2=1;
if (i2)
s1[0]=0;
if (s1[0]) {
if (strchr(s1,'.')==NULL)
strcat(s1,".*");
get_arc_cmd(s3,s4,1,stripfn(s1));
cd_to(syscfg.tempdir);
if (!okfn(s1))
s3[0]=0;
if (s3[0]) {
do_external(s3,0);
sprintf(s2,"Extracted out %s from %s",s1,u.filename);
} else
s2[0]=0;
cd_to(cdir);
if (s2[0])
sysoplog(s2);
}
} while ((!hangup) && (ok) && (ok1));
}
} else
if (s1[0]) {
nl();
pl("That file currently isn't there.");
nl();
}
if (ok)
i=nrecno(s,i);
}
closedl();
}
void list_temp_text()
{
int i,i1,f1,ok,sent;
char s[81],s1[81];
struct ffblk ff;
uploadsrec u;
double percent;
nl();
prt(1,"List what file(s)3 ? ");
input(s,12);
if (!okfn(s))
return;
if (s[0]) {
if (strchr(s,'.')==NULL)
strcat(s,".*");
sprintf(s1,"%s%s",syscfg.tempdir,stripfn(s));
f1=findfirst(s1,&ff,0);
ok=1;
nl();
while ((f1==0) && (ok)) {
sprintf(s,"%s%s",syscfg.tempdir,ff.ff_name);
nl();
npr("1Listing %s3:\r\n",ff.ff_name);
nl();
ascii_send(s,&sent,&percent);
if (sent) {
sprintf(s,"Temp text D/L '%s'",ff.ff_name);
sysoplog(s);
} else {
sprintf(s,"Temp Tried text D/L '%s' %3.2f%%",ff.ff_name,percent*100.0);
sysoplog(s);
ok=0;
}
f1=findnext(&ff);
}
}
}
void list_temp_arc()
{
char s1[81],s2[81];
sprintf(s1,"TEMP.%s",syscfg.arcs[ARC_NUMBER].extension);
list_arc_out(s1,syscfg.tempdir);
nl();
}
void temporary_stuff()
{
char s[81],s1[81],ch;
int done;
done=0;
do {
nl();
prt(1,"Archive3: 5Q1,5D1,5R1,5A1,5V1,5L1,5T3: ");
ch=onek("Q?DRAVLT");
switch(ch) {
case 'Q':
done=1;
break;
case 'D':
download_temp_arc();
break;
case 'V':
list_temp_arc();
break;
case 'A':
add_temp_arc();
break;
case 'R':
del_temp();
break;
case 'L':
list_temp_dir();
break;
case 'T':
list_temp_text();
break;
case '?':
printmenu(14);
break;
}
} while ((!hangup) && (!done));
}