Annotation of sbbs/sbbs3/filedat.c, revision 1.1.1.2

1.1       root        1: /* filedat.c */
                      2: 
                      3: /* Synchronet file database-related exported functions */
                      4: 
1.1.1.2 ! root        5: /* $Id: filedat.c,v 1.23 2004/05/30 06:47:52 deuce Exp $ */
1.1       root        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:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       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: {
1.1.1.2 ! root       47:        char buf[F_LEN+1],str[256];
1.1       root       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:                return(FALSE); 
                     54:        }
                     55:        length=filelength(file);
                     56:        if(f->datoffset>length) {
                     57:                close(file);
                     58:                return(FALSE); 
                     59:        }
                     60:        if(length%F_LEN) {
                     61:                close(file);
                     62:                return(FALSE); 
                     63:        }
                     64:        lseek(file,f->datoffset,SEEK_SET);
                     65:        if(read(file,buf,F_LEN)!=F_LEN) {
                     66:                close(file);
                     67:                return(FALSE); 
                     68:        }
                     69:        close(file);
                     70:        getrec(buf,F_ALTPATH,2,str);
                     71:        f->altpath=hptoi(str);
                     72:        getrec(buf,F_CDT,LEN_FCDT,str);
                     73:        f->cdt=atol(str);
                     74: 
                     75:        if(!f->size) {                                  /* only read disk if this is null */
1.1.1.2 ! root       76:                        getfilepath(cfg,f,str);
1.1       root       77:                        f->size=flength(str);
                     78:                        f->date=fdate(str);
                     79:        /*
                     80:                        }
                     81:                else {
                     82:                        f->size=f->cdt;
                     83:                        f->date=0; }
                     84:        */
                     85:                        }
                     86: #if 0
                     87:        if((f->size>0L) && cur_cps)
                     88:                f->timetodl=(ushort)(f->size/(ulong)cur_cps);
                     89:        else
                     90: #endif
                     91:                f->timetodl=0;
                     92: 
                     93:        getrec(buf,F_DESC,LEN_FDESC,f->desc);
                     94:        getrec(buf,F_ULER,LEN_ALIAS,f->uler);
                     95:        getrec(buf,F_TIMESDLED,5,str);
                     96:        f->timesdled=atoi(str);
                     97:        getrec(buf,F_OPENCOUNT,3,str);
                     98:        f->opencount=atoi(str);
                     99:        if(buf[F_MISC]!=ETX)
