Annotation of sbbs/sbbs3/bat_xfer.cpp, revision 1.1

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