|
|
1.1 ! root 1: /* filedat.c */ ! 2: ! 3: /* Synchronet file database-related exported functions */ ! 4: ! 5: /* $Id: filedat.c,v 1.7 2000/11/04 12:03:50 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #include "sbbs.h" ! 39: ! 40: /****************************************************************************/ ! 41: /* Gets filedata from dircode.DAT file */ ! 42: /* Need fields .name ,.dir and .offset to get other info */ ! 43: /* Does not fill .dateuled or .datedled fields. */ ! 44: /****************************************************************************/ ! 45: BOOL DLLCALL getfiledat(scfg_t* cfg, file_t* f) ! 46: { ! 47: char buf[F_LEN+1],str[256],tmp[128]; ! 48: int file; ! 49: long length; ! 50: ! 51: sprintf(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); ! 52: if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) { ! 53: // errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 54: return(FALSE); ! 55: } ! 56: length=filelength(file); ! 57: if(f->datoffset>length) { ! 58: close(file); ! 59: // errormsg(WHERE,ERR_LEN,str,length); ! 60: return(FALSE); ! 61: } ! 62: if(length%F_LEN) { ! 63: close(file); ! 64: // errormsg(WHERE,ERR_LEN,str,length); ! 65: return(FALSE); ! 66: } ! 67: lseek(file,f->datoffset,SEEK_SET); ! 68: if(read(file,buf,F_LEN)!=F_LEN) { ! 69: close(file); ! 70: // errormsg(WHERE,ERR_READ,str,F_LEN); ! 71: return(FALSE); ! 72: } ! 73: close(file); ! 74: getrec(buf,F_ALTPATH,2,str); ! 75: f->altpath=hptoi(str); ! 76: getrec(buf,F_CDT,LEN_FCDT,str); ! 77: f->cdt=atol(str); ! 78: ! 79: if(!f->size) { /* only read disk if this is null */ ! 80: // if(dir[f->dir]->misc&DIR_FCHK) { ! 81: sprintf(str,"%s%s" ! 82: ,f->altpath>0 && f->altpath<=cfg->altpaths ? cfg->altpath[f->altpath-1] ! 83: : cfg->dir[f->dir]->path,unpadfname(f->name,tmp)); ! 84: f->size=flength(str); ! 85: f->date=fdate(str); ! 86: /* ! 87: } ! 88: else { ! 89: f->size=f->cdt; ! 90: f->date=0; } ! 91: */ ! 92: } ! 93: #if 0 ! 94: if((f->size>0L) && cur_cps) ! 95: f->timetodl=(ushort)(f->size/(ulong)cur_cps); ! 96: else ! 97: #endif ! 98: f->timetodl=0; ! 99: ! 100: getrec(buf,F_DESC,LEN_FDESC,f->desc); ! 101: getrec(buf,F_ULER,LEN_ALIAS,f->uler); ! 102: getrec(buf,F_TIMESDLED,5,str); ! 103: f->timesdled=atoi(str); ! 104: getrec(buf,F_OPENCOUNT,3,str); ! 105: f->opencount=atoi(str); ! 106: if(buf[F_MISC]!=ETX) ! 107: f->misc=buf[F_MISC]-SP; ! 108: else ! 109: f->misc=0; ! 110: return(TRUE); ! 111: } ! 112: ! 113: /****************************************************************************/ ! 114: /* Puts filedata into DIR_code.DAT file */ ! 115: /* Called from removefiles */ ! 116: /****************************************************************************/ ! 117: BOOL DLLCALL putfiledat(scfg_t* cfg, file_t* f) ! 118: { ! 119: char buf[F_LEN+1],str[256],tmp[128]; ! 120: int file; ! 121: long length; ! 122: ! 123: putrec(buf,F_CDT,LEN_FCDT,ultoa(f->cdt,tmp,10)); ! 124: putrec(buf,F_DESC,LEN_FDESC,f->desc); ! 125: putrec(buf,F_DESC+LEN_FDESC,2,crlf); ! 126: putrec(buf,F_ULER,LEN_ALIAS+5,f->uler); ! 127: putrec(buf,F_ULER+LEN_ALIAS+5,2,crlf); ! 128: putrec(buf,F_TIMESDLED,5,ultoa(f->timesdled,tmp,10)); ! 129: putrec(buf,F_TIMESDLED+5,2,crlf); ! 130: putrec(buf,F_OPENCOUNT,3,ultoa(f->opencount,tmp,10)); ! 131: putrec(buf,F_OPENCOUNT+3,2,crlf); ! 132: buf[F_MISC]=f->misc+SP; ! 133: putrec(buf,F_ALTPATH,2,hexplus(f->altpath,tmp)); ! 134: putrec(buf,F_ALTPATH+2,2,crlf); ! 135: sprintf(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); ! 136: if((file=sopen(str,O_WRONLY|O_BINARY,SH_DENYRW))==-1) { ! 137: // errormsg(WHERE,ERR_OPEN,str,O_WRONLY); ! 138: return(FALSE); ! 139: } ! 140: length=filelength(file); ! 141: if(length%F_LEN) { ! 142: close(file); ! 143: // errormsg(WHERE,ERR_LEN,str,length); ! 144: return(FALSE); ! 145: } ! 146: if(f->datoffset>length) { ! 147: close(file); ! 148: // errormsg(WHERE,ERR_LEN,str,length); ! 149: return(FALSE); ! 150: } ! 151: lseek(file,f->datoffset,SEEK_SET); ! 152: if(write(file,buf,F_LEN)!=F_LEN) { ! 153: close(file); ! 154: // errormsg(WHERE,ERR_WRITE,str,F_LEN); ! 155: return(FALSE); ! 156: } ! 157: length=filelength(file); ! 158: close(file); ! 159: if(length%F_LEN) { ! 160: // errormsg(WHERE,ERR_LEN,str,length); ! 161: return(FALSE); ! 162: } ! 163: return(TRUE); ! 164: } ! 165: ! 166: /****************************************************************************/ ! 167: /* Adds the data for struct filedat to the directory's data base. */ ! 168: /* changes the .datoffset field only */ ! 169: /* returns 1 if added successfully, 0 if not. */ ! 170: /****************************************************************************/ ! 171: BOOL DLLCALL addfiledat(scfg_t* cfg, file_t* f) ! 172: { ! 173: char str[256],fname[13],c,fdat[F_LEN+1]; ! 174: char tmp[128]; ! 175: uchar HUGE16 *ixbbuf,idx[3]; ! 176: int i,file; ! 177: long l,length; ! 178: time_t now; ! 179: time_t uldate; ! 180: ! 181: /************************/ ! 182: /* Add data to DAT File */ ! 183: /************************/ ! 184: sprintf(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); ! 185: if((file=sopen(str,O_RDWR|O_BINARY|O_CREAT,SH_DENYRW))==-1) { ! 186: // errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_CREAT); ! 187: return(FALSE); ! 188: } ! 189: length=filelength(file); ! 190: if(length==0L) ! 191: l=0L; ! 192: else { ! 193: if(length%F_LEN) { ! 194: close(file); ! 195: // errormsg(WHERE,ERR_LEN,str,length); ! 196: return(FALSE); ! 197: } ! 198: for(l=0;l<length;l+=F_LEN) { /* Find empty slot */ ! 199: lseek(file,l,SEEK_SET); ! 200: read(file,&c,1); ! 201: if(c==ETX) break; ! 202: } ! 203: if(l/F_LEN>=MAX_FILES || l/F_LEN>=cfg->dir[f->dir]->maxfiles) { ! 204: close(file); ! 205: #if 0 ! 206: bputs(text[DirFull]); ! 207: sprintf(str,"Directory Full: %s %s" ! 208: ,cfg->lib[cfg->dir[f->dir]->lib]->sname,cfg->dir[f->dir]->sname); ! 209: logline("U!",str); ! 210: #endif ! 211: return(FALSE); ! 212: } ! 213: } ! 214: putrec(fdat,F_CDT,LEN_FCDT,ultoa(f->cdt,tmp,10)); ! 215: putrec(fdat,F_DESC,LEN_FDESC,f->desc); ! 216: putrec(fdat,F_DESC+LEN_FDESC,2,crlf); ! 217: putrec(fdat,F_ULER,LEN_ALIAS+5,f->uler); ! 218: putrec(fdat,F_ULER+LEN_ALIAS+5,2,crlf); ! 219: putrec(fdat,F_TIMESDLED,5,ultoa(f->timesdled,tmp,10)); ! 220: putrec(fdat,F_TIMESDLED+5,2,crlf); ! 221: putrec(fdat,F_OPENCOUNT,3,ultoa(f->opencount,tmp,10)); ! 222: putrec(fdat,F_OPENCOUNT+3,2,crlf); ! 223: fdat[F_MISC]=f->misc+SP; ! 224: putrec(fdat,F_ALTPATH,2,hexplus(f->altpath,tmp)); ! 225: putrec(fdat,F_ALTPATH+2,2,crlf); ! 226: f->datoffset=l; ! 227: idx[0]=(uchar)(l&0xff); /* Get offset within DAT file for IXB file */ ! 228: idx[1]=(uchar)((l>>8)&0xff); ! 229: idx[2]=(uchar)((l>>16)&0xff); ! 230: lseek(file,l,SEEK_SET); ! 231: if(write(file,fdat,F_LEN)!=F_LEN) { ! 232: close(file); ! 233: // errormsg(WHERE,ERR_WRITE,str,F_LEN); ! 234: return(FALSE); ! 235: } ! 236: length=filelength(file); ! 237: close(file); ! 238: if(length%F_LEN) { ! 239: // errormsg(WHERE,ERR_LEN,str,length); ! 240: return(FALSE); ! 241: } ! 242: ! 243: /*******************************************/ ! 244: /* Update last upload date/time stamp file */ ! 245: /*******************************************/ ! 246: sprintf(str,"%s%s.dab",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); ! 247: if((file=sopen(str,O_WRONLY|O_CREAT|O_BINARY,SH_DENYRW))!=-1) { ! 248: now=time(NULL); ! 249: write(file,&now,4); ! 250: close(file); ! 251: } ! 252: ! 253: /************************/ ! 254: /* Add data to IXB File */ ! 255: /************************/ ! 256: strcpy(fname,f->name); ! 257: for(i=8;i<12;i++) /* Turn FILENAME.EXT into FILENAMEEXT */ ! 258: fname[i]=fname[i+1]; ! 259: sprintf(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); ! 260: if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW))==-1) { ! 261: // errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_CREAT); ! 262: return(FALSE); ! 263: } ! 264: length=filelength(file); ! 265: if(length) { /* IXB file isn't empty */ ! 266: if(length%F_IXBSIZE) { ! 267: close(file); ! 268: // errormsg(WHERE,ERR_LEN,str,length); ! 269: return(FALSE); ! 270: } ! 271: if((ixbbuf=(uchar *)MALLOC(length))==NULL) { ! 272: close(file); ! 273: // errormsg(WHERE,ERR_ALLOC,str,length); ! 274: return(FALSE); ! 275: } ! 276: if(lread(file,ixbbuf,length)!=length) { ! 277: close(file); ! 278: // errormsg(WHERE,ERR_READ,str,length); ! 279: FREE((char *)ixbbuf); ! 280: return(FALSE); ! 281: } ! 282: /************************************************/ ! 283: /* Sort by Name or Date, Assending or Decending */ ! 284: /************************************************/ ! 285: if(cfg->dir[f->dir]->sort==SORT_NAME_A || cfg->dir[f->dir]->sort==SORT_NAME_D) { ! 286: for(l=0;l<length;l+=F_IXBSIZE) { ! 287: for(i=0;i<12 && fname[i]==ixbbuf[l+i];i++); ! 288: if(i==12) { /* file already in directory index */ ! 289: close(file); ! 290: // errormsg(WHERE,ERR_CHK,str,0); ! 291: FREE((char *)ixbbuf); ! 292: return(FALSE); ! 293: } ! 294: if(cfg->dir[f->dir]->sort==SORT_NAME_A && fname[i]<ixbbuf[l+i]) ! 295: break; ! 296: if(cfg->dir[f->dir]->sort==SORT_NAME_D && fname[i]>ixbbuf[l+i]) ! 297: break; ! 298: } ! 299: } ! 300: else { /* sort by date */ ! 301: for(l=0;l<length;l+=F_IXBSIZE) { ! 302: uldate=(ixbbuf[l+14]|((long)ixbbuf[l+15]<<8) ! 303: |((long)ixbbuf[l+16]<<16)|((long)ixbbuf[l+17]<<24)); ! 304: if(cfg->dir[f->dir]->sort==SORT_DATE_A && f->dateuled<uldate) ! 305: break; ! 306: if(cfg->dir[f->dir]->sort==SORT_DATE_D && f->dateuled>uldate) ! 307: break; ! 308: } ! 309: } ! 310: lseek(file,l,SEEK_SET); ! 311: if(write(file,fname,11)!=11) { /* Write filename to IXB file */ ! 312: close(file); ! 313: // errormsg(WHERE,ERR_WRITE,str,11); ! 314: FREE((char *)ixbbuf); ! 315: return(FALSE); ! 316: } ! 317: if(write(file,idx,3)!=3) { /* Write DAT offset into IXB file */ ! 318: close(file); ! 319: // errormsg(WHERE,ERR_WRITE,str,3); ! 320: FREE((char *)ixbbuf); ! 321: return(FALSE); ! 322: } ! 323: write(file,&f->dateuled,sizeof(time_t)); ! 324: write(file,&f->datedled,4); /* Write 0 for datedled */ ! 325: if(lwrite(file,&ixbbuf[l],length-l)!=length-l) { /* Write rest of IXB */ ! 326: close(file); ! 327: // errormsg(WHERE,ERR_WRITE,str,length-l); ! 328: FREE((char *)ixbbuf); ! 329: return(FALSE); ! 330: } ! 331: FREE((char *)ixbbuf); } ! 332: else { /* IXB file is empty... No files */ ! 333: if(write(file,fname,11)!=11) { /* Write filename it IXB file */ ! 334: close(file); ! 335: // errormsg(WHERE,ERR_WRITE,str,11); ! 336: return(FALSE); ! 337: } ! 338: if(write(file,idx,3)!=3) { /* Write DAT offset into IXB file */ ! 339: close(file); ! 340: // errormsg(WHERE,ERR_WRITE,str,3); ! 341: return(FALSE); ! 342: } ! 343: write(file,&f->dateuled,sizeof(time_t)); ! 344: write(file,&f->datedled,4); ! 345: } ! 346: length=filelength(file); ! 347: close(file); ! 348: /// if(length%F_IXBSIZE) ! 349: // errormsg(WHERE,ERR_LEN,str,length); ! 350: return(TRUE); ! 351: } ! 352: ! 353: /****************************************************************************/ ! 354: /* Gets file data from dircode.ixb file */ ! 355: /* Need fields .name and .dir filled. */ ! 356: /* only fills .offset, .dateuled, and .datedled */ ! 357: /****************************************************************************/ ! 358: BOOL DLLCALL getfileixb(scfg_t* cfg, file_t* f) ! 359: { ! 360: char str[256],fname[13]; ! 361: uchar HUGE16 * ixbbuf; ! 362: int file; ! 363: long l,length; ! 364: ! 365: sprintf(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); ! 366: if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) { ! 367: // errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 368: return(FALSE); ! 369: } ! 370: length=filelength(file); ! 371: if(length%F_IXBSIZE) { ! 372: close(file); ! 373: // errormsg(WHERE,ERR_LEN,str,length); ! 374: return(FALSE); ! 375: } ! 376: if((ixbbuf=(uchar *)MALLOC(length))==NULL) { ! 377: close(file); ! 378: // errormsg(WHERE,ERR_ALLOC,str,length); ! 379: return(FALSE); ! 380: } ! 381: if(lread(file,ixbbuf,length)!=length) { ! 382: close(file); ! 383: FREE((char *)ixbbuf); ! 384: // errormsg(WHERE,ERR_READ,str,length); ! 385: return(FALSE); ! 386: } ! 387: close(file); ! 388: strcpy(fname,f->name); ! 389: for(l=8;l<12;l++) /* Turn FILENAME.EXT into FILENAMEEXT */ ! 390: fname[l]=fname[l+1]; ! 391: for(l=0;l<length;l+=F_IXBSIZE) { ! 392: sprintf(str,"%11.11s",ixbbuf+l); ! 393: if(!strcmp(str,fname)) ! 394: break; ! 395: } ! 396: if(l>=length) { ! 397: // errormsg(WHERE,ERR_CHK,str,0); ! 398: FREE((char *)ixbbuf); ! 399: return(FALSE); ! 400: } ! 401: l+=11; ! 402: f->datoffset=ixbbuf[l]|((long)ixbbuf[l+1]<<8)|((long)ixbbuf[l+2]<<16); ! 403: f->dateuled=ixbbuf[l+3]|((long)ixbbuf[l+4]<<8) ! 404: |((long)ixbbuf[l+5]<<16)|((long)ixbbuf[l+6]<<24); ! 405: f->datedled=ixbbuf[l+7]|((long)ixbbuf[l+8]<<8) ! 406: |((long)ixbbuf[l+9]<<16)|((long)ixbbuf[l+10]<<24); ! 407: FREE((char *)ixbbuf); ! 408: return(TRUE); ! 409: } ! 410: ! 411: /****************************************************************************/ ! 412: /* Removes DAT and IXB entries for the file in the struct 'f' */ ! 413: /****************************************************************************/ ! 414: BOOL DLLCALL removefiledat(scfg_t* cfg, file_t* f) ! 415: { ! 416: char c,str[256],ixbname[12],HUGE16 *ixbbuf,fname[13]; ! 417: int file; ! 418: long l,length; ! 419: ! 420: strcpy(fname,f->name); ! 421: for(c=8;c<12;c++) /* Turn FILENAME.EXT into FILENAMEEXT */ ! 422: fname[c]=fname[c+1]; ! 423: sprintf(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); ! 424: if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) { ! 425: // errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 426: return(FALSE); ! 427: } ! 428: length=filelength(file); ! 429: if(!length) { ! 430: close(file); ! 431: return(FALSE); ! 432: } ! 433: if((ixbbuf=(char *)MALLOC(length))==0) { ! 434: close(file); ! 435: // errormsg(WHERE,ERR_ALLOC,str,length); ! 436: return(FALSE); ! 437: } ! 438: if(lread(file,ixbbuf,length)!=length) { ! 439: close(file); ! 440: // errormsg(WHERE,ERR_READ,str,length); ! 441: FREE((char *)ixbbuf); ! 442: return(FALSE); ! 443: } ! 444: close(file); ! 445: if((file=sopen(str,O_WRONLY|O_TRUNC|O_BINARY,SH_DENYRW))==-1) { ! 446: // errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_TRUNC); ! 447: return(FALSE); ! 448: } ! 449: for(l=0;l<length;l+=F_IXBSIZE) { ! 450: for(c=0;c<11;c++) ! 451: ixbname[c]=ixbbuf[l+c]; ! 452: ixbname[c]=0; ! 453: if(strcmp(ixbname,fname)) ! 454: if(lwrite(file,&ixbbuf[l],F_IXBSIZE)!=F_IXBSIZE) { ! 455: close(file); ! 456: // errormsg(WHERE,ERR_WRITE,str,F_IXBSIZE); ! 457: FREE((char *)ixbbuf); ! 458: return(FALSE); ! 459: } ! 460: } ! 461: FREE((char *)ixbbuf); ! 462: close(file); ! 463: sprintf(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); ! 464: if((file=sopen(str,O_WRONLY|O_BINARY,SH_DENYRW))==-1) { ! 465: // errormsg(WHERE,ERR_OPEN,str,O_WRONLY); ! 466: return(FALSE); ! 467: } ! 468: lseek(file,f->datoffset,SEEK_SET); ! 469: c=ETX; /* If first char of record is ETX, record is unused */ ! 470: if(write(file,&c,1)!=1) { /* So write a D_T on the first byte of the record */ ! 471: close(file); ! 472: // errormsg(WHERE,ERR_WRITE,str,1); ! 473: return(FALSE); ! 474: } ! 475: close(file); ! 476: if(f->dir==cfg->user_dir) /* remove file from index */ ! 477: rmuserxfers(cfg,0,0,f->name); ! 478: return(TRUE); ! 479: } ! 480: ! 481: /****************************************************************************/ ! 482: /* Checks directory data file for 'filename' (must be padded). If found, */ ! 483: /* it returns the 1, else returns 0. */ ! 484: /* Called from upload and bulkupload */ ! 485: /****************************************************************************/ ! 486: BOOL DLLCALL findfile(scfg_t* cfg, uint dirnum, char *filename) ! 487: { ! 488: char str[256],c,fname[13],HUGE16 *ixbbuf; ! 489: int file; ! 490: long length,l; ! 491: ! 492: sprintf(fname,"%.12s",filename); ! 493: strupr(fname); ! 494: for(c=8;c<12;c++) /* Turn FILENAME.EXT into FILENAMEEXT */ ! 495: fname[c]=fname[c+1]; ! 496: sprintf(str,"%s%s.ixb",cfg->dir[dirnum]->data_dir,cfg->dir[dirnum]->code); ! 497: if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) return(FALSE); ! 498: length=filelength(file); ! 499: if(!length) { ! 500: close(file); ! 501: return(FALSE); } ! 502: if((ixbbuf=(char *)MALLOC(length))==NULL) { ! 503: close(file); ! 504: // errormsg(WHERE,ERR_ALLOC,str,length); ! 505: return(FALSE); } ! 506: if(lread(file,ixbbuf,length)!=length) { ! 507: close(file); ! 508: // errormsg(WHERE,ERR_READ,str,length); ! 509: FREE((char *)ixbbuf); ! 510: return(FALSE); } ! 511: close(file); ! 512: for(l=0;l<length;l+=F_IXBSIZE) { ! 513: for(c=0;c<11;c++) ! 514: if(fname[c]!=toupper(ixbbuf[l+c])) break; ! 515: if(c==11) break; } ! 516: FREE((char *)ixbbuf); ! 517: if(l!=length) ! 518: return(TRUE); ! 519: return(FALSE); ! 520: } ! 521: ! 522: /****************************************************************************/ ! 523: /* Turns FILE.EXT into FILE .EXT */ ! 524: /****************************************************************************/ ! 525: char* DLLCALL padfname(char *filename, char *str) ! 526: { ! 527: char c,d; ! 528: ! 529: for(c=0;c<8;c++) ! 530: if(filename[c]=='.' || !filename[c]) break; ! 531: else str[c]=filename[c]; ! 532: d=c; ! 533: if(filename[c]=='.') c++; ! 534: while(d<8) ! 535: str[d++]=SP; ! 536: str[d++]='.'; ! 537: while(d<12) ! 538: if(!filename[c]) break; ! 539: else str[d++]=filename[c++]; ! 540: while(d<12) ! 541: str[d++]=SP; ! 542: str[d]=0; ! 543: return(str); ! 544: } ! 545: ! 546: char* DLLCALL getfname(char* path) ! 547: { ! 548: char *fname; ! 549: ! 550: fname=strrchr(path,'/'); ! 551: if(fname==NULL) ! 552: fname=strrchr(path,'\\'); ! 553: if(fname!=NULL) ! 554: fname++; ! 555: else ! 556: fname=path; ! 557: return(fname); ! 558: } ! 559: ! 560: ! 561: /****************************************************************************/ ! 562: /* Turns FILE .EXT into FILE.EXT */ ! 563: /****************************************************************************/ ! 564: char* DLLCALL unpadfname(char *filename, char *str) ! 565: { ! 566: char c,d; ! 567: ! 568: for(c=0,d=0;filename[c];c++) ! 569: if(filename[c]!=SP) str[d++]=filename[c]; ! 570: str[d]=0; ! 571: return(str); ! 572: } ! 573: ! 574: /****************************************************************************/ ! 575: /* Removes any files in the user transfer index (XFER.IXT) that match the */ ! 576: /* specifications of dest, or source user, or filename or any combination. */ ! 577: /****************************************************************************/ ! 578: BOOL DLLCALL rmuserxfers(scfg_t* cfg, int fromuser, int destuser, char *fname) ! 579: { ! 580: char str[256],*ixtbuf; ! 581: int file; ! 582: long l,length; ! 583: ! 584: sprintf(str,"%sxfer.ixt", cfg->data_dir); ! 585: if(!fexist(str)) ! 586: return(FALSE); ! 587: if(!flength(str)) { ! 588: remove(str); ! 589: return(FALSE); ! 590: } ! 591: if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) { ! 592: // errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 593: return(FALSE); ! 594: } ! 595: length=filelength(file); ! 596: if((ixtbuf=(char *)MALLOC(length))==NULL) { ! 597: close(file); ! 598: // errormsg(WHERE,ERR_ALLOC,str,length); ! 599: return(FALSE); ! 600: } ! 601: if(read(file,ixtbuf,length)!=length) { ! 602: close(file); ! 603: FREE(ixtbuf); ! 604: // errormsg(WHERE,ERR_READ,str,length); ! 605: return(FALSE); ! 606: } ! 607: close(file); ! 608: if((file=sopen(str,O_WRONLY|O_TRUNC|O_BINARY,SH_DENYRW))==-1) { ! 609: FREE(ixtbuf); ! 610: // errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_TRUNC); ! 611: return(FALSE); ! 612: } ! 613: for(l=0;l<length;l+=24) { ! 614: if(fname!=NULL && fname[0]) { /* fname specified */ ! 615: if(!strncmp(ixtbuf+l+5,fname,12)) { /* this is the file */ ! 616: if(destuser && fromuser) { /* both dest and from user */ ! 617: if(atoi(ixtbuf+l)==destuser && atoi(ixtbuf+l+18)==fromuser) ! 618: continue; } /* both match */ ! 619: else if(fromuser) { /* from user */ ! 620: if(atoi(ixtbuf+l+18)==fromuser) /* matches */ ! 621: continue; } ! 622: else if(destuser) { /* dest user */ ! 623: if(atoi(ixtbuf+l)==destuser) /* matches */ ! 624: continue; } ! 625: else continue; } } /* no users, so match */ ! 626: else if(destuser && fromuser) { ! 627: if(atoi(ixtbuf+l+18)==fromuser && atoi(ixtbuf+l)==destuser) ! 628: continue; } ! 629: else if(destuser && atoi(ixtbuf+l)==destuser) ! 630: continue; ! 631: else if(fromuser && atoi(ixtbuf+l+18)==fromuser) ! 632: continue; ! 633: write(file,ixtbuf+l,24); } ! 634: close(file); ! 635: FREE(ixtbuf); ! 636: ! 637: return(TRUE); ! 638: } ! 639:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.