Skip to content
Snippets Groups Projects
Commit 03db7f43 authored by rswindell's avatar rswindell
Browse files

Created smb_dump module with smb_dump_msghdr() routine for common message

header debug/dump function (used by chksmb and smbutil).
parent 7d099a1e
Branches
No related tags found
No related merge requests found
......@@ -146,7 +146,7 @@ $(NODE): node.c
$(QUIET)$(CC) $(CFLAGS) -n$(EXEODIR) $**
SMBLIB = $(LIBODIR)\smblib.obj $(LIBODIR)\genwrap.obj $(LIBODIR)\filewrap.obj \
$(LIBODIR)\crc16.obj
$(LIBODIR)\crc16.obj $(LIBODIR)\smbdump.obj
# FIXSMB Utility
$(FIXSMB): fixsmb.c $(SMBLIB) $(LIBODIR)\str_util.obj $(LIBODIR)\dirwrap.obj
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -149,7 +149,7 @@ int main(int argc, char **argv)
smbmsg_t msg;
fprintf(stderr,"\nCHKSMB v2.12 - Check Synchronet Message Base - "
"Copyright 2003 Rob Swindell\n");
"Copyright 2004 Rob Swindell\n");
if(argc<2) {
printf("%s",usage);
......@@ -263,6 +263,7 @@ int main(int argc, char **argv)
for(l=smb.status.header_offset;l<length;l+=size) {
size=SHD_BLOCK_LEN;
fprintf(stderr,"\r%2lu%% ",(long)(100.0/((float)length/l)));
memset(&msg,0,sizeof(msg));
msg.idx.offset=l;
msgerr=0;
if((i=smb_lockmsghdr(&smb,&msg))!=0) {
......@@ -480,53 +481,8 @@ int main(int argc, char **argv)
headers++;
if(msgerr && extinfo) {
printf("\n");
printf("%-20s: %s\n","Message Base",smb.file);
printf("%-20s: %lu (%lu)\n","Message Number"
,msg.hdr.number,msg.offset+1);
printf("%-20s: %s\n","Subject",msg.subj);
printf("%-20s: %s","To",msg.to);
if(msg.to_net.type && msg.to_net.addr)
printf(" (%s)",msg.to_net.type==NET_FIDO
? faddrtoa(*(fidoaddr_t *)msg.to_net.addr) : (char*)msg.to_net.addr);
printf("\n%-20s: %s","From",msg.from);
if(msg.from_net.type && msg.from_net.addr)
printf(" (%s)",msg.from_net.type==NET_FIDO
? faddrtoa(*(fidoaddr_t *)msg.from_net.addr)
: (char*)msg.from_net.addr);
printf("\n");
printf("%-20s: %.24s tz: %04hXh\n","When Written"
,ctime((time_t *)&msg.hdr.when_written.time)
,msg.hdr.when_written.zone);
printf("%-20s: %.24s tz: %04hXh\n","When Imported"
,ctime((time_t *)&msg.hdr.when_imported.time)
,msg.hdr.when_imported.zone);
printf("%-20s: %04hXh\n","Type"
,msg.hdr.type);
printf("%-20s: %04hXh\n","Version"
,msg.hdr.version);
printf("%-20s: %u\n","Length"
,msg.hdr.length);
printf("%-20s: %lu\n","Calculated Length"
,smb_getmsghdrlen(&msg));
printf("%-20s: %04hXh\n","Attributes"
,msg.hdr.attr);
printf("%-20s: %08lXh\n","Auxilary Attributes"
,msg.hdr.auxattr);
printf("%-20s: %08lXh\n","Network Attributes"
,msg.hdr.netattr);
printf("%-20s: %06lXh\n","Header Offset"
,msg.idx.offset);
printf("%-20s: %06lXh\n","Data Offset"
,msg.hdr.offset);
printf("%-20s: %u\n","Total Data Fields"
,msg.hdr.total_dfields);
for(i=0;i<msg.hdr.total_dfields;i++)
printf("dfield[%u].type : %02Xh\n"
"dfield[%u].offset : %lu (%lXh)\n"
"dfield[%u].length : %lu\n"
,i,msg.dfield[i].type
,i,msg.dfield[i].offset, msg.dfield[i].offset
,i,msg.dfield[i].length);
printf("%-20s %s\n","message base",smb.file);
smb_dump_msghdr(stdout,&msg);
printf("\n");
}
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -571,88 +571,9 @@ void viewmsgs(ulong start, ulong count)
break;
}
printf("%-16.16s %ld\n" ,"index record",ftell(smb.sid_fp)/sizeof(idxrec_t));
printf("%-16.16s %ld\n" ,"number" ,msg.hdr.number);
/* convenience strings */
if(msg.subj)
printf("%-16.16s %s\n" ,"subject" ,msg.subj);
if(msg.to) {
printf("%-16.16s %s" ,"to" ,msg.to);
if(msg.to_net.addr && strchr(msg.to,'@')==NULL)
printf(" (%s)",net_addr(&msg.to_net));
if(msg.to_ext)
printf(" #%s",msg.to_ext);
printf("\n");
}
if(msg.from) {
printf("%-16.16s %s" ,"from" ,msg.from);
if(msg.from_net.addr && strchr(msg.from,'@')==NULL)
printf(" (%s)",net_addr(&msg.from_net));
if(msg.from_ext)
printf(" #%s",msg.from_ext);
printf("\n");
}
if(msg.replyto) {
printf("%-16.16s %s" ,"reply-to" ,msg.replyto);
if(msg.replyto_net.addr && strchr(msg.replyto,'@')==NULL)
printf(" (%s)",net_addr(&msg.replyto_net));
if(msg.replyto_ext)
printf(" #%s",msg.replyto_ext);
printf("\n");
}
if(msg.summary)
printf("%-16.16s %s\n" ,"summary" ,msg.summary);
/* optional fixed fields */
if(msg.hdr.thread_orig)
printf("%-16.16s %ld\n" ,"thread_orig" ,msg.hdr.thread_orig);
if(msg.hdr.thread_next)
printf("%-16.16s %ld\n" ,"thread_next" ,msg.hdr.thread_next);
if(msg.hdr.thread_first)
printf("%-16.16s %ld\n" ,"thread_first" ,msg.hdr.thread_first);
if(msg.hdr.delivery_attempts)
printf("%-16.16s %hu\n" ,"delivery_attempts",msg.hdr.delivery_attempts);
if(msg.hdr.times_downloaded)
printf("%-16.16s %lu\n" ,"times_downloaded" ,msg.hdr.times_downloaded);
if(msg.hdr.last_downloaded)
printf("%-16.16s %s\n" ,"last_downloaded" ,my_timestr((time_t*)&msg.hdr.last_downloaded));
/* convenience integers */
if(msg.cost)
printf("%-16.16s %lu\n" ,"cost" ,msg.cost);
if(msg.priority)
printf("%-16.16s %lu\n" ,"priority" ,msg.priority);
if(msg.expiration)
printf("%-16.16s %s\n" ,"expiration"
,my_timestr((time_t *)&msg.expiration));
printf("%-16.16s %s %s\n" ,"when_written"
,my_timestr((time_t *)&msg.hdr.when_written.time), zonestr(msg.hdr.when_written.zone));
printf("%-16.16s %s %s\n" ,"when_imported"
,my_timestr((time_t *)&msg.hdr.when_imported.time), zonestr(msg.hdr.when_imported.zone));
printf("%-16.16s %04Xh\n" ,"type" ,msg.hdr.type);
printf("%-16.16s %04Xh\n" ,"version" ,msg.hdr.version);
printf("%-16.16s %04Xh\n" ,"attr" ,msg.hdr.attr);
printf("%-16.16s %08lXh\n" ,"auxattr" ,msg.hdr.auxattr);
printf("%-16.16s %08lXh\n" ,"netattr" ,msg.hdr.netattr);
printf("%-16.16s %06lXh\n" ,"header offset" ,msg.idx.offset);
printf("%-16.16s %u\n" ,"header length" ,msg.hdr.length);
/* variable fields */
for(i=0;i<msg.total_hfields;i++)
printf("%-16.16s %s\n"
,smb_hfieldtype(msg.hfield[i].type)
,binstr((uchar *)msg.hfield_dat[i],msg.hfield[i].length));
printf("%-16.16s %06lXh\n" ,"data offset" ,msg.hdr.offset);
for(i=0;i<msg.hdr.total_dfields;i++)
printf("data field[%u] %s, offset %lu, length %lu\n"
,i
,smb_dfieldtype(msg.dfield[i].type)
,msg.dfield[i].offset
,msg.dfield[i].length);
printf("--------------------\n");
printf("%-20.20s %ld\n" ,"index record",ftell(smb.sid_fp)/sizeof(idxrec_t));
smb_dump_msghdr(stdout,&msg);
printf("\n");
smb_freemsgmem(&msg);
l++;
......
/* smbdump.c */
/* Synchronet message base (SMB) message header dumper */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include "smblib.h"
#include <time.h> /* ctime */
static char *binstr(uchar *buf, ushort length)
{
static char str[512];
char tmp[128];
int i;
str[0]=0;
for(i=0;i<length;i++)
if(buf[i] && (buf[i]<' ' || buf[i]>=0x7f)
&& buf[i]!='\r' && buf[i]!='\n' && buf[i]!='\t')
break;
if(i==length) /* not binary */
return(buf);
for(i=0;i<length;i++) {
sprintf(tmp,"%02X ",buf[i]);
strcat(str,tmp);
if(i>=100) {
strcat(str,"...");
break;
}
}
return(str);
}
void SMBCALL smb_dump_msghdr(FILE* fp, smbmsg_t* msg)
{
int i;
fprintf(fp,"%-20.20s %ld\n" ,"number" ,msg->hdr.number);
/* convenience strings */
if(msg->subj)
fprintf(fp,"%-20.20s %s\n" ,"subject" ,msg->subj);
if(msg->to) {
fprintf(fp,"%-20.20s %s" ,"to" ,msg->to);
if(msg->to_ext)
fprintf(fp," #%s",msg->to_ext);
fprintf(fp,"\n");
}
if(msg->from) {
fprintf(fp,"%-20.20s %s" ,"from" ,msg->from);
if(msg->from_ext)
fprintf(fp," #%s",msg->from_ext);
fprintf(fp,"\n");
}
if(msg->replyto) {
fprintf(fp,"%-20.20s %s" ,"reply-to" ,msg->replyto);
if(msg->replyto_ext)
fprintf(fp," #%s",msg->replyto_ext);
fprintf(fp,"\n");
}
if(msg->summary)
fprintf(fp,"%-20.20s %s\n" ,"summary" ,msg->summary);
/* convenience integers */
if(msg->expiration)
fprintf(fp,"%-20.20s %.24s\n","expiration"
,ctime((time_t *)&msg->expiration));
/* fixed header fields */
fprintf(fp,"%-20.20s %.24s UTC%+d:%02d\n" ,"when_written"
,ctime((time_t *)&msg->hdr.when_written.time)
,smb_tzutc(msg->hdr.when_written.zone)/60
,abs(smb_tzutc(msg->hdr.when_written.zone)%60));
fprintf(fp,"%-20.20s %.24s UTC%+d:%02d\n" ,"when_imported"
,ctime((time_t *)&msg->hdr.when_imported.time)
,smb_tzutc(msg->hdr.when_imported.zone)/60
,abs(smb_tzutc(msg->hdr.when_imported.zone)%60));
fprintf(fp,"%-20.20s %04Xh\n" ,"type" ,msg->hdr.type);
fprintf(fp,"%-20.20s %04Xh\n" ,"version" ,msg->hdr.version);
fprintf(fp,"%-20.20s %04Xh\n" ,"attr" ,msg->hdr.attr);
fprintf(fp,"%-20.20s %08lXh\n" ,"auxattr" ,msg->hdr.auxattr);
fprintf(fp,"%-20.20s %08lXh\n" ,"netattr" ,msg->hdr.netattr);
/* optional fixed fields */
if(msg->hdr.thread_orig)
fprintf(fp,"%-20.20s %ld\n" ,"thread_orig" ,msg->hdr.thread_orig);
if(msg->hdr.thread_next)
fprintf(fp,"%-20.20s %ld\n" ,"thread_next" ,msg->hdr.thread_next);
if(msg->hdr.thread_first)
fprintf(fp,"%-20.20s %ld\n" ,"thread_first" ,msg->hdr.thread_first);
if(msg->hdr.delivery_attempts)
fprintf(fp,"%-20.20s %hu\n" ,"delivery_attempts",msg->hdr.delivery_attempts);
if(msg->hdr.times_downloaded)
fprintf(fp,"%-20.20s %lu\n" ,"times_downloaded" ,msg->hdr.times_downloaded);
if(msg->hdr.last_downloaded)
fprintf(fp,"%-20.20s %.24s\n" ,"last_downloaded" ,ctime((time_t*)&msg->hdr.last_downloaded));
fprintf(fp,"%-20.20s %06lXh\n" ,"header offset" ,msg->idx.offset);
fprintf(fp,"%-20.20s %u\n" ,"header length" ,msg->hdr.length);
fprintf(fp,"%-20.20s %lu\n" ,"calculated length",smb_getmsghdrlen(msg));
/* variable fields */
for(i=0;i<msg->total_hfields;i++)
fprintf(fp,"%-20.20s %s\n"
,smb_hfieldtype(msg->hfield[i].type)
,binstr((uchar *)msg->hfield_dat[i],msg->hfield[i].length));
/* data fields */
fprintf(fp,"%-20.20s %06lXh\n" ,"data offset" ,msg->hdr.offset);
for(i=0;i<msg->hdr.total_dfields;i++)
fprintf(fp,"data field[%u] %s, offset %lu, length %lu\n"
,i
,smb_dfieldtype(msg->dfield[i].type)
,msg->dfield[i].offset
,msg->dfield[i].length);
}
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -152,9 +152,14 @@ SMBEXPORT int SMBCALL smb_freemsgdat(smb_t* smb, ulong offset, ulong length, u
SMBEXPORT int SMBCALL smb_freemsghdr(smb_t* smb, ulong offset, ulong length);
SMBEXPORT void SMBCALL smb_freemsgtxt(char* buf);
SMBEXPORT int SMBCALL smb_copymsgmem(smb_t* smb, smbmsg_t* destmsg, smbmsg_t* srcmsg);
SMBEXPORT char* SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode);
SMBEXPORT int SMBCALL smb_tzutc(short timezone);
/* smbtxt.c */
SMBEXPORT char* SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode);
/* smbdump.c */
SMBEXPORT void SMBCALL smb_dump_msghdr(FILE* fp, smbmsg_t* msg);
/* FILE pointer I/O functions */
SMBEXPORT int SMBCALL smb_feof(FILE* fp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment