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

1.1       root        1: /* postmsg.cpp */
                      2: 
                      3: /* Synchronet user create/post public message routine */
                      4: 
1.1.1.2 ! root        5: /* $Id: postmsg.cpp,v 1.63 2004/12/22 10:51:27 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 2004 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: 
1.1.1.2 ! root       40: static char* program_id(char* pid)
        !            41: {
        !            42:        char compiler[64];
        !            43: 
        !            44:        DESCRIBE_COMPILER(compiler);
        !            45:        sprintf(pid,"%.10s %s%c-%s%s%s %s %s"
        !            46:                ,VERSION_NOTICE,VERSION,REVISION,PLATFORM_DESC
        !            47:                ,beta_version
        !            48: #ifdef _DEBUG
        !            49:                ," Debug"
        !            50: #else
        !            51:                ,""
        !            52: #endif
        !            53:                ,__DATE__,compiler);
        !            54:        return(pid);
        !            55: }
        !            56: 
1.1       root       57: /****************************************************************************/
                     58: /* Posts a message on subboard number sub, with 'top' as top of message.    */
                     59: /* Returns 1 if posted, 0 if not.                                           */
                     60: /****************************************************************************/
                     61: bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
                     62: {
                     63:        char    str[256],touser[256],title[LEN_TITLE+1],buf[SDT_BLOCK_LEN]
                     64:                        ,top[256];
1.1.1.2 ! root       65:        char    msg_id[256];
        !            66:        char    pid[128];
1.1       root       67:        ushort  xlat,msgattr;
                     68:        int     i,j,x,file,storage;
1.1.1.2 ! root       69:        ulong   length,offset,crc=0xffffffff;
        !            70:        FILE*   instream;
        !            71:        smbmsg_t msg;
1.1       root       72: 
                     73:        if(remsg) {
                     74:                sprintf(title,"%.*s",LEN_TITLE,remsg->subj);
1.1.1.2 ! root       75: #if 0  /* We *do* support internet posts to specific people July-11-2002 */
1.1       root       76:                if(cfg.sub[subnum]->misc&SUB_INET)      // All Internet posts to "All" 05/20/97
                     77:                        touser[0]=0;
1.1.1.2 ! root       78:                else 
        !            79: #endif
        !            80:                if(remsg->hdr.attr&MSG_ANONYMOUS)
1.1       root       81:                        strcpy(touser,text[Anonymous]);
                     82:                else
                     83:                        strcpy(touser,remsg->from);
                     84:                msgattr=(ushort)(remsg->hdr.attr&MSG_PRIVATE);
                     85:                sprintf(top,text[RegardingByToOn],title,touser,remsg->to
                     86:                        ,timestr((time_t *)&remsg->hdr.when_written.time)
1.1.1.2 ! root       87:                        ,smb_zonestr(remsg->hdr.when_written.zone,NULL)); 
        !            88:        } else {
1.1       root       89:                title[0]=0;
                     90:                touser[0]=0;
                     91:                top[0]=0;
1.1.1.2 ! root       92:                msgattr=0; 
        !            93:        }
1.1       root       94: 
1.1.1.2 ! root       95:        /* Security checks */
        !            96:        if(!chk_ar(cfg.sub[subnum]->post_ar,&useron)) {
        !            97:                bputs(text[CantPostOnSub]);
        !            98:                return(false); 
        !            99:        }
1.1       root      100:        if(useron.rest&FLAG('P')) {
                    101:                bputs(text[R_Post]);
1.1.1.2 ! root      102:                return(false); 
        !           103:        }
1.1       root      104:        if((cfg.sub[subnum]->misc&(SUB_QNET|SUB_FIDO|SUB_PNET|SUB_INET))
                    105:                && (useron.rest&FLAG('N'))) {
                    106:                bputs(text[CantPostOnSub]);
1.1.1.2 ! root      107:                return(false); 
        !           108:        }
1.1       root      109:        if(useron.ptoday>=cfg.level_postsperday[useron.level]) {
                    110:                bputs(text[TooManyPostsToday]);
1.1.1.2 ! root      111:                return(false); 
        !           112:        }
1.1       root      113: 
                    114:        bprintf(text[Posting],cfg.grp[cfg.sub[subnum]->grp]->sname,cfg.sub[subnum]->lname);
                    115:        action=NODE_PMSG;
                    116:        nodesync();
                    117: 
                    118:        if(!(msgattr&MSG_PRIVATE) && (cfg.sub[subnum]->misc&SUB_PONLY
                    119:                || (cfg.sub[subnum]->misc&SUB_PRIV && !noyes(text[PrivatePostQ]))))
                    120:                msgattr|=MSG_PRIVATE;
                    121: 
                    122:        if(sys_status&SS_ABORT)
                    123:                return(false);
                    124: 
1.1.1.2 ! root      125:        if(
        !           126: #if 0  /* we *do* support internet posts to specific people July-11-2002 */
        !           127:                !(cfg.sub[subnum]->misc&SUB_INET) &&    // Prompt for TO: user
        !           128: #endif
        !           129:                (cfg.sub[subnum]->misc&SUB_TOUSER || msgattr&MSG_PRIVATE || touser[0])) {
1.1       root      130:                if(!touser[0] && !(msgattr&MSG_PRIVATE))
                    131:                        strcpy(touser,"All");
                    132:                bputs(text[PostTo]);
                    133:                i=LEN_ALIAS;
                    134:                if(cfg.sub[subnum]->misc&SUB_QNET)
                    135:                        i=25;
1.1.1.2 ! root      136:                if(cfg.sub[subnum]->misc&SUB_FIDO)
        !           137:                        i=FIDO_NAME_LEN-1;
        !           138:                if(cfg.sub[subnum]->misc&(SUB_PNET|SUB_INET))
        !           139:                        i=60;
1.1       root      140:                getstr(touser,i,K_UPRLWR|K_LINE|K_EDIT|K_AUTODEL);
                    141:                if(stricmp(touser,"ALL")
                    142:                && !(cfg.sub[subnum]->misc&(SUB_PNET|SUB_FIDO|SUB_QNET|SUB_INET|SUB_ANON))) {
                    143:                        if(cfg.sub[subnum]->misc&SUB_NAME) {
                    144:                                if(!userdatdupe(useron.number,U_NAME,LEN_NAME,touser,0)) {
                    145:                                        bputs(text[UnknownUser]);
1.1.1.2 ! root      146:                                        return(false); 
        !           147:                                } 
        !           148:                        }
1.1       root      149:                        else {
                    150:                                if((i=finduser(touser))==0)
                    151:                                        return(false);
1.1.1.2 ! root      152:                                username(&cfg,i,touser); 
        !           153:                        } 
        !           154:                }
1.1       root      155:                if(sys_status&SS_ABORT)
1.1.1.2 ! root      156:                        return(false); 
        !           157:        }
1.1       root      158: 
                    159:        if(!touser[0])
                    160:                strcpy(touser,"All");       // Default to ALL
                    161: 
                    162:        if(!stricmp(touser,"SYSOP") && !SYSOP)  // Change SYSOP to user #1
                    163:                username(&cfg,1,touser);
                    164: 
                    165:        if(msgattr&MSG_PRIVATE && !stricmp(touser,"ALL")) {
                    166:                bputs(text[NoToUser]);
1.1.1.2 ! root      167:                return(false); 
        !           168:        }
1.1       root      169:        if(msgattr&MSG_PRIVATE)
                    170:                wm_mode|=WM_PRIVATE;
                    171: 
                    172:        if(cfg.sub[subnum]->misc&SUB_AONLY
                    173:                || (cfg.sub[subnum]->misc&SUB_ANON && useron.exempt&FLAG('A')
                    174:                        && !noyes(text[AnonymousQ])))
                    175:                msgattr|=MSG_ANONYMOUS;
                    176: 
                    177:        if(cfg.sub[subnum]->mod_ar[0] && chk_ar(cfg.sub[subnum]->mod_ar,&useron))
                    178:                msgattr|=MSG_MODERATED;
                    179: 
                    180:        if(cfg.sub[subnum]->misc&SUB_SYSPERM && sub_op(subnum))
                    181:                msgattr|=MSG_PERMANENT;
                    182: 
                    183:        if(msgattr&MSG_PRIVATE)
                    184:                bputs(text[PostingPrivately]);
                    185: 
                    186:        if(msgattr&MSG_ANONYMOUS)
                    187:                bputs(text[PostingAnonymously]);
                    188: 
                    189:        if(cfg.sub[subnum]->misc&SUB_NAME)
                    190:                bputs(text[UsingRealName]);
                    191: 
1.1.1.2 ! root      192:        sprintf(str,"%sinput.msg",cfg.node_dir);
        !           193:        if(!writemsg(str,top,title,wm_mode,subnum,touser)
        !           194:                || (long)(length=flength(str))<1) {     /* Bugfix Aug-20-2003: Reject negative length */
1.1       root      195:                bputs(text[Aborted]);
1.1.1.2 ! root      196:                return(false); 
        !           197:        }
1.1       root      198: 
                    199:        bputs(text[WritingIndx]);
                    200: 
1.1.1.2 ! root      201:        if((i=smb_stack(&smb,SMB_STACK_PUSH))!=SMB_SUCCESS) {
        !           202:                errormsg(WHERE,ERR_OPEN,cfg.sub[subnum]->code,i,smb.last_error);
        !           203:                return(false); 
        !           204:        }
1.1       root      205: 
                    206:        sprintf(smb.file,"%s%s",cfg.sub[subnum]->data_dir,cfg.sub[subnum]->code);
                    207:        smb.retry_time=cfg.smb_retry_time;
1.1.1.2 ! root      208:        smb.subnum=subnum;
        !           209:        if((i=smb_open(&smb))!=SMB_SUCCESS) {
1.1       root      210:                errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
1.1.1.2 ! root      211:                smb_stack(&smb,SMB_STACK_POP);
        !           212:                return(false); 
        !           213:        }
1.1       root      214: 
                    215:        if(filelength(fileno(smb.shd_fp))<1) {   /* Create it if it doesn't exist */
                    216:                smb.status.max_crcs=cfg.sub[subnum]->maxcrcs;
                    217:                smb.status.max_msgs=cfg.sub[subnum]->maxmsgs;
                    218:                smb.status.max_age=cfg.sub[subnum]->maxage;
                    219:                smb.status.attr=cfg.sub[subnum]->misc&SUB_HYPER ? SMB_HYPERALLOC : 0;
1.1.1.2 ! root      220:                if((i=smb_create(&smb))!=SMB_SUCCESS) {
1.1       root      221:                        smb_close(&smb);
                    222:                        errormsg(WHERE,ERR_CREATE,smb.file,i,smb.last_error);
1.1.1.2 ! root      223:                        smb_stack(&smb,SMB_STACK_POP);
        !           224:                        return(false); 
        !           225:                } 
        !           226:        }
1.1       root      227: 
1.1.1.2 ! root      228:        if((i=smb_locksmbhdr(&smb))!=SMB_SUCCESS) {
1.1       root      229:                smb_close(&smb);
                    230:                errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);
1.1.1.2 ! root      231:                smb_stack(&smb,SMB_STACK_POP);
        !           232:                return(false); 
        !           233:        }
