Annotation of sbbs/sbbs2/un_rep.c, revision 1.1

1.1     ! root        1: #line 1 "UN_REP.C"
        !             2: 
        !             3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
        !             4: 
        !             5: #include "sbbs.h"
        !             6: #include "qwk.h"
        !             7: 
        !             8: /****************************************************************************/
        !             9: /* Unpacks .REP packet, 'repname' is the path and filename of the packet    */
        !            10: /****************************************************************************/
        !            11: void unpack_rep()
        !            12: {
        !            13:        uchar   ch,str[256],fname[128],block[128]
        !            14:                        ,*AttemptedToUploadREPpacket="Attempted to upload REP packet";
        !            15:        int     file;
        !            16:        uint    h,i,j,k,msgs,lastsub=INVALID_SUB;
        !            17:        ulong   n;
        !            18:        long    l,size,misc,crc;
        !            19:        node_t  node;
        !            20:        time_t  t;
        !            21:        file_t  f;
        !            22:     struct  ffblk ff;
        !            23:        FILE    *rep;
        !            24: 
        !            25: sprintf(str,"%s%s.REP",temp_dir,sys_id);
        !            26: if(!fexist(str)) {
        !            27:        bputs(text[QWKReplyNotReceived]);
        !            28:        logline("U!",AttemptedToUploadREPpacket);
        !            29:        logline(nulstr,"REP file not received");
        !            30:        return; }
        !            31: for(k=0;k<total_fextrs;k++)
        !            32:        if(!stricmp(fextr[k]->ext,useron.tmpext) && chk_ar(fextr[k]->ar,useron))
        !            33:                break;
        !            34: if(k>=total_fextrs)
        !            35:        k=0;
        !            36: i=external(cmdstr(fextr[k]->cmd,str,"*.*",NULL),EX_OUTL|EX_OUTR);
        !            37: if(i) {
        !            38:        bputs(text[QWKExtractionFailed]);
        !            39:        logline("U!",AttemptedToUploadREPpacket);
        !            40:        logline(nulstr,"Extraction failed");
        !            41:        return; }
        !            42: sprintf(str,"%s%s.MSG",temp_dir,sys_id);
        !            43: if(!fexist(str)) {
        !            44:        bputs(text[QWKReplyNotReceived]);
        !            45:        logline("U!",AttemptedToUploadREPpacket);
        !            46:        logline(nulstr,"MSG file not received");
        !            47:        return; }
        !            48: if((rep=fnopen(&file,str,O_RDONLY))==NULL) {
        !            49:        errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
        !            50:        return; }
        !            51: size=filelength(file);
        !            52: fread(block,128,1,rep);
        !            53: if(strncmpi(block,sys_id,strlen(sys_id))) {
        !            54:        fclose(rep);
        !            55:        bputs(text[QWKReplyNotReceived]);
        !            56:        logline("U!",AttemptedToUploadREPpacket);
        !            57:        logline(nulstr,"Incorrect BBSID");
        !            58:        return; }
        !            59: logline("U+","Uploaded REP packet");
        !            60: /********************/
        !            61: /* Process messages */
        !            62: /********************/
        !            63: bputs(text[QWKUnpacking]);
        !            64: 
        !            65: for(l=128;l<size;l+=i*128) {
        !            66:        lncntr=0;                                       /* defeat pause */
        !            67:        fseek(rep,l,SEEK_SET);
        !            68:        fread(block,128,1,rep);
        !            69:        sprintf(tmp,"%.6s",block+116);
        !            70:        i=atoi(tmp);  /* i = number of 128 byte records */
        !            71:        if(i<2) {
        !            72:                sprintf(tmp,"%s blocks",str);
        !            73:                errormsg(WHERE,ERR_CHK,tmp,i);
        !            74:                i=1;
        !            75:                continue; }
        !            76:        if(atoi(block+1)==0) {                                  /**********/
        !            77:                if(useron.rest&FLAG('E')) {         /* E-mail */
        !            78:                        bputs(text[R_Email]);                   /**********/
        !            79:                        continue; }
        !            80: 
        !            81:         sprintf(str,"%25.25s",block+21);
        !            82:                truncsp(str);
        !            83:                if(!stricmp(str,"NETMAIL")) {  /* QWK to FidoNet NetMail */
        !            84:                        qwktonetmail(rep,block,NULL,0);
        !            85:                        continue; }
        !            86:                if(strchr(str,'@')) {
        !            87:                        qwktonetmail(rep,block,str,0);
        !            88:                        continue; }
        !            89:                if(!stricmp(str,"SBBS")) {    /* to SBBS, config stuff */
        !            90:                        qwkcfgline(block+71,INVALID_SUB);
        !            91:             continue; }
        !            92: 
        !            93:                if(useron.etoday>=level_emailperday[useron.level]
        !            94:                        && !(useron.rest&FLAG('Q'))) {
        !            95:                        bputs(text[TooManyEmailsToday]);
        !            96:                        continue; }
        !            97:                j=atoi(str);
        !            98:                if(j && j>lastuser())
        !            99:                        j=0;
        !           100:                if(!j &&
        !           101:                        (!stricmp(str,"SYSOP")
        !           102:                        || !stricmp(str,sys_id)
        !           103:                        || !stricmp(str,sys_op)))
        !           104:                        j=1;
        !           105:                if(!j)
        !           106:                        j=matchuser(str);
        !           107:                if(!j) {
        !           108:                        bputs(text[UnknownUser]);
        !           109:                        continue; }
        !           110:                if(j==1 && useron.rest&FLAG('S')) {
        !           111:                        bprintf(text[R_Feedback],sys_op);
        !           112:                        continue; }
        !           113: 
        !           114:                getuserrec(j,U_MISC,8,str);
        !           115:                misc=ahtoul(str);
        !           116:                if(misc&NETMAIL && sys_misc&SM_FWDTONET) {
        !           117:                        getuserrec(j,U_NETMAIL,LEN_NETMAIL,str);
        !           118:                        qwktonetmail(rep,block,str,0);
        !           119:                        continue; }
        !           120: 
        !           121:                sprintf(smb.file,"%sMAIL",data_dir);
        !           122:                smb.retry_time=smb_retry_time;
        !           123: 
        !           124:                if(lastsub!=INVALID_SUB) {
        !           125:                        smb_close(&smb);
        !           126:                        lastsub=INVALID_SUB; }
        !           127: 
        !           128:                if((k=smb_open(&smb))!=0) {
        !           129:                        errormsg(WHERE,ERR_OPEN,smb.file,k);
        !           130:                        continue; }
        !           131: 
        !           132:                if(!filelength(fileno(smb.shd_fp))) {
        !           133:                        smb.status.max_crcs=mail_maxcrcs;
        !           134:                        smb.status.max_msgs=MAX_SYSMAIL;
        !           135:                        smb.status.max_age=mail_maxage;
        !           136:                        smb.status.attr=SMB_EMAIL;
        !           137:                        if((k=smb_create(&smb))!=0) {
        !           138:                                smb_close(&smb);
        !           139:                                errormsg(WHERE,ERR_CREATE,smb.file,k);
        !           140:                                continue; } }
        !           141: 
        !           142:                if((k=smb_locksmbhdr(&smb))!=0) {
        !           143:                        smb_close(&smb);
        !           144:                        errormsg(WHERE,ERR_LOCK,smb.file,k);
        !           145:                        continue; }
        !           146: 
        !           147:                if((k=smb_getstatus(&smb))!=0) {
        !           148:                        smb_close(&smb);
        !           149:                        errormsg(WHERE,ERR_READ,smb.file,k);
        !           150:                        continue; }
        !           151: 
        !           152:                smb_unlocksmbhdr(&smb);
        !           153: 
        !           154:                if(!qwktomsg(rep,block,0,INVALID_SUB,j)) {
        !           155:                        smb_close(&smb);
        !           156:                        continue; }
        !           157:                smb_close(&smb);
        !           158: 
        !           159:                if(j==1) {
        !           160:                        useron.fbacks++;
        !           161:                        logon_fbacks++;
        !           162:                        putuserrec(useron.number,U_FBACKS,5
        !           163:                                ,itoa(useron.fbacks,tmp,10)); }
        !           164:                else {
        !           165:                        useron.emails++;
        !           166:                        logon_emails++;
        !           167:                        putuserrec(useron.number,U_EMAILS,5
        !           168:                                ,itoa(useron.emails,tmp,10)); }
        !           169:                useron.etoday++;
        !           170:                putuserrec(useron.number,U_ETODAY,5
        !           171:                        ,itoa(useron.etoday,tmp,10));
        !           172:                bprintf(text[Emailed],username(j,tmp),j);
        !           173:                sprintf(str,"E-mailed %s #%d",username(j,tmp),j);
        !           174:                logline("E+",str);
        !           175:                if(useron.rest&FLAG('Q')) {
        !           176:                        sprintf(tmp,"%-25.25s",block+46);
        !           177:                        truncsp(tmp); }
        !           178:                else
        !           179:                        strcpy(tmp,useron.alias);
        !           180:                for(k=1;k<=sys_nodes;k++) { /* Tell user, if online */
        !           181:                        getnodedat(k,&node,0);
        !           182:                        if(node.useron==j && !(node.misc&NODE_POFF)
        !           183:                                && (node.status==NODE_INUSE
        !           184:                                || node.status==NODE_QUIET)) {
        !           185:                                sprintf(str,text[EmailNodeMsg]
        !           186:                                        ,node_num,tmp);
        !           187:                                putnmsg(k,str);
        !           188:                                break; } }
        !           189:                if(k>sys_nodes) {
        !           190:                        sprintf(str,text[UserSentYouMail],tmp);
        !           191:                        putsmsg(j,str); } }    /* end of email */
        !           192: 
        !           193:                        /**************************/
        !           194:        else {  /* message on a sub-board */
        !           195:                        /**************************/
        !           196:                n=atol((char *)block+1); /* conference number */
        !           197:                for(j=0;j<usrgrps;j++) {
        !           198:                        for(k=0;k<usrsubs[j];k++)
        !           199:                                if(sub[usrsub[j][k]]->qwkconf==n)
        !           200:                                        break;
        !           201:                        if(k<usrsubs[j])
        !           202:                                break; }
        !           203: 
        !           204:                if(j>=usrgrps) {
        !           205:                        if(n<1000) {                     /* version 1 method, start at 101 */
        !           206:                                j=n/100;
        !           207:                                k=n-(j*100); }
        !           208:                        else {                                   /* version 2 method, start at 1001 */
        !           209:                                j=n/1000;
        !           210:                                k=n-(j*1000); }
        !           211:                        j--;    /* j is group */
        !           212:                        k--;    /* k is sub */
        !           213:                        if(j>=usrgrps || k>=usrsubs[j]) {
        !           214:                                bprintf(text[QWKInvalidConferenceN],n);
        !           215:                                sprintf(str,"Invalid conference number %d",n);
        !           216:                                logline("P!",str);
        !           217:                                continue; } }
        !           218: 
        !           219:                n=usrsub[j][k];
        !           220: 
        !           221:                /* if posting, add to new-scan config for QWKnet nodes automatically */
        !           222:         if(useron.rest&FLAG('Q'))
        !           223:                        sub[n]->misc|=SUB_NSCAN;
        !           224: 
        !           225:                sprintf(str,"%-25.25s","SBBS");
        !           226:                if(!strnicmp((char *)block+21,str,25)) {        /* to SBBS, config stuff */
        !           227:                        qwkcfgline((char *)block+71,n);
        !           228:                        continue; }
        !           229: 
        !           230:                if(!SYSOP && sub[n]->misc&SUB_QNET) {   /* QWK Netted */
        !           231:                        sprintf(str,"%-25.25s","DROP");         /* Drop from new-scan? */
        !           232:                        if(!strnicmp((char *)block+71,str,25))  /* don't allow post */
        !           233:                                continue;
        !           234:                        sprintf(str,"%-25.25s","ADD");          /* Add to new-scan? */
        !           235:                        if(!strnicmp((char *)block+71,str,25))  /* don't allow post */
        !           236:                                continue; }
        !           237: 
        !           238:                if(useron.rest&FLAG('Q') && !(sub[n]->misc&SUB_QNET)) {
        !           239:                        bputs(text[CantPostOnSub]);
        !           240:                        logline("P!","Attempted to post on non-QWKnet sub");
        !           241:                        continue; }
        !           242: 
        !           243:         if(useron.rest&FLAG('P')) {
        !           244:             bputs(text[R_Post]);
        !           245:                        logline("P!","Post attempted");
        !           246:             continue; }
        !           247: 
        !           248:                if(useron.ptoday>=level_postsperday[useron.level]
        !           249:                        && !(useron.rest&FLAG('Q'))) {
        !           250:                        bputs(text[TooManyPostsToday]);
        !           251:                        continue; }
        !           252: 
        !           253:                if(useron.rest&FLAG('N')
        !           254:                        && sub[n]->misc&(SUB_FIDO|SUB_PNET|SUB_QNET|SUB_INET)) {
        !           255:                        bputs(text[CantPostOnSub]);
        !           256:                        logline("P!","Networked post attempted");
        !           257:                        continue; }
        !           258: 
        !           259:                if(!chk_ar(sub[n]->post_ar,useron)) {
        !           260:                        bputs(text[CantPostOnSub]);
        !           261:                        logline("P!","Post attempted");
        !           262:                        continue; }
        !           263: 
        !           264:                if((block[0]=='*' || block[0]=='+')
        !           265:                        && !(sub[n]->misc&SUB_PRIV)) {
        !           266:                        bputs(text[PrivatePostsNotAllowed]);
        !           267:                        logline("P!","Private post attempt");
        !           268:                        continue; }
        !           269: 
        !           270:                if(block[0]=='*' || block[0]=='+'           /* Private post */
        !           271:                        || sub[n]->misc&SUB_PONLY) {
        !           272:                        sprintf(str,"%-25.25s",nulstr);
        !           273:                        sprintf(tmp,"%-25.25s","ALL");
        !           274:                        if(!strnicmp((char *)block+21,str,25)
        !           275:                                || !strnicmp((char *)block+21,tmp,25)) {        /* to blank */
        !           276:                                bputs(text[NoToUser]);                                          /* or all */
        !           277:                                continue; } }
        !           278: 
        !           279:                if(!SYSOP && !(useron.rest&FLAG('Q'))) {
        !           280:                        sprintf(str,"%-25.25s","SYSOP");
        !           281:                        if(!strnicmp((char *)block+21,str,25)) {
        !           282:                                sprintf(str,"%-25.25s",username(1,tmp));
        !           283:                                memcpy((char *)block+21,str,25); } }    /* change from sysop */
        !           284:                                                                                                                /* to user #1 */
        !           285: 
        !           286: #if 0  /* TWIT FILTER */
        !           287:                sprintf(str,"%25.25s",block+46);  /* From user */
        !           288:                truncsp(str);
        !           289: 
        !           290:                if(!stricmp(str,"Lee Matherne")
        !           291:                        || !stricmp(str,"Big Joe")
        !           292:                        ) {
        !           293:                        bprintf(text[Posted],grp[sub[n]->grp]->sname
        !           294:                                ,sub[n]->lname);
        !           295:                        continue; }
        !           296: #endif
        !           297: 
        !           298:                if(n!=lastsub) {
        !           299:                        if(lastsub!=INVALID_SUB)
        !           300:                                smb_close(&smb);
        !           301:                        lastsub=INVALID_SUB;
        !           302:                        sprintf(smb.file,"%s%s",sub[n]->data_dir,sub[n]->code);
        !           303:                        smb.retry_time=smb_retry_time;
        !           304:                        if((j=smb_open(&smb))!=0) {
        !           305:                                errormsg(WHERE,ERR_OPEN,smb.file,j);
        !           306:                                continue; }
        !           307: 
        !           308:                        if(!filelength(fileno(smb.shd_fp))) {
        !           309:                                smb.status.max_crcs=sub[n]->maxcrcs;
        !           310:                                smb.status.max_msgs=sub[n]->maxmsgs;
        !           311:                                smb.status.max_age=sub[n]->maxage;
        !           312:                                smb.status.attr=sub[n]->misc&SUB_HYPER ? SMB_HYPERALLOC:0;
        !           313:                                if((j=smb_create(&smb))!=0) {
        !           314:                                        smb_close(&smb);
        !           315:                                        lastsub=INVALID_SUB;
        !           316:                                        errormsg(WHERE,ERR_CREATE,smb.file,j);
        !           317:                                        continue; } }
        !           318: 
        !           319:                        if((j=smb_locksmbhdr(&smb))!=0) {
        !           320:                                smb_close(&smb);
        !           321:                                lastsub=INVALID_SUB;
        !           322:                                errormsg(WHERE,ERR_LOCK,smb.file,j);
        !           323:                                continue; }
        !           324:                        if((j=smb_getstatus(&smb))!=0) {
        !           325:                                smb_close(&smb);
        !           326:                                lastsub=INVALID_SUB;
        !           327:                                errormsg(WHERE,ERR_READ,smb.file,j);
        !           328:                                continue; }
        !           329:                        smb_unlocksmbhdr(&smb);
        !           330:                        lastsub=n; }
        !           331: 
        !           332:                if(!qwktomsg(rep,block,0,n,0))
        !           333:                        continue;
        !           334: 
        !           335:                useron.ptoday++;
        !           336:                useron.posts++;
        !           337: //               if(!(useron.rest&FLAG('Q')))
        !           338:                logon_posts++;
        !           339:                putuserrec(useron.number,U_POSTS,5,itoa(useron.posts,str,10));
        !           340:                putuserrec(useron.number,U_PTODAY,5,itoa(useron.ptoday,str,10));
        !           341:                bprintf(text[Posted],grp[sub[n]->grp]->sname
        !           342:                        ,sub[n]->lname);
        !           343:                sprintf(str,"Posted on %s %s",grp[sub[n]->grp]->sname
        !           344:                        ,sub[n]->lname);
        !           345:                if(sub[n]->misc&SUB_FIDO && sub[n]->echomail_sem[0])  /* semaphore */
        !           346:                        if((file=nopen(sub[n]->echomail_sem,O_WRONLY|O_CREAT|O_TRUNC))!=-1)
        !           347:                                close(file);
        !           348:         logline("P+",str); } }         /* end of public message */
        !           349: 
        !           350: update_qwkroute(NULL);                 /* Write ROUTE.DAT */
        !           351: 
        !           352: if(lastsub!=INVALID_SUB)
        !           353:        smb_close(&smb);
        !           354: fclose(rep);
        !           355: 
        !           356: if(useron.rest&FLAG('Q')) {             /* QWK Net Node */
        !           357:        sprintf(str,"%s%s.MSG",temp_dir,sys_id);
        !           358:        remove(str);
        !           359:        sprintf(str,"%s%s.REP",temp_dir,sys_id);
        !           360:     remove(str);
        !           361: 
        !           362:        sprintf(str,"%s*.*",temp_dir);
        !           363:        i=findfirst(str,&ff,0);
        !           364:        if(!i) {
        !           365:                sprintf(str,"%sQNET\\%s.IN",data_dir,useron.alias);
        !           366:                mkdir(str); }
        !           367:        while(!i) {                                             /* Extra files */
        !           368:                sprintf(str,"%s%s",temp_dir,ff.ff_name);
        !           369:                sprintf(fname,"%sQNET\\%s.IN\\%s",data_dir,useron.alias,ff.ff_name);
        !           370:                mv(str,fname,1);
        !           371:                sprintf(str,text[ReceivedFileViaQWK],ff.ff_name,useron.alias);
        !           372:                putsmsg(1,str);
        !           373:                i=findnext(&ff); } }
        !           374: 
        !           375: bputs(text[QWKUnpacked]);
        !           376: CRLF;
        !           377: /**********************************************/
        !           378: /* Hang-up now if that's what the user wanted */
        !           379: /**********************************************/
        !           380: autohangup();
        !           381: 
        !           382: }

unix.superglobalmegacorp.com

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