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

1.1       root        1: /* pack_rep.cpp */
                      2: 
                      3: /* Synchronet QWK reply (REP) packet creation routine */
                      4: 
1.1.1.2 ! root        5: /* $Id: pack_rep.cpp,v 1.29 2004/01/10 11:07:36 rswindell Exp $ */
1.1       root        6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       12:  *                                                                                                                                                     *
                     13:  * This program is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU General Public License                         *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU General Public License for more details: gpl.txt or                     *
                     18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: #include "sbbs.h"
                     39: #include "qwk.h"
                     40: 
                     41: /****************************************************************************/
                     42: /* Creates an REP packet for upload to QWK hub 'hubnum'.                    */
                     43: /* Returns 1 if successful, 0 if not.                                                                          */
                     44: /****************************************************************************/
                     45: bool sbbs_t::pack_rep(uint hubnum)
                     46: {
1.1.1.2 ! root       47:        char    str[MAX_PATH+1];
        !            48:        char    tmp[MAX_PATH+1],tmp2[MAX_PATH+1];
1.1       root       49:        int     file,mode;
                     50:        uint    i,j,k;
                     51:        long    l,msgcnt,submsgs,posts,packedmail,netfiles=0,deleted;
                     52:        ulong   mailmsgs;
                     53:        ulong   last,msgs;
                     54:        post_t  HUGE16 *post;
                     55:        mail_t  *mail;
                     56:        FILE*   rep;
                     57:        DIR*    dir;
                     58:        DIRENT* dirent;
                     59:        smbmsg_t msg;
                     60: 
                     61:        msgcnt=0L;
                     62:        delfiles(cfg.temp_dir,ALLFILES);
                     63:        sprintf(str,"%s%s.rep",cfg.data_dir,cfg.qhub[hubnum]->id);
                     64:        if(fexist(str)) {
1.1.1.2 ! root       65:                eprintf(LOG_INFO,"Updating %s", str);
1.1       root       66:                external(cmdstr(cfg.qhub[hubnum]->unpack,str,ALLFILES,NULL),EX_OFFLINE);
                     67:        } else
1.1.1.2 ! root       68:                eprintf(LOG_INFO,"Creating %s", str);
1.1       root       69:        /*************************************************/
                     70:        /* Create SYSID.MSG, write header and leave open */
                     71:        /*************************************************/
                     72:        sprintf(str,"%s%s.msg",cfg.temp_dir,cfg.qhub[hubnum]->id);
1.1.1.2 ! root       73:        if((rep=fnopen(&file,str,O_CREAT|O_WRONLY|O_TRUNC))==NULL) {
        !            74:                errormsg(WHERE,ERR_CREATE,str,O_CREAT|O_WRONLY|O_TRUNC);
1.1       root       75:                return(false); }
                     76:        if(filelength(file)<1) {                                                        /* New REP packet */
1.1.1.2 ! root       77:                sprintf(str,"%-*s"
        !            78:                        ,QWK_BLOCK_LEN,cfg.qhub[hubnum]->id);           /* So write header */
        !            79:                fwrite(str,QWK_BLOCK_LEN,1,rep); 
        !            80:        }
1.1       root       81:        fseek(rep,0L,SEEK_END);
                     82:        /*********************/
                     83:        /* Pack new messages */
                     84:        /*********************/
                     85:        sprintf(smb.file,"%smail",cfg.data_dir);
                     86:        smb.retry_time=cfg.smb_retry_time;
1.1.1.2 ! root       87:        smb.subnum=INVALID_SUB;
1.1       root       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:        /***********************/
1.1.1.2 ! root       96:        qwkmail_last=0;
1.1       root       97:        mail=loadmail(&smb,&mailmsgs,0,MAIL_YOUR,0);
                     98:        packedmail=0;
                     99:        if(mailmsgs) {
1.1.1.2 ! root      100:                eprintf(LOG_INFO,"Packing NetMail for %s", cfg.qhub[hubnum]->id);
1.1       root      101:                for(l=0;(ulong)l<mailmsgs;l++) {
                    102:        //              bprintf("\b\b\b\b\b%-5lu",l+1);
                    103: 
1.1.1.2 ! root      104:                        memset(&msg,0,sizeof(msg));
        !           105:                        msg.idx=mail[l];
        !           106:                        if(msg.idx.number>qwkmail_last)
        !           107:                                qwkmail_last=msg.idx.number;
1.1       root      108:                        if(!loadmsg(&msg,mail[l].number))
                    109:                                continue;
                    110: 
                    111:                        sprintf(str,"%s/",cfg.qhub[hubnum]->id);
                    112:                        if(msg.to_net.type!=NET_QWK
                    113:                                || (strcmp((char *)msg.to_net.addr,cfg.qhub[hubnum]->id)
                    114:                                && strncmp((char *)msg.to_net.addr,str,strlen(str)))) {
                    115:                                smb_unlockmsghdr(&smb,&msg);
                    116:                                smb_freemsgmem(&msg);
                    117:                                continue; }
                    118: 
1.1.1.2 ! root      119:                        msgtoqwk(&msg,rep,QM_TO_QNET|QM_REP|A_LEAVE,INVALID_SUB,0);
1.1       root      120:                        packedmail++;
                    121:                        smb_unlockmsghdr(&smb,&msg);
1.1.1.2 ! root      122:                        smb_freemsgmem(&msg); 
        !           123:                        YIELD();        /* yield */
        !           124:                }
        !           125:                eprintf(LOG_INFO,"Packed %d NetMail messages",packedmail); 
        !           126:        }
1.1       root      127:        smb_close(&smb);                                        /* Close the e-mail */
                    128:        if(mailmsgs)
                    129:                FREE(mail);
                    130: 
                    131:        for(i=0;i<cfg.qhub[hubnum]->subs;i++) {
                    132:                j=cfg.qhub[hubnum]->sub[i];                     /* j now equals the real sub num */
                    133:                msgs=getlastmsg(j,&last,0);
                    134:                lncntr=0;                                               /* defeat pause */
1.1.1.2 ! root      135:                if(!msgs || last<=subscan[j].ptr) {
        !           136:                        if(subscan[j].ptr>last) {
        !           137:                                subscan[j].ptr=last;
        !           138:                                subscan[j].ptr=last; }
        !           139:                        eprintf(LOG_INFO,remove_ctrl_a(text[NScanStatusFmt],tmp)
1.1       root      140:                                ,cfg.grp[cfg.sub[j]->grp]->sname
                    141:                                ,cfg.sub[j]->lname,0L,msgs);
                    142:                        continue; }
                    143: 
                    144:                sprintf(smb.file,"%s%s"
                    145:                        ,cfg.sub[j]->data_dir,cfg.sub[j]->code);
                    146:                smb.retry_time=cfg.smb_retry_time;
1.1.1.2 ! root      147:                smb.subnum=j;
1.1       root      148:                if((k=smb_open(&smb))!=0) {
                    149:                        errormsg(WHERE,ERR_OPEN,smb.file,k,smb.last_error);
                    150:                        continue; }
                    151: 
1.1.1.2 ! root      152:                post=loadposts(&posts,j,subscan[j].ptr,LP_BYSELF|LP_OTHERS|LP_PRIVATE|LP_REP);
        !           153:                eprintf(LOG_INFO,remove_ctrl_a(text[NScanStatusFmt],tmp)
1.1       root      154:                        ,cfg.grp[cfg.sub[j]->grp]->sname
                    155:                        ,cfg.sub[j]->lname,posts,msgs);
                    156:                if(!posts)      { /* no new messages */
                    157:                        smb_close(&smb);
                    158:                        continue; }
                    159: 
1.1.1.2 ! root      160:                subscan[j].ptr=last;                   /* set pointer */
        !           161:                eprintf(LOG_INFO,"%s",remove_ctrl_a(text[QWKPackingSubboard],tmp));     /* ptr to last msg      */
1.1       root      162:                submsgs=0;
                    163:                for(l=0;l<posts;l++) {
                    164:        //              bprintf("\b\b\b\b\b%-5lu",l+1);
                    165: 
1.1.1.2 ! root      166:                        memset(&msg,0,sizeof(msg));
        !           167:                        msg.idx=post[l];
1.1       root      168:                        if(!loadmsg(&msg,post[l].number))
                    169:                                continue;
                    170: 
                    171:                        if(msg.from_net.type && msg.from_net.type!=NET_QWK &&
                    172:                                !(cfg.sub[j]->misc&SUB_GATE)) {
                    173:                                smb_freemsgmem(&msg);
                    174:                                smb_unlockmsghdr(&smb,&msg);
                    175:                                continue; }
                    176: 
                    177:                        if(!strnicmp(msg.subj,"NE:",3) || (msg.from_net.type==NET_QWK &&
                    178:                                route_circ((char *)msg.from_net.addr,cfg.qhub[hubnum]->id))) {
                    179:                                smb_freemsgmem(&msg);
                    180:                                smb_unlockmsghdr(&smb,&msg);
                    181:                                continue; }
                    182: 
1.1.1.2 ! root      183:                        mode=cfg.qhub[hubnum]->mode[i]|QM_TO_QNET|QM_REP;
        !           184:                        if(mode&A_LEAVE) mode|=(QM_VIA|QM_TZ|QM_MSGID);
1.1       root      185:                        if(msg.from_net.type!=NET_QWK)
1.1.1.2 ! root      186:                                mode|=QM_TAGLINE;
1.1       root      187: 
                    188:                        msgtoqwk(&msg,rep,mode,j,cfg.qhub[hubnum]->conf[i]);
                    189: 
                    190:                        smb_freemsgmem(&msg);
                    191:                        smb_unlockmsghdr(&smb,&msg);
                    192:                        msgcnt++;
1.1.1.2 ! root      193:                        submsgs++; 
        !           194:                        if(!(l%50))
        !           195:                                YIELD(); /* yield */
        !           196:                }
        !           197:                eprintf(LOG_INFO,remove_ctrl_a(text[QWKPackedSubboard],tmp),submsgs,msgcnt);
1.1       root      198:                LFREE(post);
1.1.1.2 ! root      199:                smb_close(&smb); 
        !           200:                YIELD();        /* yield */
        !           201:        }
1.1       root      202: 
1.1.1.2 ! root      203:        fclose(rep);                    /* close HUB_ID.MSG */
1.1       root      204:        CRLF;
                    205:                                                        /* Look for extra files to send out */
                    206:        sprintf(str,"%sqnet/%s.out",cfg.data_dir,cfg.qhub[hubnum]->id);
                    207:        strlwr(str);
                    208:        dir=opendir(str);
1.1.1.2 ! root      209:        while(dir!=NULL && (dirent=readdir(dir))!=NULL) {
1.1       root      210:                sprintf(str,"%sqnet/%s.out/%s",cfg.data_dir,cfg.qhub[hubnum]->id,dirent->d_name);
                    211:                strlwr(str);
                    212:                if(isdir(str))
                    213:                        continue;
                    214:                sprintf(tmp2,"%s%s",cfg.temp_dir,dirent->d_name);
1.1.1.2 ! root      215:                eprintf(LOG_INFO,remove_ctrl_a(text[RetrievingFile],tmp),str);
1.1       root      216:                if(!mv(str,tmp2,1))
                    217:                        netfiles++;
                    218:        }
1.1.1.2 ! root      219:        if(dir!=NULL)
        !           220:                closedir(dir);
1.1       root      221:        if(netfiles)
                    222:                CRLF;
                    223: 
                    224:        if(!msgcnt && !netfiles && !packedmail) {
1.1.1.2 ! root      225:                eprintf(LOG_INFO,remove_ctrl_a(text[QWKNoNewMessages],tmp));
        !           226:                return(false); 
        !           227:        }
1.1       root      228: 
                    229:        /*******************/
                    230:        /* Compress Packet */
                    231:        /*******************/
                    232:        sprintf(str,"%s%s.rep",cfg.data_dir,cfg.qhub[hubnum]->id);
                    233:        sprintf(tmp2,"%s%s",cfg.temp_dir,ALLFILES);
1.1.1.2 ! root      234:        i=external(cmdstr(cfg.qhub[hubnum]->pack,str,tmp2,NULL)
        !           235:                ,EX_OFFLINE|EX_WILDCARD);
1.1       root      236:        if(!fexist(str)) {
1.1.1.2 ! root      237:                eprintf(LOG_WARNING,"%s",remove_ctrl_a(text[QWKCompressionFailed],tmp));
1.1       root      238:                if(i)
                    239:                        errormsg(WHERE,ERR_EXEC,cmdstr(cfg.qhub[hubnum]->pack,str,tmp2,NULL),i);
                    240:                else
                    241:                        errorlog("Couldn't compress REP packet");
                    242:                return(false); }
                    243:        sprintf(str,"%sqnet/%s.out/",cfg.data_dir,cfg.qhub[hubnum]->id);
                    244:        strlwr(str);
                    245:        delfiles(str,ALLFILES);
                    246: 
                    247:        if(packedmail) {                                                /* Delete NetMail */
                    248:                sprintf(smb.file,"%smail",cfg.data_dir);
                    249:                smb.retry_time=cfg.smb_retry_time;
1.1.1.2 ! root      250:                smb.subnum=INVALID_SUB;
1.1       root      251:                if((i=smb_open(&smb))!=0) {
                    252:                        errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
                    253:                        return(true); }
                    254: 
                    255:                mail=loadmail(&smb,&mailmsgs,0,MAIL_YOUR,0);
                    256: 
                    257:                if((i=smb_locksmbhdr(&smb))!=0) {                         /* Lock the base, so nobody */
                    258:                        if(mailmsgs)
                    259:                                FREE(mail);
                    260:                        smb_close(&smb);
                    261:                        errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);     /* messes with the index */
                    262:                        return(true); }
                    263: 
                    264:                if((i=smb_getstatus(&smb))!=0) {
                    265:                        if(mailmsgs)
                    266:                                FREE(mail);
                    267:                        smb_close(&smb);
                    268:                        errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
                    269:                        return(true); }
                    270: 
                    271:                deleted=0;
                    272:                /* Mark as READ and DELETE */
                    273:                for(l=0;(ulong)l<mailmsgs;l++) {
1.1.1.2 ! root      274:                        if(mail[l].number>qwkmail_last)
1.1       root      275:                                continue;
1.1.1.2 ! root      276:                        memset(&msg,0,sizeof(msg));
        !           277:                        /* !IMPORTANT: search by number (do not initialize msg.idx.offset) */
1.1       root      278:                        if(!loadmsg(&msg,mail[l].number))
                    279:                                continue;
                    280: 
                    281:                        sprintf(str,"%s/",cfg.qhub[hubnum]->id);
                    282:                        if(msg.to_net.type!=NET_QWK
                    283:                                || (strcmp((char *)msg.to_net.addr,cfg.qhub[hubnum]->id)
                    284:                                && strncmp((char *)msg.to_net.addr,str,strlen(str)))) {
                    285:                                smb_unlockmsghdr(&smb,&msg);
                    286:                                smb_freemsgmem(&msg);
                    287:                                continue; }
                    288: 
                    289:                        msg.hdr.attr|=MSG_DELETE;
                    290:                        msg.idx.attr=msg.hdr.attr;
                    291:                        if((i=smb_putmsg(&smb,&msg))!=0)
                    292:                                errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
                    293:                        else
                    294:                                deleted++;
                    295:                        smb_unlockmsghdr(&smb,&msg);
1.1.1.2 ! root      296:                        smb_freemsgmem(&msg); 
        !           297:                }
1.1       root      298: 
                    299:                if(deleted && cfg.sys_misc&SM_DELEMAIL)
                    300:                        delmail(0,MAIL_YOUR);
                    301:                smb_close(&smb);
                    302:                if(mailmsgs)
1.1.1.2 ! root      303:                        FREE(mail); 
        !           304:                eprintf(LOG_INFO,"Deleted %d sent NetMail messages",deleted); 
        !           305:        }
1.1       root      306: 
                    307:        return(true);
                    308: }

unix.superglobalmegacorp.com

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