1.1       root      234: 
1.1.1.2 ! root      235:        if((i=smb_getstatus(&smb))!=SMB_SUCCESS) {
1.1       root      236:                smb_close(&smb);
                    237:                errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
1.1.1.2 ! root      238:                smb_stack(&smb,SMB_STACK_POP);
        !           239:                return(false); 
        !           240:        }
1.1       root      241: 
1.1.1.2 ! root      242:        length+=sizeof(xlat);    /* +2 for translation string */
1.1       root      243: 
                    244:        if(length&0xfff00000UL) {
                    245:                smb_close(&smb);
1.1.1.2 ! root      246:                errormsg(WHERE,ERR_LEN,str,length,smb.last_error);
1.1       root      247:                smb_stack(&smb,SMB_STACK_POP);
1.1.1.2 ! root      248:                return(false); 
        !           249:        }
1.1       root      250: 
                    251:        if(smb.status.attr&SMB_HYPERALLOC) {
                    252:                offset=smb_hallocdat(&smb);
1.1.1.2 ! root      253:                storage=SMB_HYPERALLOC; 
        !           254:        }
1.1       root      255:        else {
1.1.1.2 ! root      256:                if((i=smb_open_da(&smb))!=SMB_SUCCESS) {
1.1       root      257:                        smb_close(&smb);
                    258:                        errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
1.1.1.2 ! root      259:                        smb_stack(&smb,SMB_STACK_POP);
        !           260:                        return(false); 
        !           261:                }
1.1       root      262:                if(cfg.sub[subnum]->misc&SUB_FAST) {
                    263:                        offset=smb_fallocdat(&smb,length,1);
1.1.1.2 ! root      264:                        storage=SMB_FASTALLOC; 
        !           265:                }
1.1       root      266:                else {
                    267:                        offset=smb_allocdat(&smb,length,1);
1.1.1.2 ! root      268:                        storage=SMB_SELFPACK; 
        !           269:                }
        !           270:                smb_close_da(&smb); 
        !           271:        }
