Annotation of sbbs/smblib/smbdump.c, revision 1.1.1.1

1.1       root        1: /* smbdump.c */
                      2: 
                      3: /* Synchronet message base (SMB) message header dumper */
                      4: 
                      5: /* $Id: smbdump.c,v 1.3 2004/09/11 09:26:23 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 2004 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 <time.h>              /* ctime */
                     39: #include "smblib.h"
                     40: 
                     41: static char *binstr(uchar *buf, ushort length)
                     42: {
                     43:        static char str[512];
                     44:        char tmp[128];
                     45:        int i;
                     46: 
                     47:        str[0]=0;
                     48:        for(i=0;i<length;i++)
                     49:                if(buf[i] && (buf[i]<' ' || buf[i]>=0x7f) 
                     50:                        && buf[i]!='\r' && buf[i]!='\n' && buf[i]!='\t')
                     51:                        break;
                     52:        if(i==length)           /* not binary */
                     53:                return(buf);
                     54:        for(i=0;i<length;i++) {
                     55:                sprintf(tmp,"%02X ",buf[i]);
                     56:                strcat(str,tmp); 
                     57:                if(i>=100) {
                     58:                        strcat(str,"...");
                     59:                        break;
                     60:                }
                     61:        }
                     62:        return(str);
                     63: }
                     64: 
                     65: void SMBCALL smb_dump_msghdr(FILE* fp, smbmsg_t* msg)
                     66: {
                     67:        int i;
                     68: 
                     69:        fprintf(fp,"%-20.20s %ld\n"             ,"number"                       ,msg->hdr.number);
                     70: 
                     71:        /* convenience strings */
                     72:        if(msg->subj)
                     73:                fprintf(fp,"%-20.20s %s\n"      ,"subject"                      ,msg->subj);
                     74:        if(msg->to) {
                     75:                fprintf(fp,"%-20.20s %s"        ,"to"                           ,msg->to);
                     76:                if(msg->to_ext)
                     77:                        fprintf(fp," #%s",msg->to_ext);
                     78:                fprintf(fp,"\n");
                     79:        }
                     80:        if(msg->from) {
                     81:                fprintf(fp,"%-20.20s %s"        ,"from"                         ,msg->from);
                     82:                if(msg->from_ext)
                     83:                        fprintf(fp," #%s",msg->from_ext);
                     84:                fprintf(fp,"\n");
                     85:        }
                     86:        if(msg->replyto) {
                     87:                fprintf(fp,"%-20.20s %s"        ,"reply-to"                     ,msg->replyto);
                     88:                if(msg->replyto_ext)
                     89:                        fprintf(fp," #%s",msg->replyto_ext);
                     90:                fprintf(fp,"\n");
                     91:        }
                     92:        if(msg->summary)
                     93:                fprintf(fp,"%-20.20s %s\n"      ,"summary"                      ,msg->summary);
                     94: 
                     95:        /* convenience integers */
                     96:        if(msg->expiration)
                     97:                fprintf(fp,"%-20.20s %.24s\n","expiration"      
                     98:                        ,ctime((time_t *)&msg->expiration));
                     99: 
                    100:        /* fixed header fields */
                    101:        fprintf(fp,"%-20.20s %.24s  UTC%+d:%02d\n"      ,"when_written" 
                    102:                ,ctime((time_t *)&msg->hdr.when_written.time)   
                    103:                ,smb_tzutc(msg->hdr.when_written.zone)/60
                    104:                ,abs(smb_tzutc(msg->hdr.when_written.zone)%60));
                    105:        fprintf(fp,"%-20.20s %.24s  UTC%+d:%02d\n"      ,"when_imported"        
                    106:                ,ctime((time_t *)&msg->hdr.when_imported.time)  
                    107:                ,smb_tzutc(msg->hdr.when_imported.zone)/60
                    108:                ,abs(smb_tzutc(msg->hdr.when_imported.zone)%60));
                    109:        fprintf(fp,"%-20.20s %04Xh\n"   ,"type"                         ,msg->hdr.type);
                    110:        fprintf(fp,"%-20.20s %04Xh\n"   ,"version"                      ,msg->hdr.version);
                    111:        fprintf(fp,"%-20.20s %04Xh\n"   ,"attr"                         ,msg->hdr.attr);
                    112:        fprintf(fp,"%-20.20s %08lXh\n"  ,"auxattr"                      ,msg->hdr.auxattr);
                    113:        fprintf(fp,"%-20.20s %08lXh\n"  ,"netattr"                      ,msg->hdr.netattr);
                    114: 
                    115:        /* optional fixed fields */
                    116:        if(msg->hdr.thread_back)
                    117:                fprintf(fp,"%-20.20s %ld\n"     ,"thread_back"          ,msg->hdr.thread_back);
                    118:        if(msg->hdr.thread_next)
                    119:                fprintf(fp,"%-20.20s %ld\n"     ,"thread_next"          ,msg->hdr.thread_next);
                    120:        if(msg->hdr.thread_first)
                    121:                fprintf(fp,"%-20.20s %ld\n"     ,"thread_first"         ,msg->hdr.thread_first);
                    122:        if(msg->hdr.delivery_attempts)
                    123:                fprintf(fp,"%-20.20s %hu\n"     ,"delivery_attempts",msg->hdr.delivery_attempts);
                    124:        if(msg->hdr.times_downloaded)
                    125:                fprintf(fp,"%-20.20s %lu\n"     ,"times_downloaded"     ,msg->hdr.times_downloaded);
                    126:        if(msg->hdr.last_downloaded)
                    127:                fprintf(fp,"%-20.20s %.24s\n"   ,"last_downloaded"      ,ctime((time_t*)&msg->hdr.last_downloaded));
                    128: 
                    129:        fprintf(fp,"%-20.20s %06lXh\n"  ,"header offset"        ,msg->idx.offset);
                    130:        fprintf(fp,"%-20.20s %u\n"              ,"header length"        ,msg->hdr.length);
                    131:        fprintf(fp,"%-20.20s %lu\n"             ,"calculated length",smb_getmsghdrlen(msg));
                    132: 
                    133:        /* variable fields */
                    134:        for(i=0;i<msg->total_hfields;i++)
                    135:                fprintf(fp,"%-20.20s %s\n"
                    136:                        ,smb_hfieldtype(msg->hfield[i].type)
                    137:                        ,binstr((uchar *)msg->hfield_dat[i],msg->hfield[i].length));
                    138: 
                    139:        /* data fields */
                    140:        fprintf(fp,"%-20.20s %06lXh\n"  ,"data offset"          ,msg->hdr.offset);
                    141:        for(i=0;i<msg->hdr.total_dfields;i++)
                    142:                fprintf(fp,"data field[%u]        %s, offset %lu, length %lu\n"
                    143:                        ,i
                    144:                        ,smb_dfieldtype(msg->dfield[i].type)
                    145:                        ,msg->dfield[i].offset
                    146:                        ,msg->dfield[i].length);
                    147: }

unix.superglobalmegacorp.com

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