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 //  Copyright (C) 1999-2000 Alexander S. Aganichev
7 //  ------------------------------------------------------------------
8 //  This library is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU Library General Public
10 //  License as published by the Free Software Foundation; either
11 //  version 2 of the License, or (at your option) any later version.
12 //
13 //  This library is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 //  Library General Public License for more details.
17 //
18 //  You should have received a copy of the GNU Library General Public
19 //  License along with this program; if not, write to the Free
20 //  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 //  MA 02111-1307, USA
22 //  ------------------------------------------------------------------
23 //  $Id: gmosqsh.h,v 1.3 2009/04/04 09:51:04 grsf Exp $
24 //  ------------------------------------------------------------------
25 //  Squish msgbase.
26 //  ------------------------------------------------------------------
27 
28 
29 //  ------------------------------------------------------------------
30 //  Only include once!
31 
32 #ifndef __GMSQSH_H
33 #define __GMSQSH_H
34 
35 
36 //  ------------------------------------------------------------------
37 
38 #include <gmoarea.h>
39 #include <limits.h>
40 #include <gdefs.h>
41 #include <gusrmax.h>
42 
43 
44 //  ------------------------------------------------------------------
45 
46 #if defined(GOLD_CANPACK)
47 #pragma pack(1)
48 #endif
49 
50 
51 //  ------------------------------------------------------------------
52 
53 #ifdef GOLD_16BIT
54 const long MAX_IDXBUFSIZE = 65300L;
55 #else
56 const long MAX_IDXBUFSIZE = LONG_MAX;
57 #endif
58 
59 
60 //  ------------------------------------------------------------------
61 
62 #define MSGAREA_NORMAL  0x00
63 #define MSGAREA_CREATE  0x01
64 #define MSGAREA_CRIFNEC 0x02
65 
66 
67 //  ------------------------------------------------------------------
68 
69 #define MSGTYPE_SDM     0x01
70 #define MSGTYPE_SQUISH  0x02
71 #define MSGTYPE_ECHO    0x80
72 
73 
74 //  ------------------------------------------------------------------
75 
76 #define MSGNUM_CUR      ((dword)-1L)
77 #define MSGNUM_PREV     ((dword)-2L)
78 #define MSGNUM_NEXT     ((dword)-3L)
79 
80 
81 //  ------------------------------------------------------------------
82 
83 #define MOPEN_CREATE    0
84 #define MOPEN_READ      1
85 #define MOPEN_WRITE     2
86 #define MOPEN_RW        3
87 
88 
89 //  ------------------------------------------------------------------
90 
91 #define SQEXTRA_BUF 16
92 
93 
94 //  ------------------------------------------------------------------
95 //  Constants for 'type' argument of SquishUidToMsgn()
96 
97 const int UID_EXACT = 0;
98 const int UID_NEXT  = 1;
99 const int UID_PREV  = 2;
100 
101 
102 //  ------------------------------------------------------------------
103 //  Values for msgapierr
104 
105 #define MERR_NONE   0     // No error
106 #define MERR_BADH   1     // Invalid handle passed to function
107 #define MERR_BADF   2     // Invalid or corrupted file
108 #define MERR_NOMEM  3     // Not enough memory for specified operation
109 #define MERR_NODS   4     // Maybe not enough disk space for operation
110 #define MERR_NOENT  5     // File/message does not exist
111 #define MERR_BADA   6     // Bad argument passed to msgapi function
112 #define MERR_EOPEN  7     // Couldn't close - messages still open
113 #define MERR_ACCESS 10    // Access denied - msgbase locked?
114 
115 
116 //  ------------------------------------------------------------------
117 //  Bitmasks for 'attr'
118 
119 #define MSGPRIVATE 0x0001
120 #define MSGCRASH   0x0002
121 #define MSGREAD    0x0004
122 #define MSGSENT    0x0008
123 #define MSGFILE    0x0010
124 #define MSGFWD     0x0020
125 #define MSGORPHAN  0x0040
126 #define MSGKILL    0x0080
127 #define MSGLOCAL   0x0100
128 #define MSGHOLD    0x0200
129 #define MSGXX2     0x0400
130 #define MSGFRQ     0x0800
131 #define MSGRRQ     0x1000
132 #define MSGCPT     0x2000
133 #define MSGARQ     0x4000
134 #define MSGURQ     0x8000
135 #define MSGSCANNED 0x00010000L
136 #define MSGUID     0x00020000L
137 #define MSGPRINTED 0x00040000L
138 #define MSGSEEN    0x00080000L
139 #define MSGLOK     0x40000000L
140 
141 
142 //  ------------------------------------------------------------------
143 //  Max number of stored replies to one msg
144 
145 #define MAX_REPLY 9
146 
147 
148 //  ------------------------------------------------------------------
149 //  Structure of message headers in .SQD
150 
151 struct SqshHdr {
152   dword    attr;
153   char    from[36];
154   char    to[36];
155   char    subj[72];
156   Addr    orig;
157   Addr    dest;
158   FTime   date_written;   // When user wrote the msg (UTC)
159   FTime   date_arrived;   // When msg arrived on-line (UTC)
160   short    utc_offset;     // Offset from UTC of message writer, in minutes.
161   dword    replyto;
162   dword    replies[MAX_REPLY];
163   dword    umsgid;
164   char    ftsc_date[20];
165 };
166 
167 
168 //  ------------------------------------------------------------------
169 //  Squish frames
170 
171 const dword SQFRAMEID      = 0xAFAE4453L;
172 const dword SQFRAME_NULL   = 0;
173 const word SQFRAME_NORMAL = 0;
174 const word SQFRAME_FREE   = 1;
175 
176 
177 //  ------------------------------------------------------------------
178 //  Structure of message frames in .SQD
179 
180 struct SqshFrm {
181   dword  id;               // Must always equal SQFRAMEID
182   int32_t  next;             // Offset of next frame
183   int32_t  prev;             // Offset of previous frame
184   dword  length;           // Length of this frame
185   dword  totsize;          // Length of data in frame (hdr+ctl+txt)
186   dword  ctlsize;          // Length of control info
187   word  type;             // Frm type (normal or free)
188   word  reserved;         // Reserved
189 };
190 
191 
192 //  ------------------------------------------------------------------
193 //  Structure of index file .SQI
194 
195 struct SqshIdx {
196   int32_t  offset;           // Offset of frame in .SQD
197   dword  msgno;            // Message number
198   dword  hash;             // Hash value of TO: name
199 };
200 
201 
202 //  ------------------------------------------------------------------
203 //  Structure of base record in .SQD
204 
205 struct SqshBase {
206   word  size;             // sizeof(SqshBaseT)
207   word  reserved1;        // reserved
208   dword totalmsgs;        // Number of messages in area
209   dword highestmsg;       // Highest msg in area. Same as totalmsgs
210   dword protmsgs;         // Skip killing first x msgs in area
211   dword highwatermark;    // Relno (not Tagno) of HWM
212   dword nextmsgno;        // Next message number to use
213   char  name[80];         // Base name of SquishFile
214   dword firstframe;       // Offset of first frame in file
215   dword lastframe;        // Offset to last frame in file
216   dword firstfreeframe;   // Offset of first FREE frame in file
217   dword lastfreeframe;    // Offset of last free frame in file
218   dword endframe;         // Pointer to end of file
219   dword maxmsgs;          // Max # of msgs to keep in area
220   word  daystokeep;       // Max age of msgs in area (for packing util)
221   word  framesize;        // sizeof(SqshFrmT)
222   byte  reserved2[124];   // Reserved by Squish for future use
223 };
224 
225 
226 //  ------------------------------------------------------------------
227 
228 #if defined(GOLD_CANPACK)
229 #pragma pack()
230 #endif
231 
232 
233 //  ------------------------------------------------------------------
234 
235 struct SqshData {
236   int        fhsqd;
237   int        fhsqi;
238   SqshBase   base;
239   SqshIdx*   idx;
240   int        softlock;
241   int        islocked;
242 };
243 
244 
245 //  ------------------------------------------------------------------
246 
247 struct SqshWide {
248   int          userno;
249   MaximusUser* user;
250   const char*  userpath;
251   int          direct;
252   int          recycle;
253   int          squishscan;
254 };
255 
256 
257 //  ------------------------------------------------------------------
258 
259 class SquishArea : public gmo_area {
260 
261 protected:
262 
263   SqshWide* wide;
264   SqshData* data;
265 
266   void data_open();
267   void data_close();
268 
269   int test_open(const char* __file);
270   void save_lastread();
271   void raw_scan(int __keep_index, int __scanpm=false);
272   void raw_open();
273   void raw_close();
274   void refresh();
275   int load_message(int __mode, gmsg* __msg, SqshHdr& __hdr);
276 
277   void read_frm(dword __offset, SqshFrm* __frm);
278   void write_frm(dword __offset, SqshFrm* __frm);
279   void upd_frm_next(dword __offset, SqshFrm* __frm, dword __next);
280   void upd_frm_prev(dword __offset, SqshFrm* __frm, dword __prev);
281   void add_to_free_chain(dword __delframe, SqshFrm* __delfrm);
282   void delete_msg(uint __reln);
283   void init_frm(SqshFrm* __frm);
284   void excess_frm(dword __lastframe, dword __newframe, SqshFrm* __newfrm, dword __totsize);
285   uint find_msgn(uint32_t __tagn);
286   void save_message(int __mode, gmsg* __msg);
287 
288 public:
289 
SquishArea()290   SquishArea() { wide = NULL; data = NULL; }
~SquishArea()291   virtual ~SquishArea() {}
292 
293   //  ----------------------------------------------------------------
294   //  Messagebase member functions
295 
296   void open();
297   void close();
298 
299   void suspend();
300   void resume();
301 
302   void lock();
303   void unlock();
304 
305   void scan();
306   void scan_area();
307   void scan_area_pm();
308 
309   int load_hdr(gmsg* msg);
310   int load_msg(gmsg* msg);
311 
312   void save_hdr(int mode, gmsg* msg);
313   void save_msg(int mode, gmsg* msg);
314 
315   void del_msg(gmsg* msg);
316 
317   void new_msgno(gmsg* msg);
318   char* user_lookup(char* lookfor);
319   int renumber();
320 
321   void update_timesread(gmsg* msg);
322 
323   Line* make_dump_msg(Line*& lin, gmsg* msg, char* lng_head);
324 };
325 
326 
327 //  ------------------------------------------------------------------
328 
329 extern SqshData* squishdata;
330 extern SqshWide* squishwide;
331 extern int       squishdatano;
332 
333 
334 //  ------------------------------------------------------------------
335 //  Squish scanning types
336 
337 const int SQS_API   = 1;
338 const int SQS_QUICK = 2;
339 
340 
341 //  ------------------------------------------------------------------
342 //  Squish recycling types
343 
344 const int SQUISHRECYCLE_NO      = false;
345 const int SQUISHRECYCLE_YES     = true;
346 const int SQUISHRECYCLE_MSGAPI1 = SQUISHRECYCLE_YES + 1;
347 const int SQUISHRECYCLE_MSGAPI2 = SQUISHRECYCLE_YES + 2;
348 
349 
350 //  ------------------------------------------------------------------
351 
352 #endif
353 
354 //  ------------------------------------------------------------------
355 
356