1.1       root      272: 
                    273:        if((file=open(str,O_RDONLY|O_BINARY))==-1
                    274:                || (instream=fdopen(file,"rb"))==NULL) {
                    275:                smb_freemsgdat(&smb,offset,length,1);
                    276:                smb_close(&smb);
                    277:                errormsg(WHERE,ERR_OPEN,str,O_RDONLY|O_BINARY);
1.1.1.2 ! root      278:                smb_stack(&smb,SMB_STACK_POP);
        !           279:                return(false); 
        !           280:        }
1.1       root      281: 
                    282:        setvbuf(instream,NULL,_IOFBF,2*1024);
                    283:        fseek(smb.sdt_fp,offset,SEEK_SET);
                    284:        xlat=XLAT_NONE;
                    285:        fwrite(&xlat,2,1,smb.sdt_fp);
                    286:        x=SDT_BLOCK_LEN-2;                              /* Don't read/write more than 255 */
                    287:        while(!feof(instream)) {
                    288:                memset(buf,0,x);
                    289:                j=fread(buf,1,x,instream);
1.1.1.2 ! root      290:                if(j<1)
        !           291:                        break;
        !           292:                if(j>1 && (j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR)
1.1       root      293:                        buf[j-1]=buf[j-2]=0;    /* Convert to NULL */
                    294:                if(cfg.sub[subnum]->maxcrcs) {
                    295:                        for(i=0;i<j;i++)
1.1.1.2 ! root      296:                                crc=ucrc32(buf[i],crc); 
        !           297:                }
1.1       root      298:                fwrite(buf,j,1,smb.sdt_fp);
1.1.1.2 ! root      299:                x=SDT_BLOCK_LEN; 
        !           300:        }
1.1       root      301:        fflush(smb.sdt_fp);
                    302:        fclose(instream);
                    303:        crc=~crc;
                    304: 
                    305:        memset(&msg,0,sizeof(smbmsg_t));
                    306:        msg.hdr.version=smb_ver();
1.1.1.2 ! root      307:        msg.hdr.attr=msgattr;
1.1       root      308:        msg.hdr.when_written.time=msg.hdr.when_imported.time=time(NULL);
1.1.1.2 ! root      309:        msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone(&cfg);
        !           310: 
        !           311:        /* using the idx records here is not technically necessary, just for convenience */
        !           312:        msg.idx.attr=msg.hdr.attr;
        !           313:        msg.idx.time=msg.hdr.when_imported.time;
        !           314:        msg.idx.number=smb.status.last_msg+1; /* this *should* be the new message number */
        !           315: 
        !           316:        smb_hfield_str(&msg,FIDOPID,program_id(pid));
        !           317: 
        !           318:        /* Generate default (RFC822) message-id (always) */
        !           319:        SAFECOPY(msg_id,get_msgid(&cfg,subnum,&msg));
        !           320:        smb_hfield_str(&msg,RFC822MSGID,msg_id);
        !           321: 
        !           322:        /* Generate FTN (FTS-9) MSGID */
        !           323:        if(cfg.sub[subnum]->misc&SUB_FIDO) {
        !           324:                SAFECOPY(msg_id,ftn_msgid(cfg.sub[subnum],&msg));
        !           325:                smb_hfield_str(&msg,FIDOMSGID,msg_id);
        !           326:        }
1.1       root      327:        if(remsg) {
1.1.1.2 ! root      328: 
        !           329:                msg.hdr.thread_back=remsg->hdr.number;  /* needed for threading backward */
        !           330: 
        !           331:                /* Add RFC-822 Reply-ID (generate if necessary) */
        !           332:                if(remsg->id!=NULL)
        !           333:                        smb_hfield_str(&msg,RFC822REPLYID,remsg->id);
        !           334: 
        !           335:                /* Add FidoNet Reply if original message has FidoNet MSGID */
        !           336:                if(remsg->ftn_msgid!=NULL)
        !           337:                        smb_hfield_str(&msg,FIDOREPLYID,remsg->ftn_msgid);
        !           338: 
        !           339:                if((i=smb_updatethread(&smb, remsg, smb.status.last_msg+1))!=SMB_SUCCESS)
        !           340:                        errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); 
        !           341:        }
