Annotation of sbbs/sbbs2/postmsg.c, revision 1.1.1.2

1.1       root        1: #line 1 "POSTMSG.C"
                      2: 
                      3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
                      4: 
                      5: #include "sbbs.h"
                      6: 
                      7: /****************************************************************************/
                      8: /* Posts a message on subboard number sub, with 'top' as top of message.    */
                      9: /* Returns 1 if posted, 0 if not.                                           */
                     10: /****************************************************************************/
                     11: char postmsg(uint subnum, smbmsg_t *remsg, int wm_mode)
                     12: {
                     13:        char    str[256],touser[256],title[LEN_TITLE+1],buf[SDT_BLOCK_LEN]
                     14:                        ,top[256],c;
                     15:        ushort  xlat,msgattr;
                     16:        int     i,j,n,x,file,storage;
                     17:        ulong   l,length,offset,crc=0xffffffff;
                     18:        FILE    *instream;
                     19:        smbmsg_t msg,tmpmsg;
                     20: 
                     21: if(remsg) {
                     22:        sprintf(title,"%.*s",LEN_TITLE,remsg->subj);
                     23:        if(sub[subnum]->misc&SUB_INET)  // All Internet posts to "All" 05/20/97
                     24:                touser[0]=0;
                     25:        else if(remsg->hdr.attr&MSG_ANONYMOUS)
                     26:                strcpy(touser,text[Anonymous]);
                     27:        else
                     28:                strcpy(touser,remsg->from);
                     29:        msgattr=(remsg->hdr.attr&MSG_PRIVATE);
                     30:        sprintf(top,text[RegardingByTo],title,touser,remsg->to
                     31:                ,timestr((time_t *)&remsg->hdr.when_written.time)
                     32:                ,zonestr(remsg->hdr.when_written.zone)); }
                     33: else {
                     34:        title[0]=0;
                     35:        touser[0]=0;
                     36:        top[0]=0;
                     37:        msgattr=0; }
                     38: 
                     39: if(useron.rest&FLAG('P')) {
                     40:     bputs(text[R_Post]);
                     41:     return(0); }
                     42: 
                     43: if((sub[subnum]->misc&(SUB_QNET|SUB_FIDO|SUB_PNET|SUB_INET))
                     44:        && (useron.rest&FLAG('N'))) {
                     45:     bputs(text[CantPostOnSub]);
                     46:     return(0); }
                     47: 
                     48: if(useron.ptoday>=level_postsperday[useron.level]) {
                     49:        bputs(text[TooManyPostsToday]);
                     50:        return(0); }
                     51: 
                     52: bprintf(text[Posting],grp[sub[subnum]->grp]->sname,sub[subnum]->lname);
                     53: action=NODE_PMSG;
                     54: nodesync();
                     55: 
                     56: if(!(msgattr&MSG_PRIVATE) && (sub[subnum]->misc&SUB_PONLY
                     57:        || (sub[subnum]->misc&SUB_PRIV && !noyes(text[PrivatePostQ]))))
                     58:        msgattr|=MSG_PRIVATE;
                     59: 
                     60: if(sys_status&SS_ABORT)
                     61:        return(0);
                     62: 
                     63: if(!(sub[subnum]->misc&SUB_INET)       // Prompt for TO: user
                     64:        && (sub[subnum]->misc&SUB_TOUSER || msgattr&MSG_PRIVATE || touser[0])) {
                     65:        if(!touser[0] && !(msgattr&MSG_PRIVATE))
                     66:                strcpy(touser,"All");
                     67:     bputs(text[PostTo]);
                     68:        i=LEN_ALIAS;
                     69:        if(sub[subnum]->misc&(SUB_PNET|SUB_INET))
                     70:                i=60;
                     71:        if(sub[subnum]->misc&SUB_FIDO)
                     72:                i=35;
                     73:        if(sub[subnum]->misc&SUB_QNET)
                     74:                i=25;
                     75:        getstr(touser,i,K_UPRLWR|K_LINE|K_EDIT|K_AUTODEL);
                     76:        if(stricmp(touser,"ALL")
                     77:        && !(sub[subnum]->misc&(SUB_PNET|SUB_FIDO|SUB_QNET|SUB_INET|SUB_ANON))) {
                     78:                if(sub[subnum]->misc&SUB_NAME) {
                     79:                        if(!userdatdupe(useron.number,U_NAME,LEN_NAME,touser,0)) {
                     80:                                bputs(text[UnknownUser]);
                     81:                                return(0); } }
                     82:                else {
                     83:                        if((i=finduser(touser))==0)
                     84:                                return(0);
                     85:                        username(i,touser); } }
                     86:        if(sys_status&SS_ABORT)
                     87:                return(0); }
                     88: 
                     89: if(!touser[0])
                     90:        strcpy(touser,"All");       // Default to ALL
                     91: 
                     92: if(!stricmp(touser,"SYSOP") && !SYSOP)  // Change SYSOP to user #1
                     93:        username(1,touser);
                     94: 
                     95: if(msgattr&MSG_PRIVATE && !stricmp(touser,"ALL")) {
                     96:     bputs(text[NoToUser]);
                     97:     return(0); }
                     98: if(msgattr&MSG_PRIVATE)
                     99:        wm_mode|=WM_PRIVATE;
                    100: 
                    101: if(sub[subnum]->misc&SUB_AONLY
                    102:        || (sub[subnum]->misc&SUB_ANON && useron.exempt&FLAG('A')
                    103:                && !noyes(text[AnonymousQ])))
                    104:        msgattr|=MSG_ANONYMOUS;
                    105: 
                    106: if(sub[subnum]->mod_ar[0] && chk_ar(sub[subnum]->mod_ar,useron))
                    107:        msgattr|=MSG_MODERATED;
                    108: 
                    109: if(sub[subnum]->misc&SUB_SYSPERM && sub_op(subnum))
                    110:        msgattr|=MSG_PERMANENT;
                    111: 
                    112: if(msgattr&MSG_PRIVATE)
                    113:        bputs(text[PostingPrivately]);
                    114: 
                    115: if(msgattr&MSG_ANONYMOUS)
                    116:        bputs(text[PostingAnonymously]);
                    117: 
                    118: if(sub[subnum]->misc&SUB_NAME)
                    119:        bputs(text[UsingRealName]);
                    120: 
                    121: sprintf(str,"%sINPUT.MSG",node_dir);
                    122: if(!writemsg(str,top,title,wm_mode,subnum,touser)) {
                    123:     bputs(text[Aborted]);
                    124:     return(0); }
                    125: 
                    126: bputs(text[WritingIndx]);
                    127: 
                    128: if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) {
                    129:        errormsg(WHERE,ERR_OPEN,sub[subnum]->code,i);
                    130:        return(0); }
                    131: 
                    132: sprintf(smb.file,"%s%s",sub[subnum]->data_dir,sub[subnum]->code);
                    133: smb.retry_time=smb_retry_time;
                    134: if((i=smb_open(&smb))!=0) {
                    135:        smb_stack(&smb,SMB_STACK_POP);
                    136:        errormsg(WHERE,ERR_OPEN,smb.file,i);
                    137:        return(0); }
                    138: 
                    139: if(filelength(fileno(smb.shd_fp))<1) {  /* Create it if it doesn't exist */
                    140:        smb.status.max_crcs=sub[subnum]->maxcrcs;
                    141:        smb.status.max_msgs=sub[subnum]->maxmsgs;
                    142:        smb.status.max_age=sub[subnum]->maxage;
                    143:        smb.status.attr=sub[subnum]->misc&SUB_HYPER ? SMB_HYPERALLOC : 0;
                    144:        if((i=smb_create(&smb))!=0) {
                    145:                smb_close(&smb);
                    146:                smb_stack(&smb,SMB_STACK_POP);
                    147:                errormsg(WHERE,ERR_CREATE,smb.file,i);
                    148:                return(0); } }
                    149: 
                    150: if((i=smb_locksmbhdr(&smb))!=0) {
                    151:        smb_close(&smb);
                    152:        smb_stack(&smb,SMB_STACK_POP);
                    153:        errormsg(WHERE,ERR_LOCK,smb.file,i);
                    154:     return(0); }
                    155: 
                    156: if((i=smb_getstatus(&smb))!=0) {
                    157:        smb_close(&smb);
                    158:        smb_stack(&smb,SMB_STACK_POP);
                    159:        errormsg(WHERE,ERR_READ,smb.file,i);
                    160:     return(0); }
                    161: 
                    162: length=flength(str)+2;  /* +2 for translation string */
                    163: 
                    164: if(length&0xfff00000UL) {
                    165:        smb_close(&smb);
                    166:        smb_stack(&smb,SMB_STACK_POP);
                    167:        errormsg(WHERE,ERR_LEN,str,length);
                    168:     return(0); }
                    169: 
                    170: if(smb.status.attr&SMB_HYPERALLOC) {
                    171:        offset=smb_hallocdat(&smb);
                    172:        storage=SMB_HYPERALLOC; }
                    173: else {
                    174:        if((i=smb_open_da(&smb))!=0) {
                    175:                smb_unlocksmbhdr(&smb);
                    176:                smb_close(&smb);
                    177:                smb_stack(&smb,SMB_STACK_POP);
                    178:                errormsg(WHERE,ERR_OPEN,smb.file,i);
                    179:                return(0); }
                    180:        if(sub[subnum]->misc&SUB_FAST) {
                    181:                offset=smb_fallocdat(&smb,length,1);
                    182:                storage=SMB_FASTALLOC; }
                    183:        else {
                    184:                offset=smb_allocdat(&smb,length,1);
                    185:                storage=SMB_SELFPACK; }
                    186:        smb_close_da(&smb); }
                    187: 
                    188: if((file=open(str,O_RDONLY|O_BINARY))==-1
                    189:        || (instream=fdopen(file,"rb"))==NULL) {
                    190:        smb_freemsgdat(&smb,offset,length,1);
                    191:        smb_unlocksmbhdr(&smb);
                    192:        smb_close(&smb);
                    193:        smb_stack(&smb,SMB_STACK_POP);
                    194:        errormsg(WHERE,ERR_OPEN,str,O_RDONLY|O_BINARY);
                    195:        return(0); }
                    196: 
                    197: setvbuf(instream,NULL,_IOFBF,2*1024);
                    198: fseek(smb.sdt_fp,offset,SEEK_SET);
                    199: xlat=XLAT_NONE;
                    200: fwrite(&xlat,2,1,smb.sdt_fp);
                    201: x=SDT_BLOCK_LEN-2;                             /* Don't read/write more than 255 */
                    202: while(!feof(instream)) {
                    203:        memset(buf,0,x);
                    204:        j=fread(buf,1,x,instream);
                    205:        if((j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR)
                    206:                buf[j-1]=buf[j-2]=0;    /* Convert to NULL */
                    207:        if(sub[subnum]->maxcrcs) {
                    208:                for(i=0;i<j;i++)
                    209:                        crc=ucrc32(buf[i],crc); }
                    210:        fwrite(buf,j,1,smb.sdt_fp);
                    211:        x=SDT_BLOCK_LEN; }
                    212: fflush(smb.sdt_fp);
                    213: fclose(instream);
                    214: crc=~crc;
                    215: 
                    216: memset(&msg,0,sizeof(smbmsg_t));
                    217: memcpy(msg.hdr.id,"SHD\x1a",4);
1.1.1.2 ! root      218: msg.hdr.version=smb_ver();
1.1       root      219: msg.hdr.attr=msg.idx.attr=msgattr;
                    220: msg.hdr.when_written.time=msg.hdr.when_imported.time=time(NULL);
                    221: msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone;
                    222: if(remsg) {
                    223:        msg.hdr.thread_orig=remsg->hdr.number;
                    224:        if(!remsg->hdr.thread_first) {
                    225:                remsg->hdr.thread_first=smb.status.last_msg+1;
                    226:                if((i=smb_lockmsghdr(&smb,remsg))!=0)
                    227:                        errormsg(WHERE,ERR_LOCK,smb.file,i);
                    228:                else {
                    229:                        i=smb_putmsghdr(&smb,remsg);
                    230:                        smb_unlockmsghdr(&smb,remsg);
                    231:                        if(i)
                    232:                                errormsg(WHERE,ERR_WRITE,smb.file,i); } }
                    233:        else {
                    234:                l=remsg->hdr.thread_first;
                    235:                while(1) {
                    236:                        tmpmsg.idx.offset=0;
                    237:                        if(!loadmsg(&tmpmsg,l))
                    238:                                break;
                    239:                        if(tmpmsg.hdr.thread_next && tmpmsg.hdr.thread_next!=l) {
                    240:                                l=tmpmsg.hdr.thread_next;
                    241:                                smb_unlockmsghdr(&smb,&tmpmsg);
                    242:                                smb_freemsgmem(&tmpmsg);
                    243:                                continue; }
                    244:                        tmpmsg.hdr.thread_next=smb.status.last_msg+1;
                    245:                        if((i=smb_putmsghdr(&smb,&tmpmsg))!=0)
                    246:                                errormsg(WHERE,ERR_WRITE,smb.file,i);
                    247:                        smb_unlockmsghdr(&smb,&tmpmsg);
                    248:                        smb_freemsgmem(&tmpmsg);
                    249:                        break; } } }
                    250: 
                    251: 
                    252: if(sub[subnum]->maxcrcs) {
                    253:        i=smb_addcrc(&smb,crc);
                    254:        if(i) {
                    255:                smb_freemsgdat(&smb,offset,length,1);
                    256:                smb_unlocksmbhdr(&smb);
                    257:                smb_close(&smb);
                    258:                smb_stack(&smb,SMB_STACK_POP);
                    259:                bputs("\1r\1h\1iDuplicate message!\r\n");
                    260:                return(0); } }
                    261: 
                    262: msg.hdr.offset=offset;
                    263: 
                    264: smb_hfield(&msg,RECIPIENT,strlen(touser),touser);
                    265: strlwr(touser);
                    266: msg.idx.to=crc16(touser);
                    267: 
                    268: strcpy(str,sub[subnum]->misc&SUB_NAME ? useron.name : useron.alias);
                    269: smb_hfield(&msg,SENDER,strlen(str),str);
                    270: strlwr(str);
                    271: msg.idx.from=crc16(str);
                    272: 
                    273: sprintf(str,"%u",useron.number);
                    274: smb_hfield(&msg,SENDEREXT,strlen(str),str);
                    275: 
                    276: smb_hfield(&msg,SUBJECT,strlen(title),title);
                    277: strcpy(str,title);
                    278: strlwr(str);
                    279: remove_re(str);
                    280: msg.idx.subj=crc16(str);
                    281: 
                    282: smb_dfield(&msg,TEXT_BODY,length);
                    283: 
                    284: smb_unlocksmbhdr(&smb);
                    285: i=smb_addmsghdr(&smb,&msg,storage);
                    286: smb_close(&smb);
                    287: smb_stack(&smb,SMB_STACK_POP);
                    288: 
                    289: smb_freemsgmem(&msg);
                    290: if(i) {
                    291:        smb_freemsgdat(&smb,offset,length,1);
                    292:        errormsg(WHERE,ERR_WRITE,smb.file,i);
                    293:        return(0); }
                    294: 
                    295: useron.ptoday++;
                    296: useron.posts++;
                    297: logon_posts++;
                    298: putuserrec(useron.number,U_POSTS,5,itoa(useron.posts,str,10));
                    299: putuserrec(useron.number,U_PTODAY,5,itoa(useron.ptoday,str,10));
                    300: bprintf(text[Posted],grp[sub[subnum]->grp]->sname
                    301:     ,sub[subnum]->lname);
                    302: sprintf(str,"Posted on %s %s",grp[sub[subnum]->grp]->sname,sub[subnum]->lname);
                    303: logline("P+",str);
                    304: if(sub[subnum]->misc&SUB_FIDO && sub[subnum]->echomail_sem[0]) /* semaphore */
                    305:        if((file=nopen(sub[subnum]->echomail_sem,O_WRONLY|O_CREAT|O_TRUNC))!=-1)
                    306:         close(file);
                    307: return(1);
                    308: }

unix.superglobalmegacorp.com

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