|
|
1.1 ! root 1: #line 1 "XFER_LO.C" ! 2: ! 3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */ ! 4: ! 5: #include "sbbs.h" ! 6: ! 7: /****************************************************************************/ ! 8: /* Prompts user for file specification. <CR> is *.* and .* is assumed. */ ! 9: /* Returns padded file specification. */ ! 10: /* Returns NULL if input was aborted. */ ! 11: /****************************************************************************/ ! 12: char *getfilespec(char *str) ! 13: { ! 14: bputs(text[FileSpecStarDotStar]); ! 15: if(!getstr(str,12,K_UPPER)) ! 16: strcpy(str,"*.*"); ! 17: else if(!strchr(str,'.') && strlen(str)<=8) ! 18: strcat(str,".*"); ! 19: if(sys_status&SS_ABORT) ! 20: return(0); ! 21: return(str); ! 22: } ! 23: ! 24: /****************************************************************************/ ! 25: /* Turns FILE.EXT into FILE .EXT */ ! 26: /****************************************************************************/ ! 27: char *padfname(char *filename, char *str) ! 28: { ! 29: char c,d; ! 30: ! 31: for(c=0;c<8;c++) ! 32: if(filename[c]=='.' || !filename[c]) break; ! 33: else str[c]=filename[c]; ! 34: d=c; ! 35: if(filename[c]=='.') c++; ! 36: while(d<8) ! 37: str[d++]=SP; ! 38: str[d++]='.'; ! 39: while(d<12) ! 40: if(!filename[c]) break; ! 41: else str[d++]=filename[c++]; ! 42: while(d<12) ! 43: str[d++]=SP; ! 44: str[d]=0; ! 45: return(str); ! 46: } ! 47: ! 48: /****************************************************************************/ ! 49: /* Turns FILE .EXT into FILE.EXT */ ! 50: /****************************************************************************/ ! 51: char *unpadfname(char *filename, char *str) ! 52: { ! 53: char c,d; ! 54: ! 55: for(c=0,d=0;c<strlen(filename);c++) ! 56: if(filename[c]!=SP) str[d++]=filename[c]; ! 57: str[d]=0; ! 58: return(str); ! 59: } ! 60: ! 61: /****************************************************************************/ ! 62: /* Checks to see if filename matches filespec. Returns 1 if yes, 0 if no */ ! 63: /****************************************************************************/ ! 64: char filematch(char *filename, char *filespec) ! 65: { ! 66: char c; ! 67: ! 68: for(c=0;c<8;c++) /* Handle Name */ ! 69: if(filespec[c]=='*') break; ! 70: else if(filespec[c]=='?') continue; ! 71: else if(filename[c]!=filespec[c]) return(0); ! 72: for(c=9;c<12;c++) ! 73: if(filespec[c]=='*') break; ! 74: else if(filespec[c]=='?') continue; ! 75: else if(filename[c]!=filespec[c]) return(0); ! 76: return(1); ! 77: } ! 78: ! 79: /****************************************************************************/ ! 80: /* Deletes all files in dir 'path' that match file spec 'spec' */ ! 81: /****************************************************************************/ ! 82: int delfiles(char *inpath, char *spec) ! 83: { ! 84: char str[256],path[128],done; ! 85: int files=0; ! 86: struct ffblk ff; ! 87: ! 88: strcpy(path,inpath); ! 89: backslash(path); ! 90: sprintf(str,"%s%s",path,spec); ! 91: done=findfirst(str,&ff,0); ! 92: while(!done) { ! 93: sprintf(str,"%s%s",path,ff.ff_name); ! 94: _chmod(str,1,FA_NORMAL); // Incase it's been marked RDONLY ! 95: if(remove(str)) ! 96: errormsg(WHERE,ERR_REMOVE,str,0); ! 97: else ! 98: files++; ! 99: done=findnext(&ff); } ! 100: return(files); ! 101: } ! 102: ! 103: /*****************************************************************************/ ! 104: /* Checks the filename 'fname' for invalid symbol or character sequences */ ! 105: /*****************************************************************************/ ! 106: char checkfname(char *fname) ! 107: { ! 108: char str[256],c=0,d; ! 109: ! 110: if(strcspn(fname,"\\/|<>+[]:=\";,%")!=strlen(fname)) { ! 111: sprintf(str,"Suspicious filename attempt: '%s'",fname); ! 112: errorlog(str); ! 113: return(0); } ! 114: if(strstr(fname,"..")) ! 115: return(0); ! 116: if(strcspn(fname,".")>8) ! 117: return(0); ! 118: d=strlen(fname); ! 119: while(c<d) { ! 120: if(fname[c]<=SP || fname[c]&0x80) ! 121: return(0); ! 122: c++; } ! 123: return(1); ! 124: } ! 125: ! 126: /**************************************************************************/ ! 127: /* Add file 'f' to batch download queue. Return 1 if successful, 0 if not */ ! 128: /**************************************************************************/ ! 129: char addtobatdl(file_t f) ! 130: { ! 131: char str[256],tmp2[256]; ! 132: uint i; ! 133: ulong totalcdt, totalsize, totaltime; ! 134: ! 135: if(useron.rest&FLAG('D')) { ! 136: bputs(text[R_Download]); ! 137: return(0); } ! 138: /*** ! 139: sprintf(str,"%s%s",f.altpath>0 && f.altpath<=altpaths ? altpath[f.altpath-1] ! 140: : dir[f.dir]->path,unpadfname(f.name,tmp)); ! 141: ***/ ! 142: for(i=0;i<batdn_total;i++) { ! 143: if(!strcmp(batdn_name[i],f.name) && f.dir==batdn_dir[i]) { ! 144: bprintf(text[FileAlreadyInQueue],f.name); ! 145: return(0); } } ! 146: if(f.size<=0 /* !fexist(str) */) { ! 147: bprintf(text[CantAddToQueue],f.name); ! 148: bputs(text[FileIsNotOnline]); ! 149: return(0); } ! 150: if(batdn_total>=max_batdn) { ! 151: bprintf(text[CantAddToQueue],f.name); ! 152: bputs(text[BatchDlQueueIsFull]); ! 153: return(0); } ! 154: for(i=0,totalcdt=0;i<batdn_total;i++) ! 155: totalcdt+=batdn_cdt[i]; ! 156: if(dir[f.dir]->misc&DIR_FREE) f.cdt=0L; ! 157: totalcdt+=f.cdt; ! 158: if(!(useron.exempt&FLAG('D')) && totalcdt>useron.cdt+useron.freecdt) { ! 159: bprintf(text[CantAddToQueue],f.name); ! 160: bprintf(text[YouOnlyHaveNCredits],ultoac(useron.cdt+useron.freecdt,tmp)); ! 161: return(0); } ! 162: if(!chk_ar(dir[f.dir]->dl_ar,useron)) { ! 163: bprintf(text[CantAddToQueue],f.name); ! 164: bputs(text[CantDownloadFromDir]); ! 165: return(0); } ! 166: for(i=0,totalsize=totaltime=0;i<batdn_total;i++) { ! 167: totalsize+=batdn_size[i]; ! 168: if(!(dir[batdn_dir[i]]->misc&DIR_TFREE) && cur_cps) ! 169: totaltime+=batdn_size[i]/(ulong)cur_cps; } ! 170: totalsize+=f.size; ! 171: if(!(dir[f.dir]->misc&DIR_TFREE) && cur_cps) ! 172: totaltime+=f.size/(ulong)cur_cps; ! 173: if(!(useron.exempt&FLAG('T')) && totaltime>timeleft) { ! 174: bprintf(text[CantAddToQueue],f.name); ! 175: bputs(text[NotEnoughTimeToDl]); ! 176: return(0); } ! 177: strcpy(batdn_name[batdn_total],f.name); ! 178: batdn_dir[batdn_total]=f.dir; ! 179: batdn_cdt[batdn_total]=f.cdt; ! 180: batdn_offset[batdn_total]=f.datoffset; ! 181: batdn_size[batdn_total]=f.size; ! 182: batdn_alt[batdn_total]=f.altpath; ! 183: batdn_total++; ! 184: openfile(f); ! 185: bprintf(text[FileAddedToBatDlQueue] ! 186: ,f.name,batdn_total,max_batdn,ultoac(totalcdt,tmp) ! 187: ,ultoac(totalsize,tmp2) ! 188: ,sectostr(totalsize/(ulong)cur_cps,str)); ! 189: return(1); ! 190: } ! 191: ! 192: /****************************************************************************/ ! 193: /* This function returns the command line for the temp file extension for */ ! 194: /* current user online. */ ! 195: /****************************************************************************/ ! 196: char *temp_cmd(void) ! 197: { ! 198: int i; ! 199: ! 200: if(!total_fcomps) { ! 201: errormsg(WHERE,ERR_CHK,"compressable file types",0); ! 202: return(nulstr); } ! 203: for(i=0;i<total_fcomps;i++) ! 204: if(!stricmp(useron.tmpext,fcomp[i]->ext) ! 205: && chk_ar(fcomp[i]->ar,useron)) ! 206: return(fcomp[i]->cmd); ! 207: return(fcomp[0]->cmd); ! 208: } ! 209:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.