1.1       root      342: 
                    343: 
                    344:        if(cfg.sub[subnum]->maxcrcs) {
                    345:                i=smb_addcrc(&smb,crc);
                    346:                if(i) {
                    347:                        smb_freemsgdat(&smb,offset,length,1);
                    348:                        smb_close(&smb);
                    349:                        smb_stack(&smb,SMB_STACK_POP);
1.1.1.2 ! root      350:                        attr(cfg.color[clr_err]);
        !           351:                        bputs("Duplicate message!\r\n");
        !           352:                        return(false); 
        !           353:                } 
        !           354:        }
1.1       root      355: 
                    356:        msg.hdr.offset=offset;
                    357: 
1.1.1.2 ! root      358:        smb_hfield_str(&msg,RECIPIENT,touser);
1.1       root      359:        strlwr(touser);
1.1.1.2 ! root      360:        msg.idx.to=crc16(touser,0);
1.1       root      361: 
                    362:        strcpy(str,cfg.sub[subnum]->misc&SUB_NAME ? useron.name : useron.alias);
1.1.1.2 ! root      363:        smb_hfield_str(&msg,SENDER,str);
1.1       root      364:        strlwr(str);
1.1.1.2 ! root      365:        msg.idx.from=crc16(str,0);
1.1       root      366: 
                    367:        sprintf(str,"%u",useron.number);
