1 // This may look like C code, but it is really -*- C++ -*-
2
3 // ------------------------------------------------------------------
4 // The Goldware Library
5 // Copyright (C) 1990-1999 Odinn Sorensen
6 // ------------------------------------------------------------------
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this program; if not, write to the Free
19 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 // MA 02111-1307, USA
21 // ------------------------------------------------------------------
22 // $Id: gmojamm5.cpp,v 1.6 2006/05/14 11:45:05 ssianky Exp $
23 // ------------------------------------------------------------------
24 // JAM msgbase implementation, utilities.
25 // ------------------------------------------------------------------
26
27
28 // ------------------------------------------------------------------
29
30 #include <gmemdbg.h>
31 #include <gdbgtrk.h>
32 #include <gutlmisc.h>
33
34 #include <gmojamm.h>
35
36
37 // ------------------------------------------------------------------
38
user_lookup(char * lookfor)39 char* JamArea::user_lookup(char* lookfor) {
40
41 NW(lookfor);
42 return NULL;
43 }
44
45
46 // ------------------------------------------------------------------
47
renumber()48 int JamArea::renumber() {
49
50 return false;
51 }
52
53
54 // ------------------------------------------------------------------
55
make_dump_msg(Line * & lin,gmsg * __msg,char * lng_head)56 Line* JamArea::make_dump_msg(Line*& lin, gmsg* __msg, char* lng_head) {
57
58 GFTRK("JamArea::make_dump_msg");
59
60 // Read base header
61 JamHdrInfo* _base = (JamHdrInfo*)throw_calloc(1, sizeof(JamHdrInfo));
62 lseekset(data->fhjhr, 0);
63 read(data->fhjhr, _base, sizeof(JamHdrInfo));
64
65 // Read index record for msg
66 JamIndex _idx;
67 lseekset(data->fhjdx, __msg->msgno-data->hdrinfo.basemsgnum, sizeof(JamIndex));
68 read(data->fhjdx, &_idx, sizeof(JamIndex));
69
70 // Allocate space for the header
71 JamHdr* _hdr = (JamHdr*)throw_calloc(1, (uint)(sizeof(JamHdr)+17));
72
73 // Read message header
74 lseekset(data->fhjhr, _idx.hdroffset);
75 read(data->fhjhr, _hdr, sizeof(JamHdr));
76
77 // Allocate space for the subfields
78 byte* _subfield = (byte*)throw_calloc(1, (uint)(_hdr->subfieldlen+17));
79
80 // Read the subfields
81 read(data->fhjhr, _subfield, (uint)_hdr->subfieldlen);
82
83 // Allocate memory for the raw message text
84 throw_free(__msg->txt);
85 __msg->txt = (char*)throw_calloc(1, (uint)_hdr->txtlen+16);
86
87 // Read the message text
88 lseekset(data->fhjdt, _hdr->offset);
89 read(data->fhjdt, __msg->txt, (uint)_hdr->txtlen);
90
91 char buf[100];
92 Line* line = lin =
93 AddLine (NULL, "Hexdump of JAM message header, subfields and text");
94 AddLineF(line, "------------------------------------------------------------------------------");
95 line = AddLine(line, "");
96 AddLineF(line, "Msgbase : %s", real_path());
97 AddLineF(line, "Signature : %s", _hdr->signature);
98 AddLineF(line, "Revision : %u", _hdr->revision);
99 AddLineF(line, "ReservedWord : %u", _hdr->reservedword);
100 AddLineF(line, "SubfieldLen : %u", _hdr->subfieldlen);
101 AddLineF(line, "TimesRead : %u", _hdr->timesread);
102 AddLineF(line, "MSGIDcrc : %08Xh", _hdr->msgidcrc);
103 AddLineF(line, "REPLYcrc : %08Xh", _hdr->replycrc);
104 AddLineF(line, "ReplyTo : %u", _hdr->replyto);
105 AddLineF(line, "Reply1st : %u", _hdr->reply1st);
106 AddLineF(line, "ReplyNext : %u", _hdr->replynext);
107 AddLineF(line, "DateWritten : %s (%08Xh)", TimeToStr(buf, _hdr->datewritten), (int32_t)_hdr->datewritten);
108 AddLineF(line, "DateReceived : %s (%08Xh)", TimeToStr(buf, _hdr->datereceived), (int32_t)_hdr->datereceived);
109 AddLineF(line, "DateProcessed : %s (%08Xh)", TimeToStr(buf, _hdr->dateprocessed), (int32_t)_hdr->dateprocessed);
110 AddLineF(line, "MessageNumber : %u", _hdr->messagenumber);
111 AddLineF(line, "Attribute : %08Xh (%sb)", _hdr->attribute, ltob(buf, _hdr->attribute, 0));
112 AddLineF(line, "Attribute2 : %08Xh (%sb)", _hdr->attribute2, ltob(buf, _hdr->attribute2, 0));
113 AddLineF(line, "Offset : %u", _hdr->offset);
114 AddLineF(line, "TxtLen : %u", _hdr->txtlen);
115 AddLineF(line, "PasswordCRC : %08Xh", _hdr->passwordcrc);
116 AddLineF(line, "Cost : %u", _hdr->cost);
117 line = AddLine(line, "");
118 AddLineF(line, "Index Record:");
119 line = AddLine(line, "");
120 AddLineF(line, "UserCrc : %08Xh", _idx.usercrc);
121 AddLineF(line, "HeaderOffset : %08Xh (%u)", _idx.hdroffset, _idx.hdroffset);
122 line = AddLine(line, "");
123 AddLineF(line, "Lastread Record:");
124 line = AddLine(line, "");
125 AddLineF(line, "Index : %u", data->lastpos);
126 AddLineF(line, "UserCrc : %08Xh", data->lastrec.usercrc);
127 AddLineF(line, "UserId : %08Xh", data->lastrec.userid);
128 AddLineF(line, "Lastread : %u", data->lastrec.lastread);
129 AddLineF(line, "Highread : %u", data->lastrec.highread);
130 line = AddLine(line, "");
131 AddLineF(line, "Base Header:");
132 line = AddLine(line, "");
133 AddLineF(line, "DateCreated : %s (%08Xh)", TimeToStr(buf, _base->datecreated), (int32_t)_base->datecreated);
134 AddLineF(line, "ModCounter : %u", _base->modcounter);
135 AddLineF(line, "ActiveMsgs : %u", _base->activemsgs);
136 AddLineF(line, "PasswordCRC : %08Xh", _base->passwordcrc);
137 AddLineF(line, "BaseMsgNum : %u", _base->basemsgnum);
138 if(jamwide->smapihw)
139 AddLineF(line, "HighWaterMark : %u", _base->highwatermark);
140 else if(data->highwater != -1)
141 AddLineF(line, "HighWaterMark : %u", data->highwater);
142 else
143 AddLineF(line, "HighWaterMark : unknown");
144 line = AddLine(line, "");
145 AddLineF(line, "Subfields:");
146 line = AddLine(line, "");
147
148 AddHexdump(line, _subfield, (uint)_hdr->subfieldlen);
149 line = AddLine(line, "");
150
151 // Process the subfields
152 JamSubField* _subfieldptr = (JamSubField*)_subfield;
153 uint _subfieldpos = 0;
154 while(_subfieldpos < _hdr->subfieldlen) {
155 _subfieldpos += sizeof(JamSubFieldHdr);
156 uint _datlen = (uint)_subfieldptr->datlen;
157 if(_subfieldpos > _hdr->subfieldlen) {
158 AddLineF(line, "Error: SubfieldHdr at pos %u exceeds SubfieldLen (%u)!", (uint)(_subfieldpos-sizeof(JamSubFieldHdr)), _hdr->subfieldlen);
159 break;
160 }
161 if((_subfieldpos + _datlen) > _hdr->subfieldlen) {
162 _datlen = (uint)(_hdr->subfieldlen - _subfieldpos);
163 AddLineF(line, "Error: SubfieldData at pos %u is too int32_t (%u)! Cut to %u.", _subfieldpos, (uint)_subfieldptr->datlen, _datlen);
164 }
165 AddLineF(line, "%05u [%3u]: \"%-*.*s\"",
166 _subfieldptr->loid, _datlen,
167 MinV(60, (int)_datlen),
168 MinV(60, (int)_datlen),
169 _subfieldptr->buffer
170 );
171 _subfieldpos += _datlen;
172 _subfieldptr = (JamSubField*)(_subfield + _subfieldpos);
173 }
174
175 // Free subfield buffer
176 throw_free(_subfield);
177
178 line = AddLine(line, "");
179 AddLineF(line, lng_head);
180 line = AddLine(line, "");
181
182 AddHexdump(line, _hdr, sizeof(JamHdr));
183
184 // Free header and base
185 throw_free(_hdr);
186 throw_free(_base);
187
188 GFTRK(0);
189
190 return line;
191 }
192
193
194 // ------------------------------------------------------------------
195
196