jam.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. JAMLIB - A JAM subroutine library
  3. Copyright (C) 1999 Björn Stenberg
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Changes made by Johan Billing 2000-04-16:
  16. - Added #defines for JAM_NO_MESSAGE and JAM_CORRUPT_MSG
  17. - Added #ifndef linux around typedefs for uint16_t and uint32_t
  18. - Added prototype for JAM_AddEmptyMessage()
  19. Backported changes from JAMLIB 1.4.7 made by Johan Billing 2003-10-26
  20. - Added prototype for JAM_DeleteMessage()
  21. */
  22. /***********************************************************************
  23. **
  24. ** JAM Definitions
  25. **
  26. ***********************************************************************/
  27. #ifndef __JAM_H__
  28. #define __JAM_H__
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <ctype.h>
  32. #include <stdint.h>
  33. /*
  34. ** Error codes
  35. */
  36. #define JAM_BAD_PARAM 1 /* one or more parameters are wrong */
  37. #define JAM_IO_ERROR 2 /* i/o error. check JAM_Errno() for details */
  38. #define JAM_LOCK_FAILED 3 /* lock could not be set */
  39. #define JAM_NOT_LOCKED 4 /* the message base was not locked before writing */
  40. #define JAM_NO_MEMORY 5 /* out of memory! */
  41. #define JAM_NO_USER 6 /* user not found */
  42. #define JAM_NO_MESSAGE 7 /* message has been deleted */
  43. #define JAM_CORRUPT_MSG 8 /* message header is corrupt */
  44. /*
  45. ** CRC definitions
  46. */
  47. #define JAM_NO_CRC 0xffffffff
  48. /*
  49. ** File extensions
  50. */
  51. #define EXT_HDRFILE ".jhr"
  52. #define EXT_TXTFILE ".jdt"
  53. #define EXT_IDXFILE ".jdx"
  54. #define EXT_LRDFILE ".jlr"
  55. /*
  56. ** Revision level and header signature
  57. */
  58. #define CURRENTREVLEV 1
  59. #define HEADERSIGNATURE "JAM\0"
  60. /*
  61. ** Header file information block, stored first in all .JHR files
  62. */
  63. typedef struct {
  64. char Signature[4]; /* <J><A><M> followed by <NUL> */
  65. uint32_t DateCreated; /* Creation date */
  66. uint32_t ModCounter; /* Last processed counter */
  67. uint32_t ActiveMsgs; /* Number of active (not deleted) msgs */
  68. uint32_t PasswordCRC; /* CRC-32 of password to access */
  69. uint32_t BaseMsgNum; /* Lowest message number in index file */
  70. char RSRVD[1000]; /* Reserved space */
  71. } s_JamBaseHeader;
  72. /*
  73. ** Message status bits
  74. */
  75. #define JAM_MSG_LOCAL 0x00000001L /* Msg created locally */
  76. #define JAM_MSG_INTRANSIT 0x00000002L /* Msg is in-transit */
  77. #define JAM_MSG_PRIVATE 0x00000004L /* Private */
  78. #define JAM_MSG_READ 0x00000008L /* Read by addressee */
  79. #define JAM_MSG_SENT 0x00000010L /* Sent to remote */
  80. #define JAM_MSG_KILLSENT 0x00000020L /* Kill when sent */
  81. #define JAM_MSG_ARCHIVESENT 0x00000040L /* Archive when sent */
  82. #define JAM_MSG_HOLD 0x00000080L /* Hold for pick-up */
  83. #define JAM_MSG_CRASH 0x00000100L /* Crash */
  84. #define JAM_MSG_IMMEDIATE 0x00000200L /* Send Msg now, ignore restrictions */
  85. #define JAM_MSG_DIRECT 0x00000400L /* Send directly to destination */
  86. #define JAM_MSG_GATE 0x00000800L /* Send via gateway */
  87. #define JAM_MSG_FILEREQUEST 0x00001000L /* File request */
  88. #define JAM_MSG_FILEATTACH 0x00002000L /* File(s) attached to Msg */
  89. #define JAM_MSG_TRUNCFILE 0x00004000L /* Truncate file(s) when sent */
  90. #define JAM_MSG_KILLFILE 0x00008000L /* Delete file(s) when sent */
  91. #define JAM_MSG_RECEIPTREQ 0x00010000L /* Return receipt requested */
  92. #define JAM_MSG_CONFIRMREQ 0x00020000L /* Confirmation receipt requested */
  93. #define JAM_MSG_ORPHAN 0x00040000L /* Unknown destination */
  94. #define JAM_MSG_ENCRYPT 0x00080000L /* Msg text is encrypted */
  95. #define JAM_MSG_COMPRESS 0x00100000L /* Msg text is compressed */
  96. #define JAM_MSG_ESCAPED 0x00200000L /* Msg text is seven bit ASCII */
  97. #define JAM_MSG_FPU 0x00400000L /* Force pickup */
  98. #define JAM_MSG_TYPELOCAL 0x00800000L /* Msg is for local use only (no export) */
  99. #define JAM_MSG_TYPEECHO 0x01000000L /* Msg is for conference distribution */
  100. #define JAM_MSG_TYPENET 0x02000000L /* Msg is direct network mail */
  101. #define JAM_MSG_NODISP 0x20000000L /* Msg may not be displayed to user */
  102. #define JAM_MSG_LOCKED 0x40000000L /* Msg is locked, no editing possible */
  103. #define JAM_MSG_DELETED 0x80000000L /* Msg is deleted */
  104. /*
  105. ** Message header
  106. */
  107. typedef struct {
  108. char Signature[4]; /* <J><A><M> followed by <NUL> */
  109. uint16_t Revision; /* CURRENTREVLEV */
  110. uint16_t ReservedWord; /* Reserved */
  111. uint32_t SubfieldLen; /* Length of Subfields */
  112. uint32_t TimesRead; /* Number of times message read */
  113. uint32_t MsgIdCRC; /* CRC-32 of MSGID line */
  114. uint32_t ReplyCRC; /* CRC-32 of REPLY line */
  115. uint32_t ReplyTo; /* This msg is a reply to.. */
  116. uint32_t Reply1st; /* First reply to this msg */
  117. uint32_t ReplyNext; /* Next msg in reply chain */
  118. uint32_t DateWritten; /* When msg was written */
  119. uint32_t DateReceived; /* When msg was received/read */
  120. uint32_t DateProcessed; /* When msg was processed by packer */
  121. uint32_t MsgNum; /* Message number (1-based) */
  122. uint32_t Attribute; /* Msg attribute, see "Status bits" */
  123. uint32_t Attribute2; /* Reserved for future use */
  124. uint32_t TxtOffset; /* Offset of text in text file */
  125. uint32_t TxtLen; /* Length of message text */
  126. uint32_t PasswordCRC; /* CRC-32 of password to access msg */
  127. uint32_t Cost; /* Cost of message */
  128. } s_JamMsgHeader;
  129. /*
  130. ** Message header Subfield types
  131. */
  132. #define JAMSFLD_OADDRESS 0
  133. #define JAMSFLD_DADDRESS 1
  134. #define JAMSFLD_SENDERNAME 2
  135. #define JAMSFLD_RECVRNAME 3
  136. #define JAMSFLD_MSGID 4
  137. #define JAMSFLD_REPLYID 5
  138. #define JAMSFLD_SUBJECT 6
  139. #define JAMSFLD_PID 7
  140. #define JAMSFLD_TRACE 8
  141. #define JAMSFLD_ENCLFILE 9
  142. #define JAMSFLD_ENCLFWALIAS 10
  143. #define JAMSFLD_ENCLFREQ 11
  144. #define JAMSFLD_ENCLFILEWC 12
  145. #define JAMSFLD_ENCLINDFILE 13
  146. #define JAMSFLD_EMBINDAT 1000
  147. #define JAMSFLD_FTSKLUDGE 2000
  148. #define JAMSFLD_SEENBY2D 2001
  149. #define JAMSFLD_PATH2D 2002
  150. #define JAMSFLD_FLAGS 2003
  151. #define JAMSFLD_TZUTCINFO 2004
  152. #define JAMSFLD_UNKNOWN 0xffff
  153. /*
  154. ** Message header Subfield
  155. */
  156. typedef struct {
  157. uint16_t LoID; /* Field ID, 0 - 0xffff */
  158. uint16_t HiID; /* Reserved for future use */
  159. uint32_t DatLen; /* Length of buffer that follows */
  160. char* Buffer; /* DatLen bytes of data */
  161. } s_JamSubfield;
  162. typedef struct {
  163. uint16_t LoID; /* Field ID, 0 - 0xffff */
  164. uint16_t HiID; /* Reserved for future use */
  165. uint32_t DatLen; /* Length of buffer that follows */
  166. } s_JamSaveSubfield;
  167. /*
  168. ** Message index record
  169. */
  170. typedef struct {
  171. uint32_t UserCRC; /* CRC-32 of destination username */
  172. uint32_t HdrOffset; /* Offset of header in .JHR file */
  173. } s_JamIndex;
  174. /*
  175. ** Lastread structure, one per user
  176. */
  177. typedef struct {
  178. uint32_t UserCRC; /* CRC-32 of user name (lowercase) */
  179. uint32_t UserID; /* Unique UserID */
  180. uint32_t LastReadMsg; /* Last read message number */
  181. uint32_t HighReadMsg; /* Highest read message number */
  182. } s_JamLastRead;
  183. /*
  184. ** JAMLIB message base handle
  185. */
  186. typedef struct {
  187. FILE* HdrFile_PS; /* File handle for .JHR file */
  188. FILE* TxtFile_PS; /* File handle for .JDT file */
  189. FILE* IdxFile_PS; /* File handle for .JDX file */
  190. FILE* LrdFile_PS; /* File handle for .JLR file */
  191. int Errno_I; /* last i/o error */
  192. int Locked_I; /* is area locked? */
  193. uint32_t LastUserPos_I; /* last position of lastread record */
  194. uint32_t LastUserId_I; /* userid for the last read lastread record */
  195. } s_JamBase;
  196. /*
  197. ** JAMLIB subfield packet
  198. */
  199. typedef struct {
  200. s_JamSubfield** Fields;
  201. uint32_t NumFields;
  202. uint32_t NumAlloc;
  203. } s_JamSubPacket;
  204. /*
  205. ** JAMLIB function declarations
  206. */
  207. /* mbase.c */
  208. int JAM_OpenMB ( char* Basename_PC,
  209. s_JamBase** NewArea_PPS );
  210. int JAM_CloseMB ( s_JamBase* Area_PS );
  211. int JAM_CreateMB ( char* Basename_PC,
  212. uint32_t BaseMsg_I,
  213. s_JamBase** NewArea_PPS );
  214. int JAM_RemoveMB ( s_JamBase* Area_PS,
  215. char* Basename_PC );
  216. int JAM_LockMB ( s_JamBase* Area_PS,
  217. int Timeout_I );
  218. int JAM_UnlockMB ( s_JamBase* Area_PS );
  219. int JAM_ReadMBHeader ( s_JamBase* Area_PS,
  220. s_JamBaseHeader* Header_PS );
  221. int JAM_WriteMBHeader ( s_JamBase* Area_PS,
  222. s_JamBaseHeader* Header_PS );
  223. int JAM_FindUser ( s_JamBase* Area_PS,
  224. uint32_t UserCrc_I,
  225. uint32_t StartMsg_I,
  226. uint32_t* MsgNo_PI );
  227. int JAM_GetMBSize ( s_JamBase* Area_PS,
  228. uint32_t* Messages_PI );
  229. /* message.c */
  230. int JAM_ReadMsgHeader ( s_JamBase* Area_PS,
  231. uint32_t MsgNo_I,
  232. s_JamMsgHeader* Header_PS,
  233. s_JamSubPacket** SubfieldPack_PPS );
  234. int JAM_ReadMsgText ( s_JamBase* Area_PS,
  235. uint32_t Offset_I,
  236. uint32_t Length_I,
  237. char* Buffer_PC );
  238. int JAM_AddMessage ( s_JamBase* Area_PS,
  239. s_JamMsgHeader* Header_PS,
  240. s_JamSubPacket* SubPack_PS,
  241. char* Text_PC,
  242. uint32_t TextLen_I );
  243. int JAM_AddEmptyMessage ( s_JamBase* Area_PS );
  244. int JAM_DeleteMessage ( s_JamBase* Base_PS,
  245. uint32_t MsgNo_I );
  246. int JAM_ChangeMsgHeader ( s_JamBase* Area_PS,
  247. uint32_t MsgNo_I,
  248. s_JamMsgHeader* Header_PS );
  249. int JAM_ClearMsgHeader ( s_JamMsgHeader* Header_PS );
  250. int JAM_Errno ( s_JamBase* Area_PS );
  251. /* lastread.c */
  252. int JAM_ReadLastRead ( s_JamBase* Area_PS,
  253. uint32_t User_I,
  254. s_JamLastRead* Record_PS );
  255. int JAM_WriteLastRead ( s_JamBase* Area_PS,
  256. uint32_t User_I,
  257. s_JamLastRead* Record_PS );
  258. /* subpacket.c */
  259. s_JamSubPacket* JAM_NewSubPacket ( void );
  260. int JAM_DelSubPacket ( s_JamSubPacket* SubPack_PS );
  261. s_JamSubfield* JAM_GetSubfield ( s_JamSubPacket* SubPack_PS );
  262. s_JamSubfield* JAM_GetSubfield_R ( s_JamSubPacket* SubPack_PS ,
  263. uint32_t* Count_PI);
  264. int JAM_PutSubfield ( s_JamSubPacket* SubPack_PS,
  265. s_JamSubfield* Field_PS );
  266. /* crc32.c */
  267. uint32_t JAM_Crc32 ( char* Buffer_PC, uint32_t Length_I );
  268. #endif