Annotation of sbbs/sbbs3/fixsmb.c, revision 1.1

1.1     ! root        1: /* fixsmb.c */
        !             2: 
        !             3: /* Synchronet message base (SMB) index re-generator */
        !             4: 
        !             5: /* $Id: fixsmb.c,v 1.3 2000/11/02 13:00:55 rswindell Exp $ */
        !             6: 
        !             7: /****************************************************************************
        !             8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !            10:  *                                                                                                                                                     *
        !            11:  * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            12:  *                                                                                                                                                     *
        !            13:  * This program is free software; you can redistribute it and/or                       *
        !            14:  * modify it under the terms of the GNU General Public License                         *
        !            15:  * as published by the Free Software Foundation; either version 2                      *
        !            16:  * of the License, or (at your option) any later version.                                      *
        !            17:  * See the GNU General Public License for more details: gpl.txt or                     *
        !            18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
        !            19:  *                                                                                                                                                     *
        !            20:  * Anonymous FTP access to the most recent released source is available at     *
        !            21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            22:  *                                                                                                                                                     *
        !            23:  * Anonymous CVS access to the development source and modification history     *
        !            24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            26:  *     (just hit return, no password is necessary)                                                     *
        !            27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            28:  *                                                                                                                                                     *
        !            29:  * For Synchronet coding style and modification guidelines, see                                *
        !            30:  * http://www.synchro.net/source.html                                                                          *
        !            31:  *                                                                                                                                                     *
        !            32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            33:  * format) via e-mail to [email protected]                                                                      *
        !            34:  *                                                                                                                                                     *
        !            35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            36:  ****************************************************************************/
        !            37: 
        !            38: #include <stdlib.h>    /* atoi */
        !            39: #include <string.h>    /* strnicmp */
        !            40: #include <ctype.h>     /* toupper */
        !            41: 
        !            42: #include "smblib.h"
        !            43: #include "smbwrap.h"
        !            44: 
        !            45: smb_t smb;
        !            46: 
        !            47: char *usage="usage: fixsmb [/opts] <smb_file>\n"
        !            48:                        "\n"
        !            49:                        " opts:\n"
        !            50:                        "       m - force mail format instead of sub-board format\n"
        !            51:                        "\n"
        !            52:                        "   ex: FIXSMB /M MAIL\n"
        !            53:                        "   or: FIXSMB DEBATE\n";
        !            54: 
        !            55: void remove_re(char *str)
        !            56: {
        !            57: while(!strnicmp(str,"RE:",3)) {
        !            58:        strcpy(str,str+3);
        !            59:        while(str[0]==SP)
        !            60:                strcpy(str,str+1); }
        !            61: }
        !            62: 
        !            63: /****************************************************************************/
        !            64: /* Updates 16-bit "rcrc" with character 'ch'                                */
        !            65: /****************************************************************************/
        !            66: void ucrc16(uchar ch, ushort *rcrc) {
        !            67:        ushort i, cy;
        !            68:     uchar nch=ch;
        !            69:  
        !            70: for (i=0; i<8; i++) {
        !            71:     cy=*rcrc & 0x8000;
        !            72:     *rcrc<<=1;
        !            73:     if (nch & 0x80) *rcrc |= 1;
        !            74:     nch<<=1;
        !            75:     if (cy) *rcrc ^= 0x1021; }
        !            76: }
        !            77: 
        !            78: /****************************************************************************/
        !            79: /* Returns 16-crc of string (not counting terminating NULL)                            */
        !            80: /****************************************************************************/
        !            81: ushort crc16(char *str)
        !            82: {
        !            83:        int     i=0;
        !            84:        ushort  crc=0;
        !            85: 
        !            86: ucrc16(0,&crc);
        !            87: while(str[i])
        !            88:        ucrc16(str[i++],&crc);
        !            89: ucrc16(0,&crc);
        !            90: ucrc16(0,&crc);
        !            91: return(crc);
        !            92: }
        !            93: 
        !            94: #define MAIL (1<<0)
        !            95: 
        !            96: int main(int argc, char **argv)
        !            97: {
        !            98:        char            str[128],c;
        !            99:        int             i,w,mode=0;
        !           100:        ulong           l,length,size,n;
        !           101:        smbmsg_t        msg;
        !           102: 
        !           103: printf("\nFIXSMB v1.23 - Rebuild Synchronet Message Base Index - by Rob Swindell\n");
        !           104: 
        !           105: smb.file[0]=0;
        !           106: for(i=1;i<argc;i++)
        !           107:        if(argv[i][0]=='/')
        !           108:                switch(toupper(argv[i][1])) {
        !           109:                        case 'M':
        !           110:                                mode|=MAIL;
        !           111:                                break;
        !           112:                        default:
        !           113:                                printf(usage);
        !           114:                                exit(1); }
        !           115:        else
        !           116:                strcpy(smb.file,argv[i]);
        !           117: 
        !           118: if(!smb.file[0]) {
        !           119:        printf(usage);
        !           120:        exit(1); }
        !           121: 
        !           122: smb.retry_time=30;
        !           123: 
        !           124: if((i=smb_open(&smb))!=0) {
        !           125:        printf("smb_open returned %d\n",i);
        !           126:        exit(1); }
        !           127: 
        !           128: if((i=smb_locksmbhdr(&smb))!=0) {
        !           129:        smb_close(&smb);
        !           130:        printf("smb_locksmbhdr returned %d\n",i);
        !           131:        exit(1); }
        !           132: 
        !           133: if((i=smb_getstatus(&smb))!=0) {
        !           134:        smb_unlocksmbhdr(&smb);
        !           135:        smb_close(&smb);
        !           136:        printf("smb_getstatus returned %d\n",i);
        !           137:        exit(1); }
        !           138: 
        !           139: if(mode&MAIL && !(smb.status.attr&SMB_EMAIL)) {
        !           140:        smb.status.attr|=SMB_EMAIL;
        !           141:        if((i=smb_putstatus(&smb))!=0) {
        !           142:                smb_unlocksmbhdr(&smb);
        !           143:                smb_close(&smb);
        !           144:                printf("smb_putstatus returned %d\n",i);
        !           145:                exit(1); } }
        !           146: 
        !           147: if(!(smb.status.attr&SMB_HYPERALLOC)) {
        !           148: 
        !           149:        if((i=smb_open_ha(&smb))!=0) {
        !           150:                smb_close(&smb);
        !           151:                printf("smb_open_ha returned %d\n",i);
        !           152:                exit(1); }
        !           153: 
        !           154:        if((i=smb_open_da(&smb))!=0) {
        !           155:                smb_close(&smb);
        !           156:                printf("smb_open_da returned %d\n",i);
        !           157:                exit(1); }
        !           158: 
        !           159:        rewind(smb.sha_fp);
        !           160:        chsize(fileno(smb.sha_fp),0L);          /* Truncate the header allocation file */
        !           161:        rewind(smb.sda_fp);
        !           162:        chsize(fileno(smb.sda_fp),0L);          /* Truncate the data allocation file */
        !           163:        }
        !           164: 
        !           165: rewind(smb.sid_fp);
        !           166: chsize(fileno(smb.sid_fp),0L);                 /* Truncate the index */
        !           167: 
        !           168: 
        !           169: if(!(smb.status.attr&SMB_HYPERALLOC)) {
        !           170:        length=filelength(fileno(smb.sdt_fp));
        !           171:        w=0;
        !           172:        for(l=0;l<length;l+=SDT_BLOCK_LEN)      /* Init .SDA file to NULL */
        !           173:                fwrite(&w,2,1,smb.sda_fp);
        !           174: 
        !           175:        length=filelength(fileno(smb.shd_fp));
        !           176:        c=0;
        !           177:        for(l=0;l<length;l+=SHD_BLOCK_LEN)      /* Init .SHD file to NULL */
        !           178:                fwrite(&c,1,1,smb.sha_fp); }
        !           179: else
        !           180:        length=filelength(fileno(smb.shd_fp));
        !           181: 
        !           182: n=1;   /* messsage number */
        !           183: for(l=smb.status.header_offset;l<length;l+=size) {
        !           184:        size=SHD_BLOCK_LEN;
        !           185:        printf("\r%2u%%  ",(long)(100.0/((float)length/l)));
        !           186:        msg.idx.offset=l;
        !           187:        if((i=smb_lockmsghdr(&smb,&msg))!=0) {
        !           188:                printf("\n(%06lX) smb_lockmsghdr returned %d\n",l,i);
        !           189:                continue; }
        !           190:        if((i=smb_getmsghdr(&smb,&msg))!=0) {
        !           191:                smb_unlockmsghdr(&smb,&msg);
        !           192:                printf("\n(%06lX) smb_getmsghdr returned %d\n",l,i);
        !           193:                continue; }
        !           194:        smb_unlockmsghdr(&smb,&msg);
        !           195:        printf("#%-5lu (%06lX) %-25.25s ",msg.hdr.number,l,msg.from);
        !           196:        if(!(msg.hdr.attr&MSG_DELETE)) {   /* Don't index deleted messages */
        !           197:                msg.offset=n-1;
        !           198:                msg.hdr.number=n;
        !           199:                msg.idx.number=n;
        !           200:                msg.idx.attr=msg.hdr.attr;
        !           201:                msg.idx.time=msg.hdr.when_imported.time;
        !           202:                strcpy(str,msg.subj);
        !           203:                strlwr(str);
        !           204:                remove_re(str);
        !           205:                msg.idx.subj=crc16(str);
        !           206:                if(smb.status.attr&SMB_EMAIL) {
        !           207:                        if(msg.to_ext)
        !           208:                                msg.idx.to=atoi(msg.to_ext);
        !           209:                        else
        !           210:                                msg.idx.to=0;
        !           211:                        if(msg.from_ext)
        !           212:                                msg.idx.from=atoi(msg.from_ext);
        !           213:                        else
        !           214:                                msg.idx.from=0; }
        !           215:                else {
        !           216:                        strcpy(str,msg.to);
        !           217:                        strlwr(str);
        !           218:                        msg.idx.to=crc16(str);
        !           219:                        strcpy(str,msg.from);
        !           220:                        strlwr(str);
        !           221:                        msg.idx.from=crc16(str); }
        !           222:                if((i=smb_putmsg(&smb,&msg))!=0) {
        !           223:                        printf("\nsmb_putmsg returned %d\n",i);
        !           224:                        continue; }
        !           225:                n++; }
        !           226:        else
        !           227:                printf("Not indexing deleted message\n");
        !           228:        size=smb_getmsghdrlen(&msg);
        !           229:        while(size%SHD_BLOCK_LEN)
        !           230:                size++;
        !           231: 
        !           232:        if(!(smb.status.attr&SMB_HYPERALLOC)) {
        !           233:                /**************************/
        !           234:                /* Allocate header blocks */
        !           235:                /**************************/
        !           236:                fseek(smb.sha_fp,(l-smb.status.header_offset)/SHD_BLOCK_LEN,SEEK_SET);
        !           237:                if(msg.hdr.attr&MSG_DELETE) c=0;                /* mark as free */
        !           238:                else c=1;                                                               /* or allocated */
        !           239: 
        !           240:                for(i=0;i<(int)(size/SHD_BLOCK_LEN);i++)
        !           241:                        fputc(c,smb.sha_fp);
        !           242: 
        !           243:                /************************/
        !           244:                /* Allocate data blocks */
        !           245:                /************************/
        !           246: 
        !           247:                if(!(msg.hdr.attr&MSG_DELETE))
        !           248:                        smb_incdat(&smb,msg.hdr.offset,smb_getmsgdatlen(&msg),1);
        !           249:                }
        !           250: 
        !           251:        smb_freemsgmem(&msg); }
        !           252: printf("\nDone.\n");
        !           253: smb.status.total_msgs=smb.status.last_msg=n-1;
        !           254: if((i=smb_putstatus(&smb))!=0)
        !           255:        printf("\nsmb_putstatus returned %d\n",i);
        !           256: smb_unlocksmbhdr(&smb);
        !           257: smb_close(&smb);
        !           258: return(0);
        !           259: }

unix.superglobalmegacorp.com

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