1 /* 2 JAMLIB - A JAM subroutine library 3 Copyright (C) 1999 Bj�rn Stenberg 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 Changes made by Johan Billing 2000-04-16: 20 21 - Added #defines for JAM_NO_MESSAGE and JAM_CORRUPT_MSG 22 - Added #ifndef linux around typedefs for ushort, ulong and uchar 23 - Added prototype for JAM_AddEmptyMessage() 24 25 Changes made by Sir Raorn 2001-12-08: 26 27 - Added prototype for JAM_DeleteMessage() 28 */ 29 30 /*********************************************************************** 31 ** 32 ** JAM Definitions 33 ** 34 ***********************************************************************/ 35 36 #ifndef __JAM_H__ 37 #define __JAM_H__ 38 39 #if (defined(__unix__) || defined(unix) || defined(__MACH__)) && !defined(USG) 40 #include <sys/param.h> 41 #endif 42 43 #include <stdlib.h> 44 #include <stdio.h> 45 #include <sys/types.h> 46 #include <ctype.h> 47 48 #if !defined(linux) 49 #if !(((defined(__FreeBSD__) && __FreeBSD_version >= 440000)) || defined(NeXTBSD)) 50 typedef unsigned short ushort; /* must be 16 bits wide */ 51 #endif 52 typedef unsigned long ulong; /* must be 32 bits wide */ 53 #endif 54 typedef unsigned char uchar; /* must be 8 bits wide */ 55 56 /* 57 ** Error codes {{{ 58 */ 59 #define JAM_BAD_PARAM 1 /* one or more parameters are wrong */ 60 #define JAM_IO_ERROR 2 /* i/o error. check JAM_Errno() for details */ 61 #define JAM_LOCK_FAILED 3 /* lock could not be set */ 62 #define JAM_NOT_LOCKED 4 /* the message base was not locked before writing */ 63 #define JAM_NO_MEMORY 5 /* out of memory! */ 64 #define JAM_NO_USER 6 /* user not found */ 65 #define JAM_NO_MESSAGE 7 /* message has been deleted */ 66 #define JAM_CORRUPT_MSG 8 /* message header is corrupt */ 67 /* 68 ** }}} 69 */ 70 71 /* 72 ** CRC definitions {{{ 73 */ 74 #define JAM_NO_CRC 0xffffffff 75 /* 76 ** }}} 77 */ 78 79 /* 80 ** File extensions {{{ 81 */ 82 #define EXT_HDRFILE ".jhr" 83 #define EXT_TXTFILE ".jdt" 84 #define EXT_IDXFILE ".jdx" 85 #define EXT_LRDFILE ".jlr" 86 /* 87 ** }}} 88 */ 89 90 /* 91 ** Revision level and header signature {{{ 92 */ 93 #define CURRENTREVLEV 1 94 #define HEADERSIGNATURE "JAM\0" 95 /* 96 ** }}} 97 */ 98 99 /* 100 ** Header file information block, stored first in all .JHR files {{{ 101 */ 102 typedef struct { 103 uchar Signature[4]; /* <J><A><M> followed by <NUL> */ 104 ulong DateCreated; /* Creation date */ 105 ulong ModCounter; /* Last processed counter */ 106 ulong ActiveMsgs; /* Number of active (not deleted) msgs */ 107 ulong PasswordCRC; /* CRC-32 of password to access */ 108 ulong BaseMsgNum; /* Lowest message number in index file */ 109 uchar RSRVD[1000]; /* Reserved space */ 110 } s_JamBaseHeader; 111 /* 112 ** }}} 113 */ 114 115 /* 116 ** Message status bits {{{ 117 */ 118 #define MSG_LOCAL 0x00000001L /* Msg created locally */ 119 #define MSG_INTRANSIT 0x00000002L /* Msg is in-transit */ 120 #define MSG_PRIVATE 0x00000004L /* Private */ 121 #define MSG_READ 0x00000008L /* Read by addressee */ 122 #define MSG_SENT 0x00000010L /* Sent to remote */ 123 #define MSG_KILLSENT 0x00000020L /* Kill when sent */ 124 #define MSG_ARCHIVESENT 0x00000040L /* Archive when sent */ 125 #define MSG_HOLD 0x00000080L /* Hold for pick-up */ 126 #define MSG_CRASH 0x00000100L /* Crash */ 127 #define MSG_IMMEDIATE 0x00000200L /* Send Msg now, ignore restrictions */ 128 #define MSG_DIRECT 0x00000400L /* Send directly to destination */ 129 #define MSG_GATE 0x00000800L /* Send via gateway */ 130 #define MSG_FILEREQUEST 0x00001000L /* File request */ 131 #define MSG_FILEATTACH 0x00002000L /* File(s) attached to Msg */ 132 #define MSG_TRUNCFILE 0x00004000L /* Truncate file(s) when sent */ 133 #define MSG_KILLFILE 0x00008000L /* Delete file(s) when sent */ 134 #define MSG_RECEIPTREQ 0x00010000L /* Return receipt requested */ 135 #define MSG_CONFIRMREQ 0x00020000L /* Confirmation receipt requested */ 136 #define MSG_ORPHAN 0x00040000L /* Unknown destination */ 137 #define MSG_ENCRYPT 0x00080000L /* Msg text is encrypted */ 138 #define MSG_COMPRESS 0x00100000L /* Msg text is compressed */ 139 #define MSG_ESCAPED 0x00200000L /* Msg text is seven bit ASCII */ 140 #define MSG_FPU 0x00400000L /* Force pickup */ 141 #define MSG_TYPELOCAL 0x00800000L /* Msg is for local use only (no export) */ 142 #define MSG_TYPEECHO 0x01000000L /* Msg is for conference distribution */ 143 #define MSG_TYPENET 0x02000000L /* Msg is direct network mail */ 144 #define MSG_NODISP 0x20000000L /* Msg may not be displayed to user */ 145 #define MSG_LOCKED 0x40000000L /* Msg is locked, no editing possible */ 146 #define MSG_DELETED 0x80000000L /* Msg is deleted */ 147 /* 148 ** }}} 149 */ 150 151 /* 152 ** Message header {{{ 153 */ 154 typedef struct { 155 uchar Signature[4]; /* <J><A><M> followed by <NUL> */ 156 ushort Revision; /* CURRENTREVLEV */ 157 ushort ReservedWord; /* Reserved */ 158 ulong SubfieldLen; /* Length of Subfields */ 159 ulong TimesRead; /* Number of times message read */ 160 ulong MsgIdCRC; /* CRC-32 of MSGID line */ 161 ulong ReplyCRC; /* CRC-32 of REPLY line */ 162 ulong ReplyTo; /* This msg is a reply to.. */ 163 ulong Reply1st; /* First reply to this msg */ 164 ulong ReplyNext; /* Next msg in reply chain */ 165 ulong DateWritten; /* When msg was written */ 166 ulong DateReceived; /* When msg was received/read */ 167 ulong DateProcessed; /* When msg was processed by packer */ 168 ulong MsgNum; /* Message number (1-based) */ 169 ulong Attribute; /* Msg attribute, see "Status bits" */ 170 ulong Attribute2; /* Reserved for future use */ 171 ulong TxtOffset; /* Offset of text in text file */ 172 ulong TxtLen; /* Length of message text */ 173 ulong PasswordCRC; /* CRC-32 of password to access msg */ 174 ulong Cost; /* Cost of message */ 175 } s_JamMsgHeader; 176 /* 177 ** }}} 178 */ 179 180 /* 181 ** Message header Subfield types {{{ 182 */ 183 #define JAMSFLD_OADDRESS 0 184 #define JAMSFLD_DADDRESS 1 185 #define JAMSFLD_SENDERNAME 2 186 #define JAMSFLD_RECVRNAME 3 187 #define JAMSFLD_MSGID 4 188 #define JAMSFLD_REPLYID 5 189 #define JAMSFLD_SUBJECT 6 190 #define JAMSFLD_PID 7 191 #define JAMSFLD_TRACE 8 192 #define JAMSFLD_ENCLFILE 9 193 #define JAMSFLD_ENCLFWALIAS 10 194 #define JAMSFLD_ENCLFREQ 11 195 #define JAMSFLD_ENCLFILEWC 12 196 #define JAMSFLD_ENCLINDFILE 13 197 #define JAMSFLD_EMBINDAT 1000 198 #define JAMSFLD_FTSKLUDGE 2000 199 #define JAMSFLD_SEENBY2D 2001 200 #define JAMSFLD_PATH2D 2002 201 #define JAMSFLD_FLAGS 2003 202 #define JAMSFLD_TZUTCINFO 2004 203 #define JAMSFLD_UNKNOWN 0xFFFF 204 /* 205 ** }}} 206 */ 207 208 /* 209 ** Message header Subfield {{{ 210 */ 211 typedef struct { 212 ushort LoID; /* Field ID, 0 - 0xffff */ 213 ushort HiID; /* Reserved for future use */ 214 ulong DatLen; /* Length of buffer that follows */ 215 uchar* Buffer; /* DatLen bytes of data */ 216 } s_JamSubfield; 217 218 typedef struct { 219 ushort LoID; /* Field ID, 0 - 0xffff */ 220 ushort HiID; /* Reserved for future use */ 221 ulong DatLen; /* Length of buffer that follows */ 222 } s_JamSaveSubfield; 223 /* 224 ** }}} 225 */ 226 227 /* 228 ** Message index record {{{ 229 */ 230 typedef struct { 231 ulong UserCRC; /* CRC-32 of destination username */ 232 ulong HdrOffset; /* Offset of header in .JHR file */ 233 } s_JamIndex; 234 /* 235 ** }}} 236 */ 237 238 /* 239 ** Lastread structure, one per user {{{ 240 */ 241 typedef struct { 242 ulong UserCRC; /* CRC-32 of user name (lowercase) */ 243 ulong UserID; /* Unique UserID */ 244 ulong LastReadMsg; /* Last read message number */ 245 ulong HighReadMsg; /* Highest read message number */ 246 } s_JamLastRead; 247 /* 248 ** }}} 249 */ 250 251 /* 252 ** JAMLIB message base handle {{{ 253 */ 254 typedef struct { 255 FILE* HdrFile_PS; /* File handle for .JHR file */ 256 FILE* TxtFile_PS; /* File handle for .JDT file */ 257 FILE* IdxFile_PS; /* File handle for .JDX file */ 258 FILE* LrdFile_PS; /* File handle for .JLR file */ 259 int Errno_I; /* last i/o error */ 260 int Locked_I; /* is area locked? */ 261 ulong LastUserPos_I; /* last position of lastread record */ 262 ulong LastUserId_I; /* userid for the last read lastread record */ 263 } s_JamBase; 264 /* 265 ** }}} 266 */ 267 268 /* 269 ** JAMLIB subfield packet {{{ 270 */ 271 typedef struct { 272 s_JamSubfield** Fields; 273 ulong NumFields; 274 ulong NumAlloc; 275 } s_JamSubPacket; 276 /* 277 ** }}} 278 */ 279 280 /* 281 ** JAMLIB function declarations {{{ 282 */ 283 284 /* mbase.c {{{ */ 285 int JAM_OpenMB ( uchar* Basename_PC, 286 s_JamBase** NewArea_PPS ); 287 288 int JAM_CloseMB ( s_JamBase* Area_PS ); 289 290 int JAM_CreateMB ( uchar* Basename_PC, 291 ulong BaseMsg_I, 292 s_JamBase** NewArea_PPS ); 293 294 int JAM_RemoveMB ( s_JamBase* Area_PS, 295 uchar* Basename_PC ); 296 297 int JAM_LockMB ( s_JamBase* Area_PS, 298 int Timeout_I ); 299 300 int JAM_UnlockMB ( s_JamBase* Area_PS ); 301 302 int JAM_ReadMBHeader ( s_JamBase* Area_PS, 303 s_JamBaseHeader* Header_PS ); 304 305 int JAM_WriteMBHeader ( s_JamBase* Area_PS, 306 s_JamBaseHeader* Header_PS ); 307 308 int JAM_FindUser ( s_JamBase* Area_PS, 309 ulong UserCrc_I, 310 ulong StartMsg_I, 311 ulong* MsgNo_PI ); 312 313 int JAM_GetMBSize ( s_JamBase* Area_PS, 314 ulong* Messages_PI ); 315 /* }}} */ 316 317 /* message.c {{{ */ 318 int JAM_ReadMsgHeader ( s_JamBase* Area_PS, 319 ulong MsgNo_I, 320 s_JamMsgHeader* Header_PS, 321 s_JamSubPacket** SubfieldPack_PPS ); 322 323 int JAM_ReadMsgText ( s_JamBase* Area_PS, 324 ulong Offset_I, 325 ulong Length_I, 326 uchar* Buffer_PC ); 327 328 int JAM_AddMessage ( s_JamBase* Area_PS, 329 s_JamMsgHeader* Header_PS, 330 s_JamSubPacket* SubPack_PS, 331 uchar* Text_PC, 332 ulong TextLen_I ); 333 334 int JAM_AddEmptyMessage ( s_JamBase* Area_PS ); 335 336 int JAM_DeleteMessage ( s_JamBase* Base_PS, 337 ulong MsgNo_I ); 338 339 int JAM_ChangeMsgHeader ( s_JamBase* Area_PS, 340 ulong MsgNo_I, 341 s_JamMsgHeader* Header_PS ); 342 343 int JAM_ClearMsgHeader ( s_JamMsgHeader* Header_PS ); 344 345 int JAM_Errno ( s_JamBase* Area_PS ); 346 /* }}} */ 347 348 /* lastread.c {{{ */ 349 int JAM_ReadLastRead ( s_JamBase* Area_PS, 350 ulong User_I, 351 s_JamLastRead* Record_PS ); 352 353 int JAM_WriteLastRead ( s_JamBase* Area_PS, 354 ulong User_I, 355 s_JamLastRead* Record_PS ); 356 /* }}} */ 357 358 /* subpacket.c {{{ */ 359 s_JamSubPacket* JAM_NewSubPacket ( void ); 360 361 int JAM_DelSubPacket ( s_JamSubPacket* SubPack_PS ); 362 363 s_JamSubfield* JAM_GetSubfield ( s_JamSubPacket* SubPack_PS ); 364 365 s_JamSubfield* JAM_GetSubfield_R ( s_JamSubPacket* SubPack_PS , 366 ulong* Count_PI); 367 368 int JAM_PutSubfield ( s_JamSubPacket* SubPack_PS, 369 s_JamSubfield* Field_PS ); 370 /* }}} */ 371 372 /* crc32.c {{{ */ 373 ulong JAM_Crc32 ( uchar* Buffer_PC, ulong Length_I ); 374 /* }}} */ 375 376 /* 377 ** }}} 378 */ 379 #endif 380 /* Local variables: 381 * vim:set ts=8 sts=4 sw=4: 382 * vim600:fdm=marker: 383 */ 384