1 #ifndef __STRUCTS__H
2 #define __STRUCTS__H
3 
4 #include <stdlib.h>             // size_t
5 
6                                 // Class for reading and writing structures
7                                 // that reside on disk in a way that is more
8                                 // portable than just doing
9                                 // fread(..,sizeof(sturcture),..).
10 
11 #include "buffer.hpp"
12 
13 class DiskRecord
14 {
15 public:
16 
DiskRecord()17     DiskRecord() {} ;
~DiskRecord()18     virtual ~DiskRecord() {} ;
19 
20     virtual size_t get_filesize(void) = 0;
21     virtual void   Import(const unsigned char *buffer) = 0;
22     virtual void   Export(unsigned char *buffer) = 0;
23 
24     int    read(FILE *f);
25     int    read(C_FileRead &);
26     int    write(FILE *f);
27 };
28 
29 class S_MSG: public DiskRecord
30 {
31 public:
32 
33     char FromUserName[36];
34     char ToUserName[36];
35     char Subject[72];
36     char DateTime[20];
37     unsigned short TimesRead;
38     unsigned short DestNode;
39     unsigned short OrigNode;
40     unsigned short Cost;
41     unsigned short OrigNet;
42     unsigned short DestNet;
43     char Fill[8];
44     unsigned short ReplyTo;
45     unsigned short Attribute;
46     unsigned short NextReply;
47 
48                                 // member functions for endian-safe and
49                                 // architecture-independent reading and writing
50 
get_filesize(void)51     size_t get_filesize(void) { return 190; }
52     void   Import(const unsigned char *buffer);
53     void   Export(unsigned char *buffer);
54 };
55 
56 #define S_Private(x)              (((x) & 1) ? 1 : 0)
57 #define S_Crash(x)                (((x) & 2) ? 1 : 0)
58 #define S_Recd(x)                 (((x) & 4) ? 1 : 0)
59 #define S_Sent(x)                 (((x) & 8) ? 1 : 0)
60 #define S_FileAttached(x)         (((x) & 16) ? 1 : 0)
61 #define S_InTransit(x)            (((x) & 32) ? 1 : 0)
62 #define S_Orphan(x)               (((x) & 64) ? 1 : 0)
63 #define S_KillSent(x)             (((x) & 128) ? 1 : 0)
64 #define S_Local(x)                (((x) & 256) ? 1 : 0)
65 #define S_Hold(x)                 (((x) & 512) ? 1 : 0)
66 #define S_Unused(x)               (((x) & 1024) ? 1 : 0)
67 #define S_FileRequest(x)          (((x) & 2048) ? 1 : 0)
68 #define S_ReturnReceiptRequest(x) (((x) & 4096) ? 1 : 0)
69 #define S_IsReturnReceipt(x)      (((x) & 8192) ? 1 : 0)
70 #define S_AuditRequest(x)         (((x) & 16384) ? 1 : 0)
71 #define S_FileUpdateReq(x)        (((x) & 32768U) ? 1 : 0)
72 
73 #define Set_Private(x,y)              {if (y) (x)|=     1; else (x) &= ~1;    }
74 #define Set_Crash(x,y)                {if (y) (x)|=     2; else (x) &= ~2;    }
75 #define Set_Recd(x,y)                 {if (y) (x)|=     4; else (x) &= ~4;    }
76 #define Set_Sent(x,y)                 {if (y) (x)|=     8; else (x) &= ~8;    }
77 #define Set_FileAttached(x,y)         {if (y) (x)|=    16; else (x) &= ~16;   }
78 #define Set_InTransit(x,y)            {if (y) (x)|=    32; else (x) &= ~32;   }
79 #define Set_Orphan(x,y)               {if (y) (x)|=    64; else (x) &= ~64;   }
80 #define Set_KillSent(x,y)             {if (y) (x)|=   128; else (x) &= ~128;  }
81 #define Set_Local(x,y)                {if (y) (x)|=   256; else (x) &= ~256;  }
82 #define Set_Hold(x,y)                 {if (y) (x)|=   512; else (x) &= ~512;  }
83 #define Set_Unused(x,y)               {if (y) (x)|=  1024; else (x) &= ~1024; }
84 #define Set_FileRequest(x,y)          {if (y) (x)|=  2048; else (x) &= ~2048; }
85 #define Set_ReturnReceiptRequest(x,y) {if (y) (x)|=  4096; else (x) &= ~4096; }
86 #define Set_IsReturnReceipt(x,y)      {if (y) (x)|=  8192; else (x) &= ~8192; }
87 #define Set_AuditRequest(x,y)         {if (y) (x)|= 16384; else (x) &= ~16384;}
88 #define Set_FileUpdateReq(x,y)        {if (y) (x)|= 32768; else (x) &= ~32768;}
89 
90 #define S_ArchiveSent(x)          (((x) & 1) ? 1 : 0)
91 #define S_KillFileSent(x)         (((x) & 2) ? 1 : 0)
92 #define S_Direct(x)               (((x) & 4) ? 1 : 0)
93 #define S_Zonegate(x)             (((x) & 8) ? 1 : 0)
94 #define S_Hub(x)                  (((x) & 16) ? 1 : 0)
95 #define S_Immediate(x)            (((x) & 32) ? 1 : 0)
96 #define S_XMA(x)                  (((x) & 64) ? 1 : 0)
97 #define S_Lock(x)                 (((x) & 128) ? 1 : 0)
98 #define S_Truncate(x)             (((x) & 256) ? 1 : 0)
99 #define S_HiRes(x)                (((x) & 512) ? 1 : 0)
100 #define S_CoverLetter(x)          (((x) & 1024) ? 1 : 0)
101 #define S_Signature(x)            (((x) & 2048) ? 1 : 0)
102 #define S_LetterHead(x)           (((x) & 4096) ? 1 : 0)
103 #define S_Fax(x)                  (((x) & 8192) ? 1 : 0)
104 #define S_ForcePickup(x)          (((x) & 16384) ? 1 : 0)
105 #define S_Unused2(x)              (((x) & 32768U) ? 1 : 0)
106 
107 #define Set_ArchiveSent(x,y)          {if (y) (x)|=     1; else (x) &= ~1;    }
108 #define Set_KillFileSent(x,y)         {if (y) (x)|=     2; else (x) &= ~2;    }
109 #define Set_Direct(x,y)               {if (y) (x)|=     4; else (x) &= ~4;    }
110 #define Set_Zonegate(x,y)             {if (y) (x)|=     8; else (x) &= ~8;    }
111 #define Set_Hub(x,y)                  {if (y) (x)|=    16; else (x) &= ~16;   }
112 #define Set_Immediate(x,y)            {if (y) (x)|=    32; else (x) &= ~32;   }
113 #define Set_XMA(x,y)                  {if (y) (x)|=    64; else (x) &= ~64;   }
114 #define Set_Lock(x,y)                 {if (y) (x)|=   128; else (x) &= ~128;  }
115 #define Set_Truncate(x,y)             {if (y) (x)|=   256; else (x) &= ~256;  }
116 #define Set_HiRes(x,y)                {if (y) (x)|=   512; else (x) &= ~512;  }
117 #define Set_CoverLetter(x,y)          {if (y) (x)|=  1024; else (x) &= ~1024; }
118 #define Set_Signature(x,y)            {if (y) (x)|=  2048; else (x) &= ~2048; }
119 #define Set_LetterHead(x,y)           {if (y) (x)|=  4096; else (x) &= ~4096; }
120 #define Set_Fax(x,y)                  {if (y) (x)|=  8192; else (x) &= ~8192; }
121 #define Set_ForcePickup(x,y)          {if (y) (x)|= 16384; else (x) &= ~16384;}
122 #define Set_Unused2(x,y)              {if (y) (x)|= 32768; else (x) &= ~32768;}
123 
124 class S_PKT: public DiskRecord
125 {
126 public:
127 	unsigned short OrigNode;
128 	unsigned short DestNode;
129 	unsigned short Year;
130 	unsigned short Month;
131 	unsigned short Day;
132 	unsigned short Hour;
133 	unsigned short Minute;
134 	unsigned short Second;
135 	unsigned short Baud;
136 	unsigned short Signature;
137 	unsigned short OrigNet;
138 	unsigned short DestNet;
139 	char ProdCode,SerialNo;
140 	char Password[8];
141 	unsigned short OrigZone;
142 	unsigned short DestZone;
143 	union
144 	{
145 		char Fill[20];
146 		struct
147 		{
148 			char Fill[2];
149 			unsigned short CapabilitySwapped;
150 			char PrdCodH;
151 			char PVMinor;
152 			unsigned short Capability;
153 			unsigned short OrigZone;
154 			unsigned short DestZone;
155 			unsigned short OrigPoint;
156 			unsigned short DestPoint;
157 			char ProdData[4];
158 		} t2plus;
159 	} dif;
160 	char EndOfPKT[2];
161 
162                                 // member functions for endian-safe and
163                                 // architecture-independent reading and writing
164 
get_filesize(void)165     size_t get_filesize(void) { return 60 ; }
166     void   Import(const unsigned char *buffer);
167     void   Export(unsigned char *buffer);
168 };
169 
170 
171 class S_Packed: public DiskRecord
172 {
173 public:
174     unsigned short Signature;
175     unsigned short OrigNode;
176     unsigned short DestNode;
177     unsigned short OrigNet;
178     unsigned short DestNet;
179     unsigned short Attrib;
180     unsigned short Cost;
181     char DateTime[20];
182                                 // member functions for endian-safe and
183                                 // architecture-independent reading and writing
184 
get_filesize(void)185     size_t get_filesize(void) { return 34 ; }
186     void   Import(const unsigned char *buffer);
187     void   Export(unsigned char *buffer);
188 
189 };
190 
191 
192 
193 class DateTime: public DiskRecord
194 {
195 public:
196     unsigned char hours;
197     unsigned char minutes;
198     unsigned char seconds;
199     unsigned char hundredths;
200     unsigned char day;
201     unsigned char month;
202     unsigned short year;
203     short 	 timezone;
204     unsigned char weekday;
205 
206                                 // arch-dependent function to fill the struct
207 
208     void getCurrentTime(void);
209 
210                                 // member functions for endian-safe and
211                                 // architecture-independent reading and writing
212 
get_filesize(void)213     size_t get_filesize(void) { return 11 ; }
214     void   Import(const unsigned char *buffer);
215     void   Export(unsigned char *buffer);
216 
217 };
218 #endif
219