1.1.1.2 ! root      368:        smb_hfield_str(&msg,SENDEREXT,str);
1.1       root      369: 
1.1.1.2 ! root      370:        /* Security logging */
        !           371:        msg_client_hfields(&msg,&client);
        !           372: 
        !           373:        smb_hfield_str(&msg,SUBJECT,title);
        !           374:        msg.idx.subj=smb_subject_crc(title);
1.1       root      375: 
                    376:        smb_dfield(&msg,TEXT_BODY,length);
                    377: 
1.1.1.2 ! root      378:        i=smb_addmsghdr(&smb,&msg,storage);     // calls smb_unlocksmbhdr() 
1.1       root      379:        smb_close(&smb);
                    380:        smb_stack(&smb,SMB_STACK_POP);
                    381: 
                    382:        smb_freemsgmem(&msg);
1.1.1.2 ! root      383:        if(i!=SMB_SUCCESS) {
        !           384:                errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
1.1       root      385:                smb_freemsgdat(&smb,offset,length,1);
1.1.1.2 ! root      386:                return(false); 
        !           387:        }
1.1       root      388: 
                    389:        useron.ptoday++;
                    390:        useron.posts++;
                    391:        logon_posts++;
                    392:        putuserrec(&cfg,useron.number,U_POSTS,5,ultoa(useron.posts,str,10));
                    393:        putuserrec(&cfg,useron.number,U_PTODAY,5,ultoa(useron.ptoday,str,10));
                    394:        bprintf(text[Posted],cfg.grp[cfg.sub[subnum]->grp]->sname
                    395:                ,cfg.sub[subnum]->lname);
1.1.1.2 ! root      396:        sprintf(str,"%s posted on %s %s"
        !           397:                ,useron.alias,cfg.grp[cfg.sub[subnum]->grp]->sname,cfg.sub[subnum]->lname);