1.1.1.2 ! root      100:                f->misc=buf[F_MISC]-' ';
1.1       root      101:        else
                    102:                f->misc=0;
                    103:        return(TRUE);
                    104: }
                    105: 
                    106: /****************************************************************************/
                    107: /* Puts filedata into DIR_code.DAT file                                     */
                    108: /* Called from removefiles                                                  */
                    109: /****************************************************************************/
                    110: BOOL DLLCALL putfiledat(scfg_t* cfg, file_t* f)
                    111: {
                    112:     char buf[F_LEN+1],str[256],tmp[128];
                    113:     int file;
                    114:     long length;
                    115: 
                    116:        putrec(buf,F_CDT,LEN_FCDT,ultoa(f->cdt,tmp,10));
                    117:        putrec(buf,F_DESC,LEN_FDESC,f->desc);
                    118:        putrec(buf,F_DESC+LEN_FDESC,2,crlf);
                    119:        putrec(buf,F_ULER,LEN_ALIAS+5,f->uler);
                    120:        putrec(buf,F_ULER+LEN_ALIAS+5,2,crlf);
                    121:        putrec(buf,F_TIMESDLED,5,ultoa(f->timesdled,tmp,10));
                    122:        putrec(buf,F_TIMESDLED+5,2,crlf);
                    123:        putrec(buf,F_OPENCOUNT,3,ultoa(f->opencount,tmp,10));
                    124:        putrec(buf,F_OPENCOUNT+3,2,crlf);
1.1.1.2 ! root      125:        buf[F_MISC]=f->misc+' ';
1.1       root      126:        putrec(buf,F_ALTPATH,2,hexplus(f->altpath,tmp));
                    127:        putrec(buf,F_ALTPATH+2,2,crlf);
                    128:        sprintf(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
                    129:        if((file=sopen(str,O_WRONLY|O_BINARY,SH_DENYRW))==-1) {
                    130:                return(FALSE); 
                    131:        }
                    132:        length=filelength(file);
                    133:        if(length%F_LEN) {
                    134:                close(file);
                    135:                return(FALSE); 
                    136:        }
                    137:        if(f->datoffset>length) {
                    138:                close(file);
                    139:                return(FALSE); 
                    140:        }
                    141:        lseek(file,f->datoffset,SEEK_SET);
                    142:        if(write(file,buf,F_LEN)!=F_LEN) {
                    143:                close(file);
                    144:                return(FALSE); 
                    145:        }
                    146:        length=filelength(file);
                    147:        close(file);
                    148:        if(length%F_LEN) {
                    149:                return(FALSE);
                    150:        }
                    151:        return(TRUE);
                    152: }
                    153: 
                    154: /****************************************************************************/
                    155: /* Adds the data for struct filedat to the directory's data base.           */
                    156: /* changes the .datoffset field only                                        */
                    157: /* returns 1 if added successfully, 0 if not.                                                          */
                    158: /****************************************************************************/
                    159: BOOL DLLCALL addfiledat(scfg_t* cfg, file_t* f)
                    160: {
                    161:        char    str[256],fname[13],c,fdat[F_LEN+1];
                    162:        char    tmp[128];
                    163:        uchar   HUGE16 *ixbbuf,idx[3];
                    164:     int                i,file;
                    165:        long    l,length;
                    166:        time_t  now;
                    167:        time_t  uldate;
                    168: 
                    169:        /************************/
                    170:        /* Add data to DAT File */
                    171:        /************************/
                    172:        sprintf(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
1.1.1.2 ! root      173:        if((file=sopen(str,O_RDWR|O_BINARY|O_CREAT,SH_DENYRW,S_IREAD|S_IWRITE))==-1) {
1.1       root      174:                return(FALSE); 
                    175:        }
                    176:        length=filelength(file);
                    177:        if(length==0L)
                    178:                l=0L;
                    179:        else {
                    180:                if(length%F_LEN) {
                    181:                        close(file);
                    182:                        return(FALSE); 
                    183:                }
                    184:                for(l=0;l<length;l+=F_LEN) {    /* Find empty slot */
                    185:                        lseek(file,l,SEEK_SET);
                    186:                        read(file,&c,1);
                    187:                        if(c==ETX) break; 
                    188:                }
                    189:                if(l/F_LEN>=MAX_FILES || l/F_LEN>=cfg->dir[f->dir]->maxfiles) {
                    190:                        close(file);
                    191:                        return(FALSE); 
                    192:                } 
                    193:        }
                    194:        putrec(fdat,F_CDT,LEN_FCDT,ultoa(f->cdt,tmp,10));
                    195:        putrec(fdat,F_DESC,LEN_FDESC,f->desc);
                    196:        putrec(fdat,F_DESC+LEN_FDESC,2,crlf);
                    197:        putrec(fdat,F_ULER,LEN_ALIAS+5,f->uler);
                    198:        putrec(fdat,F_ULER+LEN_ALIAS+5,2,crlf);
                    199:        putrec(fdat,F_TIMESDLED,5,ultoa(f->timesdled,tmp,10));
                    200:        putrec(fdat,F_TIMESDLED+5,2,crlf);
                    201:        putrec(fdat,F_OPENCOUNT,3,ultoa(f->opencount,tmp,10));
                    202:        putrec(fdat,F_OPENCOUNT+3,2,crlf);
1.1.1.2 ! root      203:        fdat[F_MISC]=f->misc+' ';
1.1       root      204:        putrec(fdat,F_ALTPATH,2,hexplus(f->altpath,tmp));
                    205:        putrec(fdat,F_ALTPATH+2,2,crlf);
                    206:        f->datoffset=l;
                    207:        idx[0]=(uchar)(l&0xff);          /* Get offset within DAT file for IXB file */
                    208:        idx[1]=(uchar)((l>>8)&0xff);
                    209:        idx[2]=(uchar)((l>>16)&0xff);
                    210:        lseek(file,l,SEEK_SET);
                    211:        if(write(file,fdat,F_LEN)!=F_LEN) {
                    212:                close(file);
                    213:                return(FALSE); 
                    214:        }
                    215:        length=filelength(file);
                    216:        close(file);
                    217:        if(length%F_LEN) {
                    218:                return(FALSE);
                    219:        }
                    220: 
                    221:        /*******************************************/
                    222:        /* Update last upload date/time stamp file */
                    223:        /*******************************************/
                    224:        sprintf(str,"%s%s.dab",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
1.1.1.2 ! root      225:        if((file=sopen(str,O_WRONLY|O_CREAT|O_BINARY,SH_DENYRW,S_IREAD|S_IWRITE))!=-1) {
1.1       root      226:                now=time(NULL);
                    227:                write(file,&now,4);
                    228:                close(file); 
                    229:        }
                    230: 
                    231:        /************************/
                    232:        /* Add data to IXB File */
                    233:        /************************/
                    234:        strcpy(fname,f->name);
                    235:        for(i=8;i<12;i++)   /* Turn FILENAME.EXT into FILENAMEEXT */
                    236:                fname[i]=fname[i+1];
                    237:        sprintf(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
1.1.1.2 ! root      238:        if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW,S_IREAD|S_IWRITE))==-1) {
1.1       root      239:                return(FALSE); 
                    240:        }
                    241:        length=filelength(file);
                    242:        if(length) {    /* IXB file isn't empty */
                    243:                if(length%F_IXBSIZE) {
                    244:                        close(file);
                    245:                        return(FALSE); 
                    246:                }
                    247:                if((ixbbuf=(uchar *)MALLOC(length))==NULL) {
                    248:                        close(file);
                    249:                        return(FALSE); 
                    250:                }
                    251:                if(lread(file,ixbbuf,length)!=length) {
                    252:                        close(file);
                    253:                        FREE((char *)ixbbuf);
                    254:                        return(FALSE); 
                    255:                }
                    256:        /************************************************/
                    257:        /* Sort by Name or Date, Assending or Decending */
                    258:        /************************************************/
                    259:                if(cfg->dir[f->dir]->sort==SORT_NAME_A || cfg->dir[f->dir]->sort==SORT_NAME_D) {
                    260:                        for(l=0;l<length;l+=F_IXBSIZE) {
1.1.1.2 ! root      261:                                for(i=0;i<12 && toupper(fname[i])==toupper(ixbbuf[l+i]);i++);
1.1       root      262:                                if(i==12) {     /* file already in directory index */
                    263:                                        close(file);
                    264:                                        FREE((char *)ixbbuf);
                    265:                                        return(FALSE); 
                    266:                                }
1.1.1.2 ! root      267:                                if(cfg->dir[f->dir]->sort==SORT_NAME_A 
        !           268:                                        && toupper(fname[i])<toupper(ixbbuf[l+i]))
1.1       root      269:                                        break;
1.1.1.2 ! root      270:                                if(cfg->dir[f->dir]->sort==SORT_NAME_D 
        !           271:                                        && toupper(fname[i])>toupper(ixbbuf[l+i]))
1.1       root      272:                                        break; 
                    273:                        } 
                    274:                }
                    275:                else {  /* sort by date */
                    276:                        for(l=0;l<length;l+=F_IXBSIZE) {
                    277:                                uldate=(ixbbuf[l+14]|((long)ixbbuf[l+15]<<8)
                    278:                                        |((long)ixbbuf[l+16]<<16)|((long)ixbbuf[l+17]<<24));
                    279:                                if(cfg->dir[f->dir]->sort==SORT_DATE_A && f->dateuled<uldate)
                    280:                                        break;
                    281:                                if(cfg->dir[f->dir]->sort==SORT_DATE_D && f->dateuled>uldate)
                    282:                                        break; 
                    283:                        } 
                    284:                }
                    285:                lseek(file,l,SEEK_SET);
                    286:                if(write(file,fname,11)!=11) {  /* Write filename to IXB file */
                    287:                        close(file);
                    288:                        FREE((char *)ixbbuf);
                    289:                        return(FALSE); 
                    290:                }
                    291:                if(write(file,idx,3)!=3) {  /* Write DAT offset into IXB file */
                    292:                        close(file);
                    293:                        FREE((char *)ixbbuf);
                    294:                        return(FALSE); 
                    295:                }
                    296:                write(file,&f->dateuled,sizeof(time_t));
                    297:                write(file,&f->datedled,4);              /* Write 0 for datedled */
                    298:                if(lwrite(file,&ixbbuf[l],length-l)!=length-l) { /* Write rest of IXB */
                    299:                        close(file);
                    300:                        FREE((char *)ixbbuf);
                    301:                        return(FALSE); 
                    302:                }
                    303:                FREE((char *)ixbbuf); }
                    304:        else {              /* IXB file is empty... No files */
                    305:                if(write(file,fname,11)!=11) {  /* Write filename it IXB file */
                    306:                        close(file);
                    307:                        return(FALSE); 
                    308:                }
                    309:                if(write(file,idx,3)!=3) {  /* Write DAT offset into IXB file */
                    310:                        close(file);
                    311:                        return(FALSE); 
                    312:                }
                    313:                write(file,&f->dateuled,sizeof(time_t));
                    314:                write(file,&f->datedled,4); 
                    315:        }
                    316:        length=filelength(file);
                    317:        close(file);
                    318:        return(TRUE);
                    319: }
                    320: 
                    321: /****************************************************************************/
                    322: /* Gets file data from dircode.ixb file                                                                                */
                    323: /* Need fields .name and .dir filled.                                       */
                    324: /* only fills .offset, .dateuled, and .datedled                             */
                    325: /****************************************************************************/
                    326: BOOL DLLCALL getfileixb(scfg_t* cfg, file_t* f)
                    327: {
                    328:        char                    str[256],fname[13];
                    329:        uchar HUGE16 *  ixbbuf;
                    330:        int                             file;
                    331:        long                    l,length;
                    332: 
                    333:        sprintf(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
                    334:        if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) {
                    335:                return(FALSE); 
                    336:        }
                    337:        length=filelength(file);
                    338:        if(length%F_IXBSIZE) {
                    339:                close(file);
                    340:                return(FALSE); 
                    341:        }
                    342:        if((ixbbuf=(uchar *)MALLOC(length))==NULL) {
                    343:                close(file);
                    344:                return(FALSE); 
                    345:        }
                    346:        if(lread(file,ixbbuf,length)!=length) {
                    347:                close(file);
                    348:                FREE((char *)ixbbuf);
                    349:                return(FALSE); 
                    350:        }
                    351:        close(file);
                    352:        strcpy(fname,f->name);
                    353:        for(l=8;l<12;l++)       /* Turn FILENAME.EXT into FILENAMEEXT */
                    354:                fname[l]=fname[l+1];
                    355:        for(l=0;l<length;l+=F_IXBSIZE) {
                    356:                sprintf(str,"%11.11s",ixbbuf+l);
1.1.1.2 ! root      357:                if(!stricmp(str,fname))
1.1       root      358:                        break; 
                    359:        }
                    360:        if(l>=length) {
                    361:                FREE((char *)ixbbuf);
                    362:                return(FALSE); 
                    363:        }
                    364:        l+=11;
                    365:        f->datoffset=ixbbuf[l]|((long)ixbbuf[l+1]<<8)|((long)ixbbuf[l+2]<<16);
                    366:        f->dateuled=ixbbuf[l+3]|((long)ixbbuf[l+4]<<8)
                    367:                |((long)ixbbuf[l+5]<<16)|((long)ixbbuf[l+6]<<24);
                    368:        f->datedled=ixbbuf[l+7]|((long)ixbbuf[l+8]<<8)
                    369:                |((long)ixbbuf[l+9]<<16)|((long)ixbbuf[l+10]<<24);
                    370:        FREE((char *)ixbbuf);
                    371:        return(TRUE);
                    372: }
                    373: 
                    374: /****************************************************************************/
                    375: /* Removes DAT and IXB entries for the file in the struct 'f'               */
                    376: /****************************************************************************/
                    377: BOOL DLLCALL removefiledat(scfg_t* cfg, file_t* f)
                    378: {
                    379:        char    c,str[256],ixbname[12],HUGE16 *ixbbuf,fname[13];
1.1.1.2 ! root      380:     int                i,file;
1.1       root      381:        long    l,length;
                    382: 
                    383:        strcpy(fname,f->name);
1.1.1.2 ! root      384:        for(i=8;i<12;i++)   /* Turn FILENAME.EXT into FILENAMEEXT */
        !           385:                fname[i]=fname[i+1];
1.1       root      386:        sprintf(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
                    387:        if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) {
                    388:                return(FALSE); 
                    389:        }
                    390:        length=filelength(file);
                    391:        if(!length) {
                    392:                close(file);
                    393:                return(FALSE); 
                    394:        }
                    395:        if((ixbbuf=(char *)MALLOC(length))==0) {
                    396:                close(file);
                    397:                return(FALSE); 
                    398:        }
                    399:        if(lread(file,ixbbuf,length)!=length) {
                    400:                close(file);
                    401:                FREE((char *)ixbbuf);
                    402:                return(FALSE); 
                    403:        }
                    404:        close(file);
                    405:        if((file=sopen(str,O_WRONLY|O_TRUNC|O_BINARY,SH_DENYRW))==-1) {
                    406:                return(FALSE); 
                    407:        }
                    408:        for(l=0;l<length;l+=F_IXBSIZE) {
1.1.1.2 ! root      409:                for(i=0;i<11;i++)
        !           410:                        ixbname[i]=ixbbuf[l+i];
        !           411:                ixbname[i]=0;
        !           412:                if(stricmp(ixbname,fname))
1.1       root      413:                        if(lwrite(file,&ixbbuf[l],F_IXBSIZE)!=F_IXBSIZE) {
                    414:                                close(file);
                    415:                                FREE((char *)ixbbuf);
                    416:                                return(FALSE); 
                    417:                } 
                    418:        }
                    419:        FREE((char *)ixbbuf);
                    420:        close(file);
                    421:        sprintf(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
                    422:        if((file=sopen(str,O_WRONLY|O_BINARY,SH_DENYRW))==-1) {
                    423:                return(FALSE); 
                    424:        }
                    425:        lseek(file,f->datoffset,SEEK_SET);
                    426:        c=ETX;          /* If first char of record is ETX, record is unused */
                    427:        if(write(file,&c,1)!=1) { /* So write a D_T on the first byte of the record */
                    428:                close(file);
                    429:                return(FALSE); 
                    430:        }
                    431:        close(file);
                    432:        if(f->dir==cfg->user_dir)  /* remove file from index */
                    433:                rmuserxfers(cfg,0,0,f->name);
                    434:        return(TRUE);
                    435: }
                    436: 
                    437: /****************************************************************************/
                    438: /* Checks  directory data file for 'filename' (must be padded). If found,   */
                    439: /* it returns the 1, else returns 0.                                        */
                    440: /* Called from upload and bulkupload                                        */
                    441: /****************************************************************************/
                    442: BOOL DLLCALL findfile(scfg_t* cfg, uint dirnum, char *filename)
                    443: {
1.1.1.2 ! root      444:        char str[256],fname[13],HUGE16 *ixbbuf;
        !           445:     int i,file;
1.1       root      446:     long length,l;
                    447: 
                    448:        sprintf(fname,"%.12s",filename);
                    449:        strupr(fname);
1.1.1.2 ! root      450:        for(i=8;i<12;i++)   /* Turn FILENAME.EXT into FILENAMEEXT */
        !           451:                fname[i]=fname[i+1];
1.1       root      452:        sprintf(str,"%s%s.ixb",cfg->dir[dirnum]->data_dir,cfg->dir[dirnum]->code);
                    453:        if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) return(FALSE);
                    454:        length=filelength(file);
                    455:        if(!length) {
                    456:                close(file);
                    457:                return(FALSE); }
                    458:        if((ixbbuf=(char *)MALLOC(length))==NULL) {
                    459:                close(file);
                    460:                return(FALSE); }
                    461:        if(lread(file,ixbbuf,length)!=length) {
                    462:                close(file);
                    463:                FREE((char *)ixbbuf);
                    464:                return(FALSE); }
                    465:        close(file);
                    466:        for(l=0;l<length;l+=F_IXBSIZE) {
1.1.1.2 ! root      467:                for(i=0;i<11;i++)
        !           468:                        if(toupper(fname[i])!=toupper(ixbbuf[l+i])) break;
        !           469:                if(i==11) break; }
1.1       root      470:        FREE((char *)ixbbuf);
                    471:        if(l!=length)
                    472:                return(TRUE);
                    473:        return(FALSE);
                    474: }
                    475: 
                    476: /****************************************************************************/
                    477: /* Turns FILE.EXT into FILE    .EXT                                         */
                    478: /****************************************************************************/
                    479: char* DLLCALL padfname(char *filename, char *str)
                    480: {
1.1.1.2 ! root      481:     int c,d;
1.1       root      482: 
                    483:        for(c=0;c<8;c++)
                    484:                if(filename[c]=='.' || !filename[c]) break;
                    485:                else str[c]=filename[c];
                    486:        d=c;
                    487:        if(filename[c]=='.') c++;
                    488:        while(d<8)
1.1.1.2 ! root      489:                str[d++]=' ';
        !           490:        if(filename[c]>' ')     /* Change "FILE" to "FILE        " */
        !           491:                str[d++]='.';   /* (don't add a dot if there's no extension) */
        !           492:        else
        !           493:                str[d++]=' ';
1.1       root      494:        while(d<12)
                    495:                if(!filename[c]) break;
                    496:                else str[d++]=filename[c++];
                    497:        while(d<12)
1.1.1.2 ! root      498:                str[d++]=' ';
1.1       root      499:        str[d]=0;
                    500:        return(str);
                    501: }
                    502: 
                    503: /****************************************************************************/
                    504: /* Turns FILE    .EXT into FILE.EXT                                         */
                    505: /****************************************************************************/
                    506: char* DLLCALL unpadfname(char *filename, char *str)
                    507: {
1.1.1.2 ! root      508:     int c,d;
1.1       root      509: 
                    510:        for(c=0,d=0;filename[c];c++)
1.1.1.2 ! root      511:                if(filename[c]!=' ') str[d++]=filename[c];
1.1       root      512:        str[d]=0;
                    513:        return(str);
                    514: }
                    515: 
                    516: /****************************************************************************/
                    517: /* Removes any files in the user transfer index (XFER.IXT) that match the   */
                    518: /* specifications of dest, or source user, or filename or any combination.  */
                    519: /****************************************************************************/
                    520: BOOL DLLCALL rmuserxfers(scfg_t* cfg, int fromuser, int destuser, char *fname)
                    521: {
                    522:     char str[256],*ixtbuf;
                    523:     int file;
                    524:     long l,length;
                    525: 
                    526:        sprintf(str,"%sxfer.ixt", cfg->data_dir);
                    527:        if(!fexist(str))
                    528:                return(FALSE);
                    529:        if(!flength(str)) {
                    530:                remove(str);
                    531:                return(FALSE); 
                    532:        }
                    533:        if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) {
                    534:                return(FALSE); 
                    535:        }
                    536:        length=filelength(file);
                    537:        if((ixtbuf=(char *)MALLOC(length))==NULL) {
                    538:                close(file);
                    539:                return(FALSE); 
                    540:        }
                    541:        if(read(file,ixtbuf,length)!=length) {
                    542:                close(file);
                    543:                FREE(ixtbuf);
                    544:                return(FALSE); 
                    545:        }
                    546:        close(file);
                    547:        if((file=sopen(str,O_WRONLY|O_TRUNC|O_BINARY,SH_DENYRW))==-1) {
                    548:                FREE(ixtbuf);
                    549:                return(FALSE); 
                    550:        }
                    551:        for(l=0;l<length;l+=24) {
                    552:                if(fname!=NULL && fname[0]) {               /* fname specified */
                    553:                        if(!strncmp(ixtbuf+l+5,fname,12)) {     /* this is the file */
                    554:                                if(destuser && fromuser) {          /* both dest and from user */
                    555:                                        if(atoi(ixtbuf+l)==destuser && atoi(ixtbuf+l+18)==fromuser)
                    556:                                                continue; }                 /* both match */
                    557:                                else if(fromuser) {                 /* from user */
                    558:                                        if(atoi(ixtbuf+l+18)==fromuser) /* matches */
                    559:                                                continue; }
                    560:                                else if(destuser) {                 /* dest user */
                    561:                                        if(atoi(ixtbuf+l)==destuser)    /* matches */
                    562:                                                continue; }
                    563:                                else continue; } }                  /* no users, so match */
                    564:                else if(destuser && fromuser) {
                    565:                        if(atoi(ixtbuf+l+18)==fromuser && atoi(ixtbuf+l)==destuser)
                    566:                                continue; }
                    567:                else if(destuser && atoi(ixtbuf+l)==destuser)
                    568:                        continue;
                    569:                else if(fromuser && atoi(ixtbuf+l+18)==fromuser)
                    570:                        continue;
                    571:                write(file,ixtbuf+l,24); }
                    572:        close(file);
                    573:        FREE(ixtbuf);
                    574: 
                    575:        return(TRUE);
                    576: }
                    577: 
