Annotation of sbbs/sbbs3/pack_rep.cpp, revision 1.1.1.1

1.1       root        1: /* pack_rep.cpp */
                      2: 
                      3: /* Synchronet QWK reply (REP) packet creation routine */
                      4: 
                      5: /* $Id: pack_rep.cpp,v 1.8 2000/12/11 23:21:12 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: #include "post.h"
                     40: #include "qwk.h"
                     41: 
                     42: /****************************************************************************/
                     43: /* Creates an REP packet for upload to QWK hub 'hubnum'.                    */
                     44: /* Returns 1 if successful, 0 if not.                                                                          */
                     45: /****************************************************************************/
                     46: bool sbbs_t::pack_rep(uint hubnum)
                     47: {
                     48:        char    str[256],tmp2[256];
                     49:        char    tmp[512];
                     50:        int     file,mode;
                     51:        uint    i,j,k;
                     52:        long    l,msgcnt,submsgs,posts,packedmail,netfiles=0,deleted;
                     53:        ulong   mailmsgs;
                     54:        ulong   last,msgs;
                     55:        post_t  HUGE16 *post;
                     56:        mail_t  *mail;
                     57:        FILE*   rep;
                     58:        DIR*    dir;
                     59:        DIRENT* dirent;
                     60:        smbmsg_t msg;
                     61: 
                     62:        msgcnt=0L;
                     63:        delfiles(cfg.temp_dir,ALLFILES);
                     64:        sprintf(str,"%s%s.rep",cfg.data_dir,cfg.qhub[hubnum]->id);
                     65:        if(fexist(str)) {
                     66:                lprintf("Updating %s", str);
                     67:                external(cmdstr(cfg.qhub[hubnum]->unpack,str,ALLFILES,NULL),EX_OFFLINE);
                     68:        } else
                     69:                lprintf("Creating %s", str);
                     70:        /*************************************************/
                     71:        /* Create SYSID.MSG, write header and leave open */
                     72:        /*************************************************/
                     73:        sprintf(str,"%s%s.msg",cfg.temp_dir,cfg.qhub[hubnum]->id);
                     74:        if((rep=fnopen(&file,str,O_CREAT|O_WRONLY))==NULL) {
                     75:                errormsg(WHERE,ERR_OPEN,str,O_CREAT|O_WRONLY);
                     76:                return(false); }
                     77:        if(filelength(file)<1) {                                                        /* New REP packet */
                     78:                sprintf(str,"%-128s",cfg.qhub[hubnum]->id);     /* So write header */
                     79:                fwrite(str,128,1,rep); }
                     80:        fseek(rep,0L,SEEK_END);
                     81:        /*********************/
                     82:        /* Pack new messages */
                     83:        /*********************/
                     84:        console|=CON_L_ECHO;
                     85: 
                     86:        sprintf(smb.file,"%smail",cfg.data_dir);
                     87:        smb.retry_time=cfg.smb_retry_time;
                     88:        if((i=smb_open(&smb))!=0) {
                     89:                fclose(rep);
                     90:                errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
                     91:                return(false); }
                     92: 
                     93:        /***********************/
                     94:        /* Pack E-mail, if any */
                     95:        /***********************/
                     96:        qwkmail_time=time(NULL);
                     97:        mail=loadmail(&smb,&mailmsgs,0,MAIL_YOUR,0);
                     98:        packedmail=0;
                     99:        if(mailmsgs) {
                    100:                lprintf("Packing NetMail for %s", cfg.qhub[hubnum]->id);
                    101:                for(l=0;(ulong)l<mailmsgs;l++) {
                    102:        //              bprintf("\b\b\b\b\b%-5lu",l+1);
                    103: 
                    104:                        msg.idx.offset=mail[l].offset;
                    105:                        if(!loadmsg(&msg,mail[l].number))
                    106:                                continue;
                    107: 
                    108:                        sprintf(str,"%s/",cfg.qhub[hubnum]->id);
                    109:                        if(msg.to_net.type!=NET_QWK
                    110:                                || (strcmp((char *)msg.to_net.addr,cfg.qhub[hubnum]->id)
                    111:                                && strncmp((char *)msg.to_net.addr,str,strlen(str)))) {
                    112:                                smb_unlockmsghdr(&smb,&msg);
                    113:                                smb_freemsgmem(&msg);
                    114:                                continue; }
                    115: 
                    116:                        msgtoqwk(&msg,rep,TO_QNET|REP|A_LEAVE,INVALID_SUB,0);
                    117:                        packedmail++;
                    118:                        smb_unlockmsghdr(&smb,&msg);
                    119:                        smb_freemsgmem(&msg); }
                    120:                lprintf("Packed %d NetMail messages",packedmail); }
                    121:        smb_close(&smb);                                        /* Close the e-mail */
                    122:        if(mailmsgs)
                    123:                FREE(mail);
                    124: 
                    125:        #if 0
                    126:        useron.number=1;
                    127:        getuserdat(&useron);
                    128:        #endif
                    129:        for(i=0;i<cfg.qhub[hubnum]->subs;i++) {
                    130:                j=cfg.qhub[hubnum]->sub[i];                     /* j now equals the real sub num */
                    131:                msgs=getlastmsg(j,&last,0);
                    132:                lncntr=0;                                               /* defeat pause */
                    133:                if(!msgs || last<=sub_ptr[j]) {
                    134:                        if(sub_ptr[j]>last) {
                    135:                                sub_ptr[j]=last;
                    136:                                sub_last[j]=last; }
                    137:                        lprintf(remove_ctrl_a(text[NScanStatusFmt],tmp)
                    138:                                ,cfg.grp[cfg.sub[j]->grp]->sname
                    139:                                ,cfg.sub[j]->lname,0L,msgs);
                    140:                        continue; }
                    141: 
                    142:                sprintf(smb.file,"%s%s"
                    143:                        ,cfg.sub[j]->data_dir,cfg.sub[j]->code);
                    144:                smb.retry_time=cfg.smb_retry_time;
                    145:                if((k=smb_open(&smb))!=0) {
                    146:                        errormsg(WHERE,ERR_OPEN,smb.file,k,smb.last_error);
                    147:                        continue; }
                    148: 
                    149:                post=loadposts(&posts,j,sub_ptr[j],LP_BYSELF|LP_OTHERS|LP_PRIVATE|LP_REP);
                    150:                lprintf(remove_ctrl_a(text[NScanStatusFmt],tmp)
                    151:                        ,cfg.grp[cfg.sub[j]->grp]->sname
                    152:                        ,cfg.sub[j]->lname,posts,msgs);
                    153:                if(!posts)      { /* no new messages */
                    154:                        smb_close(&smb);
                    155:                        continue; }
                    156: 
                    157:                sub_ptr[j]=last;                   /* set pointer */
                    158:                lputs(remove_ctrl_a(text[QWKPackingSubboard],tmp));     /* ptr to last msg      */
                    159:                submsgs=0;
                    160:                for(l=0;l<posts;l++) {
                    161:        //              bprintf("\b\b\b\b\b%-5lu",l+1);
                    162: 
                    163:                        msg.idx.offset=post[l].offset;
                    164:                        if(!loadmsg(&msg,post[l].number))
                    165:                                continue;
                    166: 
                    167:                        if(msg.from_net.type && msg.from_net.type!=NET_QWK &&
                    168:                                !(cfg.sub[j]->misc&SUB_GATE)) {
                    169:                                smb_freemsgmem(&msg);
                    170:                                smb_unlockmsghdr(&smb,&msg);
                    171:                                continue; }
                    172: 
                    173:                        if(!strnicmp(msg.subj,"NE:",3) || (msg.from_net.type==NET_QWK &&
                    174:                                route_circ((char *)msg.from_net.addr,cfg.qhub[hubnum]->id))) {
                    175:                                smb_freemsgmem(&msg);
                    176:                                smb_unlockmsghdr(&smb,&msg);
                    177:                                continue; }
                    178: 
                    179:                        mode=cfg.qhub[hubnum]->mode[i]|TO_QNET|REP;
                    180:                        if(mode&A_LEAVE) mode|=(VIA|TZ);
                    181:                        if(msg.from_net.type!=NET_QWK)
                    182:                                mode|=TAGLINE;
                    183: 
                    184:                        msgtoqwk(&msg,rep,mode,j,cfg.qhub[hubnum]->conf[i]);
                    185: 
                    186:                        smb_freemsgmem(&msg);
                    187:                        smb_unlockmsghdr(&smb,&msg);
                    188:                        msgcnt++;
                    189:                        submsgs++; }
                    190:                lprintf(remove_ctrl_a(text[QWKPackedSubboard],tmp),submsgs,msgcnt);
                    191:                LFREE(post);
                    192:                smb_close(&smb); }
                    193: 
                    194:        fclose(rep);                    /* close MESSAGE.DAT */
                    195:        CRLF;
                    196:                                                        /* Look for extra files to send out */
                    197:        sprintf(str,"%sqnet/%s.out",cfg.data_dir,cfg.qhub[hubnum]->id);
                    198:        strlwr(str);
                    199:        dir=opendir(str);
                    200:        while((dirent=readdir(dir))!=NULL) {
                    201:                sprintf(str,"%sqnet/%s.out/%s",cfg.data_dir,cfg.qhub[hubnum]->id,dirent->d_name);
                    202:                strlwr(str);
                    203:                if(isdir(str))
                    204:                        continue;
                    205:                sprintf(tmp2,"%s%s",cfg.temp_dir,dirent->d_name);
                    206:                lprintf(remove_ctrl_a(text[RetrievingFile],tmp),str);
                    207:                if(!mv(str,tmp2,1))
                    208:                        netfiles++;
                    209:        }
                    210:        closedir(dir);
                    211:        if(netfiles)
                    212:                CRLF;
                    213: 
                    214:        if(!msgcnt && !netfiles && !packedmail) {
                    215:                lputs(remove_ctrl_a(text[QWKNoNewMessages],tmp));
                    216:                return(false); }
                    217: 
                    218:        /*******************/
                    219:        /* Compress Packet */
                    220:        /*******************/
                    221:        sprintf(str,"%s%s.rep",cfg.data_dir,cfg.qhub[hubnum]->id);
                    222:        sprintf(tmp2,"%s%s",cfg.temp_dir,ALLFILES);
                    223:        i=external(cmdstr(cfg.qhub[hubnum]->pack,str,tmp2,NULL),EX_OFFLINE);
                    224:        if(!fexist(str)) {
                    225:                lputs(remove_ctrl_a(text[QWKCompressionFailed],tmp));
                    226:                if(i)
                    227:                        errormsg(WHERE,ERR_EXEC,cmdstr(cfg.qhub[hubnum]->pack,str,tmp2,NULL),i);
                    228:                else
                    229:                        errorlog("Couldn't compress REP packet");
                    230:                return(false); }
                    231:        sprintf(str,"%sqnet/%s.out/",cfg.data_dir,cfg.qhub[hubnum]->id);
                    232:        strlwr(str);
                    233:        delfiles(str,ALLFILES);
                    234: 
                    235:        if(packedmail) {                                                /* Delete NetMail */
                    236:                sprintf(smb.file,"%smail",cfg.data_dir);
                    237:                smb.retry_time=cfg.smb_retry_time;
                    238:                if((i=smb_open(&smb))!=0) {
                    239:                        errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
                    240:                        return(true); }
                    241: 
                    242:                mail=loadmail(&smb,&mailmsgs,0,MAIL_YOUR,0);
                    243: 
                    244:                if((i=smb_locksmbhdr(&smb))!=0) {                         /* Lock the base, so nobody */
                    245:                        if(mailmsgs)
                    246:                                FREE(mail);
                    247:                        smb_close(&smb);
                    248:                        errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);     /* messes with the index */
                    249:                        return(true); }
                    250: 
                    251:                if((i=smb_getstatus(&smb))!=0) {
                    252:                        if(mailmsgs)
                    253:                                FREE(mail);
                    254:                        smb_close(&smb);
                    255:                        errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
                    256:                        return(true); }
                    257: 
                    258:                deleted=0;
                    259:                /* Mark as READ and DELETE */
                    260:                for(l=0;(ulong)l<mailmsgs;l++) {
                    261:                        if(mail[l].time>qwkmail_time)
                    262:                                continue;
                    263:                        msg.idx.offset=0;
                    264:                        if(!loadmsg(&msg,mail[l].number))
                    265:                                continue;
                    266: 
                    267:                        sprintf(str,"%s/",cfg.qhub[hubnum]->id);
                    268:                        if(msg.to_net.type!=NET_QWK
                    269:                                || (strcmp((char *)msg.to_net.addr,cfg.qhub[hubnum]->id)
                    270:                                && strncmp((char *)msg.to_net.addr,str,strlen(str)))) {
                    271:                                smb_unlockmsghdr(&smb,&msg);
                    272:                                smb_freemsgmem(&msg);
                    273:                                continue; }
                    274: 
                    275:                        msg.hdr.attr|=MSG_DELETE;
                    276:                        msg.idx.attr=msg.hdr.attr;
                    277:                        if((i=smb_putmsg(&smb,&msg))!=0)
                    278:                                errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
                    279:                        else
                    280:                                deleted++;
                    281:                        smb_unlockmsghdr(&smb,&msg);
                    282:                        smb_freemsgmem(&msg); }
                    283: 
                    284:                if(deleted && cfg.sys_misc&SM_DELEMAIL)
                    285:                        delmail(0,MAIL_YOUR);
                    286:                smb_close(&smb);
                    287:                if(mailmsgs)
                    288:                        FREE(mail); }
                    289: 
                    290:        return(true);
                    291: }

unix.superglobalmegacorp.com

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