1.1       root      398:        logline("P+",str);
1.1.1.2 ! root      399: 
        !           400:        signal_sub_sem(&cfg,subnum);
        !           401: 
        !           402:        user_event(EVENT_POST);
        !           403: 
1.1       root      404:        return(true);
                    405: }
1.1.1.2 ! root      406: 
        !           407: extern "C" void DLLCALL signal_sub_sem(scfg_t* cfg, uint subnum)
        !           408: {
        !           409:        char str[MAX_PATH+1];
        !           410: 
        !           411:        if(subnum==INVALID_SUB || subnum>=cfg->total_subs)      /* e-mail? */
        !           412:                return;
        !           413: 
        !           414:        /* signal semaphore files */
        !           415:        if(cfg->sub[subnum]->misc&SUB_FIDO && cfg->echomail_sem[0])             
        !           416:                ftouch(cmdstr(cfg,NULL,cfg->echomail_sem,nulstr,nulstr,str));
        !           417:        if(cfg->sub[subnum]->post_sem[0]) 
        !           418:                ftouch(cmdstr(cfg,NULL,cfg->sub[subnum]->post_sem,nulstr,nulstr,str));
        !           419: }
        !           420: 
        !           421: extern "C" int DLLCALL msg_client_hfields(smbmsg_t* msg, client_t* client)
        !           422: {
        !           423:        int i;
        !           424: 
        !           425:        if(client==NULL)
        !           426:                return(-1);
        !           427: 
        !           428:        if((i=smb_hfield_str(msg,SENDERIPADDR,client->addr))!=SMB_SUCCESS)
        !           429:                return(i);
        !           430:        if((i=smb_hfield_str(msg,SENDERHOSTNAME,client->host))!=SMB_SUCCESS)
        !           431:                return(i);
        !           432:        if((i=smb_hfield_str(msg,SENDERPROTOCOL,client->protocol))!=SMB_SUCCESS)
        !           433:                return(i);
        !           434:        return smb_hfield(msg,SENDERPORT,sizeof(client->port),&client->port);
        !           435: }
        !           436: 
        !           437: extern "C" int DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, client_t* client, char* msgbuf)
        !           438: {
        !           439:        char    pid[128];
        !           440:        char    msg_id[256];
        !           441:        ushort  xlat=XLAT_NONE;
        !           442:        int     i;
        !           443:        int             storage=SMB_SELFPACK;
        !           444:        long    dupechk_hashes=SMB_HASH_SOURCE_ALL;
        !           445: 
        !           446:        if(msg==NULL)
        !           447:                return(SMB_FAILURE);
        !           448: 
        !           449:        if(!SMB_IS_OPEN(smb)) {
        !           450:                if(smb->subnum==INVALID_SUB)
        !           451:                        sprintf(smb->file,"%smail",cfg->data_dir);
        !           452:                else
        !           453:                        sprintf(smb->file,"%s%s",cfg->sub[smb->subnum]->data_dir,cfg->sub[smb->subnum]->code);
        !           454:                smb->retry_time=cfg->smb_retry_time;
        !           455:                if((i=smb_open(smb))!=SMB_SUCCESS)
        !           456:                        return(i);
        !           457:        }
        !           458: 
        !           459:        /* Lock the msgbase early to preserve our message number (used in MSG-IDs) */
        !           460:        if(!smb->locked && smb_locksmbhdr(smb)!=SMB_SUCCESS)
        !           461:                return(SMB_ERR_LOCK);
        !           462: 
        !           463:        if(filelength(fileno(smb->shd_fp))>0 && (i=smb_getstatus(smb))!=SMB_SUCCESS) {
        !           464:                if(smb->locked)
        !           465:                        smb_unlocksmbhdr(smb);
        !           466:                return(i);
        !           467:        }
        !           468: 
        !           469:        if(smb->subnum==INVALID_SUB) {  /* e-mail */
        !           470: 
        !           471:                smb->status.max_crcs=cfg->mail_maxcrcs;
        !           472:                smb->status.max_age=cfg->mail_maxage;
        !           473:                smb->status.max_msgs=0; /* unlimited */
        !           474:                smb->status.attr=SMB_EMAIL;
        !           475: 
        !           476:                if(cfg->sys_misc&SM_FASTMAIL)
        !           477:                        storage=SMB_FASTALLOC;
        !           478: 
        !           479:                /* duplicate message-IDs must be allowed in mail database */
        !           480:                dupechk_hashes&=~(1<<SMB_HASH_SOURCE_MSG_ID);
        !           481: 
        !           482:        } else {        /* sub-board */
        !           483: 
        !           484:                smb->status.max_crcs=cfg->sub[smb->subnum]->maxcrcs;
        !           485:                smb->status.max_msgs=cfg->sub[smb->subnum]->maxmsgs;
        !           486:                smb->status.max_age=cfg->sub[smb->subnum]->maxage;
        !           487:                smb->status.attr=0;
        !           488: 
        !           489:                if(cfg->sub[smb->subnum]->misc&SUB_HYPER)
        !           490:                        storage = smb->status.attr = SMB_HYPERALLOC;
        !           491:                else if(cfg->sub[smb->subnum]->misc&SUB_FAST)
        !           492:                        storage = SMB_FASTALLOC;
        !           493: 
        !           494:                if(cfg->sub[smb->subnum]->misc&SUB_LZH)
        !           495:                        xlat=XLAT_LZH;
        !           496: 
        !           497:                /* enforce anonymous/private posts only */
        !           498:                if(cfg->sub[smb->subnum]->misc&SUB_PONLY)
        !           499:                        msg->hdr.attr|=MSG_PRIVATE;
        !           500:                if(cfg->sub[smb->subnum]->misc&SUB_AONLY)
        !           501:                        msg->hdr.attr|=MSG_ANONYMOUS;
        !           502:        }
        !           503: 
        !           504:        if(msg->hdr.when_imported.time==0) {
        !           505:                msg->hdr.when_imported.time=time(NULL);
        !           506:                msg->hdr.when_imported.zone=sys_timezone(cfg);
        !           507:        }
        !           508:        if(msg->hdr.when_written.time==0)       /* Uninitialized */
        !           509:                msg->hdr.when_written = msg->hdr.when_imported;
        !           510: 
        !           511:        msg->idx.time=msg->hdr.when_imported.time;      /* needed for MSG-ID generation */
        !           512:        msg->idx.number=smb->status.last_msg+1;         /* needed for MSG-ID generation */
        !           513: 
        !           514:        if(smb->status.max_crcs==0)     /* no CRC checking means no body text dupe checking */
        !           515:                dupechk_hashes&=~(1<<SMB_HASH_SOURCE_BODY);
        !           516: 
        !           517:        if(client!=NULL)
        !           518:                msg_client_hfields(msg,client);
        !           519:  
        !           520:        /* Generate FidoNet Program Identifier */
        !           521:        if(msg->ftn_pid==NULL)  
        !           522:                smb_hfield_str(msg,FIDOPID,program_id(pid));
        !           523:  
        !           524:        /* Generate RFC-822 Message-id  */
        !           525:        if(msg->id==NULL) {
        !           526:                SAFECOPY(msg_id,get_msgid(cfg,smb->subnum,msg));
        !           527:                smb_hfield_str(msg,RFC822MSGID,msg_id);
        !           528:        }
        !           529:  
        !           530:        /* Generate FidoNet MSGID (for FidoNet sub-boards) */
        !           531:        if(smb->subnum!=INVALID_SUB && cfg->sub[smb->subnum]->misc&SUB_FIDO 
        !           532:                && msg->ftn_msgid==NULL) {
        !           533:                SAFECOPY(msg_id,ftn_msgid(cfg->sub[smb->subnum],msg));
        !           534:                smb_hfield_str(msg,FIDOMSGID,msg_id);
        !           535:        }
        !           536: 
        !           537:        if((i=smb_addmsg(smb,msg,storage,dupechk_hashes,xlat,(uchar*)msgbuf,NULL))==SMB_SUCCESS)
        !           538:                signal_sub_sem(cfg,smb->subnum);
        !           539: 
        !           540:        return(i);
        !           541: }
        !           542: 

unix.superglobalmegacorp.com

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