1.1.1.2 ! root      578: void DLLCALL getextdesc(scfg_t* cfg, uint dirnum, ulong datoffset, char *ext)
        !           579: {
        !           580:        char str[256];
        !           581:        int file;
        !           582: 
        !           583:        memset(ext,0,F_EXBSIZE+1);
        !           584:        sprintf(str,"%s%s.exb",cfg->dir[dirnum]->data_dir,cfg->dir[dirnum]->code);
        !           585:        if((file=nopen(str,O_RDONLY))==-1)
        !           586:                return;
        !           587:        lseek(file,(datoffset/F_LEN)*F_EXBSIZE,SEEK_SET);
        !           588:        read(file,ext,F_EXBSIZE);
        !           589:        close(file);
        !           590: }
        !           591: 
        !           592: void DLLCALL putextdesc(scfg_t* cfg, uint dirnum, ulong datoffset, char *ext)
        !           593: {
        !           594:        char str[256],nulbuf[F_EXBSIZE];
        !           595:        int file;
        !           596: 
        !           597:        strip_invalid_attr(ext);        /* eliminate bogus ctrl-a codes */
        !           598:        memset(nulbuf,0,sizeof(nulbuf));
        !           599:        sprintf(str,"%s%s.exb",cfg->dir[dirnum]->data_dir,cfg->dir[dirnum]->code);
        !           600:        if((file=nopen(str,O_WRONLY|O_CREAT))==-1)
        !           601:                return;
        !           602:        lseek(file,0L,SEEK_END);
        !           603:        while(filelength(file)<(long)(datoffset/F_LEN)*F_EXBSIZE)
        !           604:                write(file,nulbuf,sizeof(nulbuf));
        !           605:        lseek(file,(datoffset/F_LEN)*F_EXBSIZE,SEEK_SET);
        !           606:        write(file,ext,F_EXBSIZE);
        !           607:        close(file);
        !           608: }
        !           609: 
        !           610: /****************************************************************************/
        !           611: /* Update the upload date for the file 'f'                                  */
        !           612: /****************************************************************************/
        !           613: int DLLCALL update_uldate(scfg_t* cfg, file_t* f)
        !           614: {
        !           615:        char str[256],fname[13];
        !           616:        int i,file;
        !           617:        long l,length;
        !           618: 
        !           619:        /*******************/
        !           620:        /* Update IXB File */
        !           621:        /*******************/
        !           622:        sprintf(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
        !           623:        if((file=nopen(str,O_RDWR))==-1)
        !           624:                return(errno); 
        !           625:        length=filelength(file);
        !           626:        if(length%F_IXBSIZE) {
        !           627:                close(file);
        !           628:                return(-1); 
        !           629:        }
        !           630:        strcpy(fname,f->name);
        !           631:        for(i=8;i<12;i++)   /* Turn FILENAME.EXT into FILENAMEEXT */
        !           632:                fname[i]=fname[i+1];
        !           633:        for(l=0;l<length;l+=F_IXBSIZE) {
        !           634:                read(file,str,F_IXBSIZE);      /* Look for the filename in the IXB file */
        !           635:                str[11]=0;
        !           636:                if(!strcmp(fname,str)) break; }
        !           637:        if(l>=length) {
        !           638:                close(file);
        !           639:                return(-2); 
        !           640:        }
        !           641:        lseek(file,l+14,SEEK_SET);
        !           642:        write(file,&f->dateuled,4);
        !           643:        close(file);
        !           644: 
        !           645:        /*******************************************/
        !           646:        /* Update last upload date/time stamp file */
        !           647:        /*******************************************/
        !           648:        sprintf(str,"%s%s.dab",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
        !           649:        if((file=nopen(str,O_WRONLY|O_CREAT))==-1)
        !           650:                return(errno);
        !           651: 
        !           652:        write(file,&f->dateuled,4);
        !           653:        close(file); 
        !           654:        return(0);
        !           655: }
        !           656: 
        !           657: /****************************************************************************/
        !           658: /* Returns full path to specified file                                                                         */
        !           659: /****************************************************************************/
        !           660: char* DLLCALL getfilepath(scfg_t* cfg, file_t* f, char* path)
        !           661: {
        !           662:        char    fname[MAX_PATH+1];
        !           663: 
        !           664:        unpadfname(f->name,fname);
        !           665:        if(f->dir>=cfg->total_dirs)
        !           666:                sprintf(path,"%s%s",cfg->temp_dir,fname);
        !           667:        else
        !           668:                sprintf(path,"%s%s",f->altpath>0 && f->altpath<=cfg->altpaths 
        !           669:                        ? cfg->altpath[f->altpath-1] : cfg->dir[f->dir]->path
        !           670:                        ,fname);
        !           671: 
        !           672:        return(path);
        !           673: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.