Annotation of sbbs/src/sbbs3/bat_xfer.cpp, revision 1.1.1.1

1.1       root        1: /* bat_xfer.cpp */
                      2: 
                      3: /* Synchronet batch file transfer functions */
                      4: 
                      5: /* $Id: bat_xfer.cpp,v 1.30 2005/06/01 02:41:49 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: /* This is the batch menu section                                           */
                     42: /****************************************************************************/
                     43: void sbbs_t::batchmenu()
                     44: {
                     45:     char       str[129],tmp2[250],done=0,ch;
                     46:        char    tmp[512];
                     47:        uint    i,n,xfrprot,xfrdir;
                     48:     ulong      totalcdt,totalsize,totaltime;
                     49:     time_t     start,end;
                     50:     file_t     f;
                     51: 
                     52:        if(!batdn_total && !batup_total && cfg.upload_dir==INVALID_DIR) {
                     53:                bputs(text[NoFilesInBatchQueue]);
                     54:                return; 
                     55:        }
                     56:        if(useron.misc&(RIP|WIP|HTML) && !(useron.misc&EXPERT))
                     57:                menu("batchxfer");
                     58:        lncntr=0;
                     59:        while(online && !done && (batdn_total || batup_total
                     60:                || cfg.upload_dir!=INVALID_DIR)) {
                     61:                if(!(useron.misc&(EXPERT|RIP|WIP|HTML))) {
                     62:                        sys_status&=~SS_ABORT;
                     63:                        if(lncntr) {
                     64:                                SYNC;
                     65:                                CRLF;
                     66:                                if(lncntr)          /* CRLF or SYNC can cause pause */
                     67:                                        pause(); 
                     68:                        }
                     69:                        menu("batchxfr"); 
                     70:                }
                     71:                ASYNC;
                     72:                bputs(text[BatchMenuPrompt]);
                     73:                ch=(char)getkeys("BCDLQRU?\r",0);
                     74:                if(ch>' ')
                     75:                        logch(ch,0);
                     76:                switch(ch) {
                     77:                        case '?':
                     78:                                if(useron.misc&(EXPERT|RIP|WIP|HTML))
                     79:                                        menu("batchxfr");
                     80:                                break;
                     81:                        case CR:
                     82:                        case 'Q':
                     83:                                lncntr=0;
                     84:                                done=1;
                     85:                                break;
                     86:                        case 'B':   /* Bi-directional transfers */
                     87:                                if(useron.rest&FLAG('D')) {
                     88:                                        bputs(text[R_Download]);
                     89:                                        break; 
                     90:                                }
                     91:                                if(useron.rest&FLAG('U')) {
                     92:                                        bputs(text[R_Upload]);
                     93:                                        break; 
                     94:                                }
                     95:                                if(!batdn_total) {
                     96:                                        bputs(text[DownloadQueueIsEmpty]);
                     97:                                        break; 
                     98:                                }
                     99:                                if(!batup_total && cfg.upload_dir==INVALID_DIR) {
                    100:                                        bputs(text[UploadQueueIsEmpty]);
                    101:                                        break; 
                    102:                                }
                    103:                                for(i=0,totalcdt=0;i<batdn_total;i++)
                    104:                                        if(!is_download_free(&cfg,batdn_dir[i],&useron))
                    105:                                                totalcdt+=batdn_cdt[i];
                    106:                                if(totalcdt>useron.cdt+useron.freecdt) {
                    107:                                        bprintf(text[YouOnlyHaveNCredits]
                    108:                                                ,ultoac(useron.cdt+useron.freecdt,tmp));
                    109:                                        break; 
                    110:                                }
                    111:                                for(i=0,totalsize=totaltime=0;i<batdn_total;i++) {
                    112:                                        totalsize+=batdn_size[i];
                    113:                                        if(!(cfg.dir[batdn_dir[i]]->misc&DIR_TFREE) && cur_cps)
                    114:                                                totaltime+=batdn_size[i]/(ulong)cur_cps; 
                    115:                                }
                    116:                                if(!(useron.exempt&FLAG('T')) && !SYSOP && totaltime>timeleft) {
                    117:                                        bputs(text[NotEnoughTimeToDl]);
                    118:                                        break; 
                    119:                                }
                    120:                                xfer_prot_menu(XFER_BIDIR);
                    121:                                SYNC;
                    122:                                mnemonics(text[ProtocolOrQuit]);
                    123:                                strcpy(tmp2,"Q");
                    124:                                for(i=0;i<cfg.total_prots;i++)
                    125:                                        if(cfg.prot[i]->bicmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
                    126:                                                sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
                    127:                                                strcat(tmp2,tmp); }
                    128:                                ungetkey(useron.prot);
                    129:                                ch=(char)getkeys(tmp2,0);
                    130:                                if(ch=='Q')
                    131:                                        break;
                    132:                                for(i=0;i<cfg.total_prots;i++)
                    133:                                        if(cfg.prot[i]->bicmd[0] && cfg.prot[i]->mnemonic==ch
                    134:                                                && chk_ar(cfg.prot[i]->ar,&useron))
                    135:                                                break;
                    136:                                if(i<cfg.total_prots) {
                    137:                                        if(!create_batchdn_lst((cfg.prot[i]->misc&PROT_NATIVE) ? true:false))
                    138:                                                break;
                    139:                                        if(!create_batchup_lst())
                    140:                                                break;
                    141:                                        if(!create_bimodem_pth())
                    142:                                                break;
                    143: 
                    144:                                        xfrprot=i;
                    145:                                        action=NODE_BXFR;
                    146:                                        SYNC;
                    147:                                        for(i=0;i<batdn_total;i++)
                    148:                                                if(cfg.dir[batdn_dir[i]]->seqdev) {
                    149:                                                        lncntr=0;
                    150:                                                        unpadfname(batdn_name[i],tmp);
                    151:                                                        sprintf(tmp2,"%s%s",cfg.temp_dir,tmp);
                    152:                                                        if(!fexistcase(tmp2)) {
                    153:                                                                seqwait(cfg.dir[batdn_dir[i]]->seqdev);
                    154:                                                                bprintf(text[RetrievingFile],tmp);
                    155:                                                                sprintf(str,"%s%s"
                    156:                                                                        ,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
                    157:                                                                        ? cfg.altpath[batdn_alt[i]-1]
                    158:                                                                        : cfg.dir[batdn_dir[i]]->path
                    159:                                                                        ,tmp);
                    160:                                                                mv(str,tmp2,1); /* copy the file to temp dir */
                    161:                                                                if(getnodedat(cfg.node_num,&thisnode,true)==0) {
                    162:                                                                        thisnode.aux=0xff;
                    163:                                                                        putnodedat(cfg.node_num,&thisnode);
                    164:                                                                }
                    165:                                                                CRLF; 
                    166:                                                        } 
                    167:                                                }
                    168:                                        sprintf(str,"%sBATCHDN.LST",cfg.node_dir);
                    169:                                        sprintf(tmp2,"%sBATCHUP.LST",cfg.node_dir);
                    170:                                        start=time(NULL);
                    171:                                        protocol(cfg.prot[xfrprot],XFER_BIDIR,str,tmp2,true);
                    172:                                        end=time(NULL);
                    173:                                        for(i=0;i<batdn_total;i++)
                    174:                                                if(cfg.dir[batdn_dir[i]]->seqdev) {
                    175:                                                        unpadfname(batdn_name[i],tmp);
                    176:                                                        sprintf(tmp2,"%s%s",cfg.temp_dir,tmp);
                    177:                                                        remove(tmp2); }
                    178:                                        batch_upload();
                    179:                                        batch_download(xfrprot);
                    180:                                        if(batdn_total)     /* files still in queue, not xfered */
                    181:                                                notdownloaded(totalsize,start,end);
                    182:                                        autohangup(); 
                    183:                                }
                    184:                                break;
                    185:                        case 'C':
                    186:                                if(batup_total) {
                    187:                                        if(!noyes(text[ClearUploadQueueQ])) {
                    188:                                                batup_total=0;
                    189:                                                bputs(text[UploadQueueCleared]); 
                    190:                                        } 
                    191:                                }
                    192:                                if(batdn_total) {
                    193:                                        if(!noyes(text[ClearDownloadQueueQ])) {
                    194:                                                for(i=0;i<batdn_total;i++) {
                    195:                                                        f.dir=batdn_dir[i];
                    196:                                                        f.datoffset=batdn_offset[i];
                    197:                                                        f.size=batdn_size[i];
                    198:                                                        strcpy(f.name,batdn_name[i]);
                    199:                                                        closefile(&f); }
                    200:                                                batdn_total=0;
                    201:                                                bputs(text[DownloadQueueCleared]); 
                    202:                                        } 
                    203:                                }
                    204:                                break;
                    205:                        case 'D':
                    206:                                start_batch_download();
                    207:                                break;
                    208:                        case 'L':
                    209:                                if(batup_total) {
                    210:                                        bputs(text[UploadQueueLstHdr]);
                    211:                                        for(i=0;i<batup_total;i++)
                    212:                                                bprintf(text[UploadQueueLstFmt],i+1,batup_name[i]
                    213:                                                        ,batup_desc[i]); }
                    214:                                if(batdn_total) {
                    215:                                        bputs(text[DownloadQueueLstHdr]);
                    216:                                        for(i=0,totalcdt=0,totalsize=0;i<batdn_total;i++) {
                    217:                                                bprintf(text[DownloadQueueLstFmt],i+1
                    218:                                                        ,batdn_name[i],ultoac(batdn_cdt[i],tmp)
                    219:                                                        ,ultoac(batdn_size[i],str)
                    220:                                                        ,cur_cps
                    221:                                                        ? sectostr(batdn_size[i]/(ulong)cur_cps,tmp2)
                    222:                                                        : "??:??:??");
                    223:                                                totalsize+=batdn_size[i];
                    224:                                                totalcdt+=batdn_cdt[i]; }
                    225:                                        bprintf(text[DownloadQueueTotals]
                    226:                                                ,ultoac(totalcdt,tmp),ultoac(totalsize,str),cur_cps
                    227:                                                ? sectostr(totalsize/(ulong)cur_cps,tmp2)
                    228:                                                : "??:??:??"); }
                    229:                                break;  /* Questionable line ^^^, see note above function */
                    230:                        case 'R':
                    231:                                if(batup_total) {
                    232:                                        bprintf(text[RemoveWhichFromUlQueue],batup_total);
                    233:                                        n=getnum(batup_total);
                    234:                                        if((int)n>=1) {
                    235:                                                n--;
                    236:                                                batup_total--;
                    237:                                                while(n<batup_total) {
                    238:                                                        batup_dir[n]=batup_dir[n+1];
                    239:                                                        batup_misc[n]=batup_misc[n+1];
                    240:                                                        batup_alt[n]=batup_alt[n+1];
                    241:                                                        strcpy(batup_name[n],batup_name[n+1]);
                    242:                                                        strcpy(batup_desc[n],batup_desc[n+1]);
                    243:                                                        n++; }
                    244:                                                if(!batup_total)
                    245:                                                        bputs(text[UploadQueueCleared]); 
                    246:                                        } 
                    247:                                }
                    248:                                if(batdn_total) {
                    249:                                        bprintf(text[RemoveWhichFromDlQueue],batdn_total);
                    250:                                        n=getnum(batdn_total);
                    251:                                        if((int)n>=1) {
                    252:                                                n--;
                    253:                                                f.dir=batdn_dir[n];
                    254:                                                strcpy(f.name,batdn_name[n]);
                    255:                                                f.datoffset=batdn_offset[n];
                    256:                                                f.size=batdn_size[n];
                    257:                                                closefile(&f);
                    258:                                                batdn_total--;
                    259:                                                while(n<batdn_total) {
                    260:                                                        strcpy(batdn_name[n],batdn_name[n+1]);
                    261:                                                        batdn_dir[n]=batdn_dir[n+1];
                    262:                                                        batdn_cdt[n]=batdn_cdt[n+1];
                    263:                                                        batdn_alt[n]=batdn_alt[n+1];
                    264:                                                        batdn_size[n]=batdn_size[n+1];
                    265:                                                        batdn_offset[n]=batdn_offset[n+1];
                    266:                                                        n++; 
                    267:                                                }
                    268:                                                if(!batdn_total)
                    269:                                                        bputs(text[DownloadQueueCleared]); 
                    270:                                        } 
                    271:                                }
                    272:                                break;
                    273:                   case 'U':
                    274:                                if(useron.rest&FLAG('U')) {
                    275:                                        bputs(text[R_Upload]);
                    276:                                        break; 
                    277:                                }
                    278:                                if(!batup_total && cfg.upload_dir==INVALID_DIR) {
                    279:                                        bputs(text[UploadQueueIsEmpty]);
                    280:                                        break; 
                    281:                                }
                    282:                                xfer_prot_menu(XFER_BATCH_UPLOAD);
                    283:                                if(!create_batchup_lst())
                    284:                                        break;
                    285:                                if(!create_bimodem_pth())
                    286:                                        break;
                    287:                                ASYNC;
                    288:                                mnemonics(text[ProtocolOrQuit]);
                    289:                                strcpy(str,"Q");
                    290:                                for(i=0;i<cfg.total_prots;i++)
                    291:                                        if(cfg.prot[i]->batulcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
                    292:                                                sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
                    293:                                                strcat(str,tmp); 
                    294:                                        }
                    295:                                ch=(char)getkeys(str,0);
                    296:                                if(ch=='Q')
                    297:                                        break;
                    298:                                for(i=0;i<cfg.total_prots;i++)
                    299:                                        if(cfg.prot[i]->batulcmd[0] && cfg.prot[i]->mnemonic==ch
                    300:                                                && chk_ar(cfg.prot[i]->ar,&useron))
                    301:                                                break;
                    302:                                if(i<cfg.total_prots) {
                    303:                                        sprintf(str,"%sBATCHUP.LST",cfg.node_dir);
                    304:                                        xfrprot=i;
                    305:                                        if(batup_total)
                    306:                                                xfrdir=batup_dir[0];
                    307:                                        else
                    308:                                                xfrdir=cfg.upload_dir;
                    309:                                        action=NODE_ULNG;
                    310:                                        SYNC;
                    311:                                        if(online==ON_REMOTE) {
                    312:                                                delfiles(cfg.temp_dir,ALLFILES);
                    313:                                                start=time(NULL);
                    314:                                                protocol(cfg.prot[xfrprot],XFER_BATCH_UPLOAD,str,nulstr,true);
                    315:                                                end=time(NULL);
                    316:                                                if(!(cfg.dir[xfrdir]->misc&DIR_ULTIME))
                    317:                                                        starttime+=end-start; 
                    318:                                        }
                    319:                                        batch_upload();
                    320:                                        delfiles(cfg.temp_dir,ALLFILES);
                    321:                                        autohangup(); 
                    322:                                }
                    323:                                break; 
                    324:                } 
                    325:        }
                    326:        delfiles(cfg.temp_dir,ALLFILES);
                    327: }
                    328: 
                    329: /****************************************************************************/
                    330: /* Download files from batch queue                                          */
                    331: /****************************************************************************/
                    332: BOOL sbbs_t::start_batch_download()
                    333: {
                    334:        char    ch;
                    335:        char    tmp[32];
                    336:        char    fname[64];
                    337:        char    str[MAX_PATH+1];
                    338:        char    path[MAX_PATH+1];
                    339:        char*   list;
                    340:        size_t  list_len;
                    341:        int             error;
                    342:     int                j;
                    343:     uint       i,xfrprot;
                    344:     ulong      totalcdt,totalsize,totaltime;
                    345:     time_t     start,end,t;
                    346:        struct  tm tm;
                    347: 
                    348:        if(batdn_total==0) {
                    349:                bputs(text[DownloadQueueIsEmpty]);
                    350:                return(FALSE);
                    351:        }
                    352:        if(useron.rest&FLAG('D')) {     /* Download restriction */
                    353:                bputs(text[R_Download]);
                    354:                return(FALSE); 
                    355:        }
                    356:        for(i=0,totalcdt=0;i<batdn_total;i++)
                    357:                if(is_download_free(&cfg,batdn_dir[i],&useron))
                    358:                        totalcdt+=batdn_cdt[i];
                    359:        if(totalcdt>useron.cdt+useron.freecdt) {
                    360:                bprintf(text[YouOnlyHaveNCredits]
                    361:                        ,ultoac(useron.cdt+useron.freecdt,tmp));
                    362:                return(FALSE); 
                    363:        }
                    364: 
                    365:        for(i=0,totalsize=totaltime=0;i<batdn_total;i++) {
                    366:                totalsize+=batdn_size[i];
                    367:                if(!(cfg.dir[batdn_dir[i]]->misc&DIR_TFREE) && cur_cps)
                    368:                        totaltime+=batdn_size[i]/(ulong)cur_cps; 
                    369:        }
                    370:        if(!(useron.exempt&FLAG('T')) && !SYSOP && totaltime>timeleft) {
                    371:                bputs(text[NotEnoughTimeToDl]);
                    372:                return(FALSE); 
                    373:        }
                    374:        xfer_prot_menu(XFER_BATCH_DOWNLOAD);
                    375:        ASYNC;
                    376:        mnemonics(text[ProtocolOrQuit]);
                    377:        strcpy(str,"Q");
                    378:        for(i=0;i<cfg.total_prots;i++)
                    379:                if(cfg.prot[i]->batdlcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
                    380:                        sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
                    381:                        strcat(str,tmp); 
                    382:                }
                    383:        ungetkey(useron.prot);
                    384:        ch=(char)getkeys(str,0);
                    385:        if(ch=='Q' || sys_status&SS_ABORT)
                    386:                return(FALSE);
                    387:        for(i=0;i<cfg.total_prots;i++)
                    388:                if(cfg.prot[i]->batdlcmd[0] && cfg.prot[i]->mnemonic==ch
                    389:                        && chk_ar(cfg.prot[i]->ar,&useron))
                    390:                        break;
                    391:        if(i>=cfg.total_prots)
                    392:                return(FALSE);  /* no protocol selected */
                    393: 
                    394:        if(!create_batchdn_lst((cfg.prot[i]->misc&PROT_NATIVE) ? true:false))
                    395:                return(FALSE);
                    396:        if(!create_bimodem_pth())
                    397:                return(FALSE);
                    398: 
                    399:        xfrprot=i;
                    400:        list=NULL;
                    401:        for(i=0;i<batdn_total;i++) {
                    402:                curdirnum=batdn_dir[i];                 /* for ARS */
                    403:                unpadfname(batdn_name[i],fname);
                    404:                if(cfg.dir[batdn_dir[i]]->seqdev) {
                    405:                        lncntr=0;
                    406:                        sprintf(path,"%s%s",cfg.temp_dir,fname);
                    407:                        if(!fexistcase(path)) {
                    408:                                seqwait(cfg.dir[batdn_dir[i]]->seqdev);
                    409:                                bprintf(text[RetrievingFile],fname);
                    410:                                sprintf(str,"%s%s"
                    411:                                        ,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
                    412:                                        ? cfg.altpath[batdn_alt[i]-1]
                    413:                                        : cfg.dir[batdn_dir[i]]->path
                    414:                                        ,fname);
                    415:                                mv(str,path,1); /* copy the file to temp dir */
                    416:                                if(getnodedat(cfg.node_num,&thisnode,true)==0) {
                    417:                                        thisnode.aux=40; /* clear the seq dev # */
                    418:                                        putnodedat(cfg.node_num,&thisnode);
                    419:                                }
                    420:                                CRLF; 
                    421:                        } 
                    422:                }
                    423:                else
                    424:                        sprintf(path,"%s%s"
                    425:                                ,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
                    426:                                ? cfg.altpath[batdn_alt[i]-1]
                    427:                                : cfg.dir[batdn_dir[i]]->path
                    428:                                ,fname);
                    429:                if(list==NULL)
                    430:                        list_len=0;
                    431:                else
                    432:                        list_len=strlen(list)+1;        /* add one for ' ' */
                    433:                if((list=(char*)realloc(list,list_len+strlen(path)+1    /* add one for '\0'*/))==NULL) {
                    434:                        errormsg(WHERE,ERR_ALLOC,"list",list_len+strlen(path));
                    435:                        return(FALSE);
                    436:                }
                    437:                if(!list_len)
                    438:                        strcpy(list,path);
                    439:                else {
                    440:                        strcat(list," ");
                    441:                        strcat(list,path);
                    442:                }
                    443:                for(j=0;j<cfg.total_dlevents;j++) {
                    444:                        if(stricmp(cfg.dlevent[j]->ext,batdn_name[i]+9))
                    445:                                continue;
                    446:                        if(!chk_ar(cfg.dlevent[j]->ar,&useron))
                    447:                                continue;
                    448:                        bputs(cfg.dlevent[j]->workstr);
                    449:                        external(cmdstr(cfg.dlevent[j]->cmd,path,nulstr,NULL),EX_OUTL);
                    450:                        CRLF; 
                    451:                }
                    452:        }
                    453: 
                    454:        sprintf(str,"%sBATCHDN.LST",cfg.node_dir);
                    455:        action=NODE_DLNG;
                    456:        t=now;
                    457:        if(cur_cps) 
                    458:                t+=(totalsize/(ulong)cur_cps);
                    459:        localtime_r(&t,&tm);
                    460:        if(getnodedat(cfg.node_num,&thisnode,true)==0) {
                    461:                thisnode.aux=(tm.tm_hour*60)+tm.tm_min;
                    462:                thisnode.action=action;
                    463:                putnodedat(cfg.node_num,&thisnode); /* calculate ETA */
                    464:        }
                    465:        start=time(NULL);
                    466:        error=protocol(cfg.prot[xfrprot],XFER_BATCH_DOWNLOAD,str,list,false);
                    467:        end=time(NULL);
                    468:        if(cfg.prot[xfrprot]->misc&PROT_DSZLOG || !error)
                    469:                batch_download(xfrprot);
                    470:        if(batdn_total)
                    471:                notdownloaded(totalsize,start,end);
                    472:        autohangup(); 
                    473:        if(list!=NULL)
                    474:                free(list);
                    475: 
                    476:        return(TRUE);
                    477: }
                    478: 
                    479: /****************************************************************************/
                    480: /* Creates the file BATCHDN.LST in the node directory. Returns true if      */
                    481: /* everything goes okay, false if not.                                      */
                    482: /****************************************************************************/
                    483: bool sbbs_t::create_batchdn_lst(bool native)
                    484: {
                    485:        char    path[MAX_PATH+1];
                    486:        char    fname[MAX_PATH+1];
                    487:        int             file;
                    488:        uint    i;
                    489: 
                    490:        sprintf(path,"%sBATCHDN.LST",cfg.node_dir);
                    491:        if((file=nopen(path,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
                    492:                errormsg(WHERE,ERR_OPEN,path,O_WRONLY|O_CREAT|O_TRUNC);
                    493:                return(false); 
                    494:        }
                    495:        for(i=0;i<batdn_total;i++) {
                    496:                if(batdn_dir[i]>=cfg.total_dirs || cfg.dir[batdn_dir[i]]->seqdev)
                    497:                        SAFECOPY(path,cfg.temp_dir);
                    498:                else
                    499:                        SAFECOPY(path,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
                    500:                                ? cfg.altpath[batdn_alt[i]-1] : cfg.dir[batdn_dir[i]]->path);
                    501: 
                    502:                unpadfname(batdn_name[i],fname);
                    503:                strcat(path,fname);
                    504:                if(native)
                    505:                        fexistcase(path);
                    506:                strcat(path,crlf);
                    507:                write(file,path,strlen(path)); 
                    508:        }
                    509:        close(file);
                    510:        return(true);
                    511: }
                    512: 
                    513: /****************************************************************************/
                    514: /* Creates the file BATCHUP.LST in the node directory. Returns true if      */
                    515: /* everything goes okay, false if not.                                      */
                    516: /* This list is not used by any protocols to date.                          */
                    517: /****************************************************************************/
                    518: bool sbbs_t::create_batchup_lst()
                    519: {
                    520:     char       str[256];
                    521:     int                file;
                    522:        uint    i;
                    523: 
                    524:        sprintf(str,"%sBATCHUP.LST",cfg.node_dir);
                    525:        if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
                    526:                errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC);
                    527:                return(false); 
                    528:        }
                    529:        for(i=0;i<batup_total;i++) {
                    530:                if(batup_dir[i]>=cfg.total_dirs)
                    531:                        strcpy(str,cfg.temp_dir);
                    532:                else
                    533:                        strcpy(str,batup_alt[i]>0 && batup_alt[i]<=cfg.altpaths
                    534:                                ? cfg.altpath[batup_alt[i]-1] : cfg.dir[batup_dir[i]]->path);
                    535:                write(file,str,strlen(str));
                    536:                unpadfname(batup_name[i],str);
                    537:                strcat(str,crlf);
                    538:                write(file,str,strlen(str)); 
                    539:        }
                    540:        close(file);
                    541:        return(true);
                    542: }
                    543: 
                    544: /****************************************************************************/
                    545: /* Creates the file BIMODEM.PTH in the node directory. Returns true if      */
                    546: /* everything goes okay, false if not.                                      */
                    547: /****************************************************************************/
                    548: bool sbbs_t::create_bimodem_pth()
                    549: {
                    550:     char       str[256],tmp2[512];
                    551:        char    tmp[512];
                    552:     int                file;
                    553:        uint    i;
                    554: 
                    555:        sprintf(str,"%sBIMODEM.PTH",cfg.node_dir);  /* Create bimodem file */
                    556:        if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
                    557:                errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC);
                    558:                return(false); 
                    559:        }
                    560:        for(i=0;i<batup_total;i++) {
                    561:                sprintf(str,"%s%s",batup_dir[i]>=cfg.total_dirs ? cfg.temp_dir
                    562:                        : batup_alt[i]>0 && batup_alt[i]<=cfg.altpaths
                    563:                        ? cfg.altpath[batup_alt[i]-1] : cfg.dir[batup_dir[i]]->path
                    564:                        ,unpadfname(batup_name[i],tmp));
                    565:                sprintf(tmp2,"D       %-80.80s%-160.160s"
                    566:                        ,unpadfname(batup_name[i],tmp),str);
                    567:                write(file,tmp2,248); 
                    568:        }
                    569:        for(i=0;i<batdn_total;i++) {
                    570:                sprintf(str,"%s%s"
                    571:                        ,(batdn_dir[i]>=cfg.total_dirs || cfg.dir[batdn_dir[i]]->seqdev)
                    572:                        ? cfg.temp_dir : batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
                    573:                                ? cfg.altpath[batdn_alt[i]-1] : cfg.dir[batdn_dir[i]]->path
                    574:                                ,unpadfname(batdn_name[i],tmp));
                    575:                sprintf(tmp2,"U       %-240.240s",str);
                    576:                write(file,tmp2,248); 
                    577:        }
                    578:        close(file);
                    579:        return(true);
                    580: }
                    581: 
                    582: /****************************************************************************/
                    583: /* Processes files that were supposed to be received in the batch queue     */
                    584: /****************************************************************************/
                    585: void sbbs_t::batch_upload()
                    586: {
                    587:     char       str1[MAX_PATH+1],str2[MAX_PATH+1];
                    588:        char    path[MAX_PATH+1];
                    589:        char    tmp[MAX_PATH+1];
                    590:        uint    i,j,x,y;
                    591:     file_t     f;
                    592:        DIR*    dir;
                    593:        DIRENT* dirent;
                    594: 
                    595:        for(i=0;i<batup_total;) {
                    596:                curdirnum=batup_dir[i];                         /* for ARS */
                    597:                lncntr=0;                               /* defeat pause */
                    598:                unpadfname(batup_name[i],tmp);
                    599:                sprintf(str1,"%s%s",cfg.temp_dir,tmp);
                    600:                sprintf(str2,"%s%s",cfg.dir[batup_dir[i]]->path,tmp);
                    601:                if(fexistcase(str1) && fexistcase(str2)) { /* file's in two places */
                    602:                        bprintf(text[FileAlreadyThere],batup_name[i]);
                    603:                        remove(str1);    /* this is the one received */
                    604:                        i++;
                    605:                        continue; 
                    606:                }
                    607:                if(fexist(str1))
                    608:                        mv(str1,str2,0);
                    609:                strcpy(f.name,batup_name[i]);
                    610:                strcpy(f.desc,batup_desc[i]);
                    611:                f.dir=batup_dir[i];
                    612:                f.misc=batup_misc[i];
                    613:                f.altpath=batup_alt[i];
                    614:                if(uploadfile(&f)) {
                    615:                        batup_total--;
                    616:                        for(j=i;j<batup_total;j++) {
                    617:                                batup_dir[j]=batup_dir[j+1];
                    618:                                batup_alt[j]=batup_alt[j+1];
                    619:                                batup_misc[j]=batup_misc[j+1];
                    620:                                strcpy(batup_name[j],batup_name[j+1]);
                    621:                                strcpy(batup_desc[j],batup_desc[j+1]); 
                    622:                        } 
                    623:                }
                    624:                else i++; 
                    625:        }
                    626:        if(cfg.upload_dir==INVALID_DIR)
                    627:                return;
                    628:        dir=opendir(cfg.temp_dir);
                    629:        while(dir!=NULL && (dirent=readdir(dir))!=NULL) {
                    630:                sprintf(str1,"%s%s",cfg.temp_dir,dirent->d_name);
                    631:                if(isdir(str1))
                    632:                        continue;
                    633:                memset(&f,0,sizeof(file_t));
                    634:                f.dir=cfg.upload_dir;
                    635: 
                    636:                SAFECOPY(path,str1);
                    637: #ifdef _WIN32
                    638:                GetShortPathName(str1, path, sizeof(path));
                    639: #endif
                    640:                padfname(getfname(path),f.name);
                    641: 
                    642:                for(x=0;x<usrlibs;x++) {
                    643:                        for(y=0;y<usrdirs[x];y++)
                    644:                                if(cfg.dir[usrdir[x][y]]->misc&DIR_DUPES
                    645:                                        && findfile(&cfg,usrdir[x][y],f.name))
                    646:                                        break;
                    647:                        if(y<usrdirs[x])
                    648:                                break; 
                    649:                }
                    650:                sprintf(str2,"%s%s",cfg.dir[f.dir]->path,dirent->d_name);
                    651:                if(x<usrlibs || fexistcase(str2)) {
                    652:                        bprintf(text[FileAlreadyOnline],f.name);
                    653:                        remove(str1); 
                    654:                } else {
                    655:                        mv(str1,str2,0);
                    656:                        uploadfile(&f); 
                    657:                }
                    658:        }
                    659:        if(dir!=NULL)
                    660:                closedir(dir);
                    661: }
                    662: 
                    663: /****************************************************************************/
                    664: /* Processes files that were supposed to be sent from the batch queue       */
                    665: /* xfrprot is -1 if downloading files from within QWK (no DSZLOG)           */
                    666: /****************************************************************************/
                    667: void sbbs_t::batch_download(int xfrprot)
                    668: {
                    669:     uint       i,j;
                    670:     file_t     f;
                    671: 
                    672:        for(i=0;i<batdn_total;) {
                    673:                lncntr=0;                               /* defeat pause */
                    674:                f.dir=curdirnum=batdn_dir[i];
                    675:                strcpy(f.name,batdn_name[i]);
                    676:                f.datoffset=batdn_offset[i];
                    677:                f.size=batdn_size[i];
                    678:                f.altpath=batdn_alt[i];
                    679:                if(xfrprot==-1 || checkprotresult(cfg.prot[xfrprot],0,&f)) {
                    680:                        if(cfg.dir[f.dir]->misc&DIR_TFREE && cur_cps)
                    681:                                starttime+=f.size/(ulong)cur_cps;
                    682:                        downloadfile(&f);
                    683:                        closefile(&f);
                    684:                        batdn_total--;
                    685:                        for(j=i;j<batdn_total;j++) {
                    686:                                strcpy(batdn_name[j],batdn_name[j+1]);
                    687:                                batdn_dir[j]=batdn_dir[j+1];
                    688:                                batdn_cdt[j]=batdn_cdt[j+1];
                    689:                                batdn_alt[j]=batdn_alt[j+1];
                    690:                                batdn_size[j]=batdn_size[j+1];
                    691:                                batdn_offset[j]=batdn_offset[j+1]; 
                    692:                        } 
                    693:                }
                    694:                else i++; 
                    695:        }
                    696: }
                    697: 
                    698: /****************************************************************************/
                    699: /* Adds a list of files to the batch download queue                                            */
                    700: /****************************************************************************/
                    701: void sbbs_t::batch_add_list(char *list)
                    702: {
                    703:     char       str[128];
                    704:        int             file;
                    705:        uint    i,j,k;
                    706:     FILE *     stream;
                    707:        file_t  f;
                    708: 
                    709:        if((stream=fnopen(&file,list,O_RDONLY))!=NULL) {
                    710:                bputs(text[SearchingAllLibs]);
                    711:                while(!feof(stream)) {
                    712:                        checkline();
                    713:                        if(!online)
                    714:                                break;
                    715:                        if(!fgets(str,127,stream))
                    716:                                break;
                    717:                        truncsp(str);
                    718:                        sprintf(f.name,"%.12s",str);
                    719:                        lncntr=0;
                    720:                        for(i=j=k=0;i<usrlibs;i++) {
                    721:                                for(j=0;j<usrdirs[i];j++,k++) {
                    722:                                        outchar('.');
                    723:                                        if(k && !(k%5))
                    724:                                                bputs("\b\b\b\b\b     \b\b\b\b\b");
                    725:                                        if(findfile(&cfg,usrdir[i][j],f.name))
                    726:                                                break; 
                    727:                                }
                    728:                                if(j<usrdirs[i])
                    729:                                        break; 
                    730:                        }
                    731:                        if(i<usrlibs) {
                    732:                                f.dir=usrdir[i][j];
                    733:                                getfileixb(&cfg,&f);
                    734:                                f.size=0;
                    735:                                getfiledat(&cfg,&f);
                    736:                                if(f.size==-1L)
                    737:                                        bprintf(text[FileIsNotOnline],f.name);
                    738:                                else
                    739:                                        addtobatdl(&f); 
                    740:                        } 
                    741:                }
                    742:                fclose(stream);
                    743:                remove(list);
                    744:                CRLF; 
                    745:        }
                    746: }
                    747: /****************************************************************************/
                    748: void sbbs_t::batch_create_list()
                    749: {
                    750:        char    str[MAX_PATH+1];
                    751:        int             i;
                    752:        FILE*   stream;
                    753: 
                    754:        if(batdn_total) {
                    755:                sprintf(str,"%sfile/%04u.dwn",cfg.data_dir,useron.number);
                    756:                if((stream=fnopen(NULL,str,O_WRONLY|O_TRUNC|O_CREAT))!=NULL) {
                    757:                        for(i=0;i<(int)batdn_total;i++)
                    758:                                fprintf(stream,"%s\r\n",batdn_name[i]);
                    759:                        fclose(stream); 
                    760:                } 
                    761:        }
                    762: }
                    763: 
                    764: /**************************************************************************/
                    765: /* Add file 'f' to batch download queue. Return 1 if successful, 0 if not */
                    766: /**************************************************************************/
                    767: bool sbbs_t::addtobatdl(file_t* f)
                    768: {
                    769:     char       str[256],tmp2[256];
                    770:        char    tmp[512];
                    771:     uint       i;
                    772:        ulong   totalcdt, totalsize, totaltime;
                    773: 
                    774:        if(useron.rest&FLAG('D')) {
                    775:                bputs(text[R_Download]);
                    776:                return(false); 
                    777:        }
                    778:        for(i=0;i<batdn_total;i++) {
                    779:                if(!strcmp(batdn_name[i],f->name) && f->dir==batdn_dir[i]) {
                    780:                        bprintf(text[FileAlreadyInQueue],f->name);
                    781:                        return(false); 
                    782:                } 
                    783:        }
                    784:        if(f->size<=0 /* !fexist(str) */) {
                    785:                bprintf(text[CantAddToQueue],f->name);
                    786:                bputs(text[FileIsNotOnline]);
                    787:                return(false); 
                    788:        }
                    789:        if(batdn_total>=cfg.max_batdn) {
                    790:                bprintf(text[CantAddToQueue],f->name);
                    791:                bputs(text[BatchDlQueueIsFull]);
                    792:                return(false); 
                    793:        }
                    794:        for(i=0,totalcdt=0;i<batdn_total;i++)
                    795:                if(!is_download_free(&cfg,batdn_dir[i],&useron))
                    796:                        totalcdt+=batdn_cdt[i];
                    797:        if(cfg.dir[f->dir]->misc&DIR_FREE) f->cdt=0L;
                    798:        if(!is_download_free(&cfg,f->dir,&useron))
                    799:                totalcdt+=f->cdt;
                    800:        if(totalcdt>useron.cdt+useron.freecdt) {
                    801:                bprintf(text[CantAddToQueue],f->name);
                    802:                bprintf(text[YouOnlyHaveNCredits],ultoac(useron.cdt+useron.freecdt,tmp));
                    803:                return(false); 
                    804:        }
                    805:        if(!chk_ar(cfg.dir[f->dir]->dl_ar,&useron)) {
                    806:                bprintf(text[CantAddToQueue],f->name);
                    807:                bputs(text[CantDownloadFromDir]);
                    808:                return(false); 
                    809:        }
                    810:        for(i=0,totalsize=totaltime=0;i<batdn_total;i++) {
                    811:                totalsize+=batdn_size[i];
                    812:                if(!(cfg.dir[batdn_dir[i]]->misc&DIR_TFREE) && cur_cps)
                    813:                        totaltime+=batdn_size[i]/(ulong)cur_cps; 
                    814:        }
                    815:        totalsize+=f->size;
                    816:        if(!(cfg.dir[f->dir]->misc&DIR_TFREE) && cur_cps)
                    817:                totaltime+=f->size/(ulong)cur_cps;
                    818:        if(!(useron.exempt&FLAG('T')) && totaltime>timeleft) {
                    819:                bprintf(text[CantAddToQueue],f->name);
                    820:                bputs(text[NotEnoughTimeToDl]);
                    821:                return(false); 
                    822:        }
                    823:        strcpy(batdn_name[batdn_total],f->name);
                    824:        batdn_dir[batdn_total]=f->dir;
                    825:        batdn_cdt[batdn_total]=f->cdt;
                    826:        batdn_offset[batdn_total]=f->datoffset;
                    827:        batdn_size[batdn_total]=f->size;
                    828:        batdn_alt[batdn_total]=f->altpath;
                    829:        batdn_total++;
                    830:        openfile(f);
                    831:        bprintf(text[FileAddedToBatDlQueue]
                    832:                ,f->name,batdn_total,cfg.max_batdn,ultoac(totalcdt,tmp)
                    833:                ,ultoac(totalsize,tmp2)
                    834:                ,sectostr(totalsize/(ulong)cur_cps,str));
                    835:        return(true);
                    836: }

unix.superglobalmegacorp.com

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