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: gmowcat3.cpp,v 1.9 2006/05/14 11:45:05 ssianky Exp $
23 // ------------------------------------------------------------------
24 // WildCat! 4.x messagebase engine.
25 // ------------------------------------------------------------------
26
27
28 // ------------------------------------------------------------------
29
30 #include <gmemdbg.h>
31 #include <gdbgtrk.h>
32 #include <gstrall.h>
33
34 #include <gmowcat.h>
35
36
37 // ------------------------------------------------------------------
38
load_message(int __mode,gmsg * __msg,WCatHdr & __hdr)39 int WCatArea::load_message(int __mode, gmsg* __msg, WCatHdr& __hdr) {
40
41 // Setup some local variables for speed
42 int _fhdat = data->fhdat;
43 WCatIdx* _idx = data->idx;
44 uint _reln = Msgn->ToReln(__msg->msgno);
45
46 // Load the message header
47 memset(&__hdr, 0, sizeof(WCatHdr));
48 lseekset(_fhdat, _idx[_reln-1].offset);
49 read(_fhdat, &__hdr, sizeof(WCatHdr));
50
51 // Convert header
52
53 __msg->timesread = 1;
54
55 __msg->link.to_set(__hdr.reference);
56
57 struplow(strnp2cc(__msg->by, __hdr.from, 70));
58 struplow(strnp2cc(__msg->to, __hdr.to, 70));
59 strnp2cc(__msg->re, __hdr.subject, 70);
60
61 strnp2cc(__msg->wildcat.from_title, __hdr.fromtitle, 10);
62 strnp2cc(__msg->wildcat.to_title, __hdr.totitle, 10);
63 strnp2cc(__msg->wildcat.network, __hdr.network, 8);
64 strnp2cc(__msg->wildcat.internal_attach, __hdr.internalattach, 12);
65 strnp2cc(__msg->wildcat.external_attach, __hdr.externalattach, 12);
66
67 memcpy(__msg->wildcat.reserved, __hdr.reserved, 20);
68
69 __msg->wildcat.from_userid = __hdr.fromuserid;
70 __msg->wildcat.to_userid = __hdr.touserid;
71 __msg->wildcat.next_unread = __hdr.nextunread;
72 __msg->wildcat.prev_unread = __hdr.prevunread;
73
74 __msg->cost = (uint)__hdr.cost;
75
76 __msg->orig.zone = __msg->oorig.zone = __hdr.origaddr.zone;
77 __msg->orig.net = __msg->oorig.net = __hdr.origaddr.net;
78 __msg->orig.node = __msg->oorig.node = __hdr.origaddr.node;
79 __msg->orig.point = __msg->oorig.point = __hdr.origaddr.point;
80
81 __msg->dest.zone = __msg->odest.zone = __hdr.destaddr.zone;
82 __msg->dest.net = __msg->odest.net = __hdr.destaddr.net;
83 __msg->dest.node = __msg->odest.node = __hdr.destaddr.node;
84 __msg->dest.point = __msg->odest.point = __hdr.destaddr.point;
85
86 // Convert date and time
87 struct tm _tm;
88 int32_t _time;
89 unsigned _year, _month, _day, _hour, _minute, _second;
90
91 __msg->written = __msg->arrived = __msg->received = 0;
92
93 if(__hdr.msgdate and __hdr.msgtime) {
94 JDN2YMD(__hdr.msgdate+1, &_year, &_month, &_day);
95 _time = __hdr.msgtime-1;
96 _hour = (unsigned)(_time / 3600L);
97 _minute = (unsigned)((_time % 3600L) / 60L);
98 _second = (unsigned)(_time - ((_hour*3600L)+_minute*60L));
99 _tm.tm_year = _year - 1900;
100 _tm.tm_mon = _month - 1;
101 _tm.tm_mday = _day;
102 _tm.tm_hour = _hour;
103 _tm.tm_min = _minute;
104 _tm.tm_sec = _second;
105 _tm.tm_isdst = -1;
106 time32_t a = gmktime(&_tm);
107 struct tm tp; ggmtime(&tp, &a);
108 tp.tm_isdst = -1;
109 time32_t b = gmktime(&tp);
110 __msg->written = a + a - b;
111 }
112
113 if(__hdr.readdate and __hdr.readtime) {
114 JDN2YMD(__hdr.readdate+1, &_year, &_month, &_day);
115 _time = __hdr.readtime-1;
116 _hour = (unsigned)(_time / 3600L);
117 _minute = (unsigned)((_time % 3600L) / 60L);
118 _second = (unsigned)(_time - ((_hour*3600L)+_minute*60L));
119 _tm.tm_year = _year - 1900;
120 _tm.tm_mon = _month - 1;
121 _tm.tm_mday = _day;
122 _tm.tm_hour = _hour;
123 _tm.tm_min = _minute;
124 _tm.tm_sec = _second;
125 _tm.tm_isdst = -1;
126 time32_t a = gmktime(&_tm);
127 struct tm tp; ggmtime(&tp, &a);
128 tp.tm_isdst = -1;
129 time32_t b = gmktime(&tp);
130 __msg->received = a + a - b;
131 }
132
133
134 // Convert fidoflag attributes
135 __msg->attr.pvt(__hdr.fidoflags & FIDO_PVT);
136 __msg->attr.cra(__hdr.fidoflags & FIDO_CRASH);
137 __msg->attr.rcv(__hdr.fidoflags & FIDO_RECEIVED);
138 __msg->attr.snt(__hdr.fidoflags & FIDO_SENT);
139 __msg->attr.att(__hdr.fidoflags & FIDO_ATTACH);
140 __msg->attr.trs(__hdr.fidoflags & FIDO_TRANSIT);
141 __msg->attr.orp(__hdr.fidoflags & FIDO_ORPHAN);
142 __msg->attr.k_s(__hdr.fidoflags & FIDO_KILLSENT);
143 __msg->attr.loc(__hdr.fidoflags & FIDO_LOCAL);
144 __msg->attr.hld(__hdr.fidoflags & FIDO_HOLD);
145 __msg->attr.rsv(__hdr.fidoflags & FIDO_RESERVED);
146 __msg->attr.frq(__hdr.fidoflags & FIDO_FREQ);
147 __msg->attr.rrq(__hdr.fidoflags & FIDO_RETRECREQ);
148 __msg->attr.rrc(__hdr.fidoflags & FIDO_RETREC);
149 __msg->attr.arq(__hdr.fidoflags & FIDO_AUDITREQ);
150 __msg->attr.urq(__hdr.fidoflags & FIDO_UPDREQ);
151
152 // Convert mflag attributes
153 __msg->attr.pvt(__hdr.mflags & mfPrivate);
154 __msg->attr.rab(__hdr.mflags & mfReceiveable);
155 __msg->attr.rcv(__hdr.mflags & mfReceived);
156 __msg->attr.rrc(__hdr.mflags & mfReceipt);
157 __msg->attr.car(__hdr.mflags & mfCarboned);
158 __msg->attr.fwd(__hdr.mflags & mfForwarded);
159 __msg->attr.efl(__hdr.mflags & mfEchoFlag);
160 __msg->attr.hrp(__hdr.mflags & mfHasReplies);
161 __msg->attr.del(__hdr.mflags & mfDeleted);
162 __msg->attr.tag(__hdr.mflags & mfTagged);
163 __msg->attr.snt(__hdr.mflags & mfSent);
164
165 // Set the unsent attribute
166 __msg->attr.uns(__msg->attr.loc() and not __msg->attr.snt());
167
168 __msg->txtlength = __hdr.msgbytes;
169
170 // If message text is requested
171 if(__mode & GMSG_TXT) {
172
173 // Get length of message text
174 uint _txtlen = __hdr.msgbytes;
175
176 // Allocate space for the message text
177 __msg->txt = (char*)throw_calloc(1, _txtlen+256);
178
179 // Read the message text
180 read(_fhdat, __msg->txt, _txtlen);
181
182 // Convert kludge char from NUL to CTRL-A
183 char* p = __msg->txt;
184 for(int n=0; n<_txtlen; n++,p++) {
185 if(*p == '\0')
186 *p = CTRL_A;
187 }
188 }
189
190 GFTRK(0);
191
192 // Success
193 return true;
194 }
195
196
197 // ------------------------------------------------------------------
198
load_hdr(gmsg * __msg)199 int WCatArea::load_hdr(gmsg* __msg) {
200
201 GFTRK("WCatLoadHdr");
202
203 WCatHdr _hdr;
204 return load_message(GMSG_HDR, __msg, _hdr);
205 }
206
207
208 // ------------------------------------------------------------------
209
load_msg(gmsg * __msg)210 int WCatArea::load_msg(gmsg* __msg) {
211
212 GFTRK("WCatLoadMsg");
213
214 WCatHdr _hdr;
215 return load_message(GMSG_HDRTXT, __msg, _hdr);
216 }
217
218
219 // ------------------------------------------------------------------
220
221