home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / sqdev200.zip / h / api_sq.h < prev    next >
C/C++ Source or Header  |  1994-05-23  |  14KB  |  321 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  Squish Developers Kit Source, Version 2.00                             *
  4.  *  Copyright 1989-1994 by SCI Communications.  All rights reserved.       *
  5.  *                                                                         *
  6.  *  USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE       *
  7.  *  SQUISH DEVELOPERS KIT LICENSING AGREEMENT IN SQDEV.PRN.  IF YOU DO NOT *
  8.  *  FIND THE TEXT OF THIS AGREEMENT IN THE AFOREMENTIONED FILE, OR IF YOU  *
  9.  *  DO NOT HAVE THIS FILE, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT    *
  10.  *  ONE OF THE ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO  *
  11.  *  USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE SQUISH          *
  12.  *  DEVELOPERS KIT LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE *
  13.  *  ABLE TO REACH WITH THE AUTHOR.                                         *
  14.  *                                                                         *
  15.  *  You can contact the author at one of the address listed below:         *
  16.  *                                                                         *
  17.  *  Scott Dudley       FidoNet     1:249/106                               *
  18.  *  777 Downing St.    Internet    sjd@f106.n249.z1.fidonet.org            *
  19.  *  Kingston, Ont.     CompuServe  >INTERNET:sjd@f106.n249.z1.fidonet.org  *
  20.  *  Canada  K7M 5N3    BBS         1-613-634-3058, V.32bis                 *
  21.  *                                                                         *
  22.  ***************************************************************************/
  23.  
  24. /* $Id: API_SQ.H 1.4 1994/01/09 22:27:54 sjd Exp sjd $ */
  25.  
  26. #ifndef __API_SQ_H_DEFINED
  27. #define __API_SQ_H_DEFINED
  28.  
  29. struct _sqhdr;
  30. struct _sqidx;
  31.  
  32. typedef struct _sqidx SQIDX;
  33. typedef struct _sqhdr SQHDR;
  34. typedef long FOFS;
  35.  
  36.  
  37. /* Try to access a locked Squish base up to five times */
  38.  
  39. #define SQUISH_LOCK_RETRY 5
  40.  
  41.  
  42. /* Expand the Squish index by 64 records at a time */
  43.  
  44. #define SQUIQSH_IDX_EXPAND    64
  45.  
  46.  
  47. /* No frame offset */
  48.  
  49. #define NULL_FRAME      ((FOFS)0L)
  50.  
  51.  
  52. /* Frame types for sqhdr.frame_type */
  53.  
  54. #define FRAME_NORMAL    0x00  /* Normal text frame */
  55. #define FRAME_FREE      0x01  /* Part of the free chain */
  56. #define FRAME_LZSS      0x02  /* Not implemented */
  57. #define FRAME_UPDATE    0x03  /* Frame is being updated by another task */
  58.  
  59. /* BItmask for sqidx.hash to indicate that the msg was received */
  60.  
  61. #define IDXE_MSGREAD    0x80000000Lu
  62.  
  63. /* Macros for accessing the hidden parts of data structures */
  64.  
  65. #define Sqd ((SQDATA *)(ha->apidata))
  66. #define HSqd ((SQDATA *)(((struct _msgh OS2FAR *)hmsg)->ha->apidata))
  67.  
  68.  
  69. /* Squish frame header.  This comes before each and every message in a      *
  70.  * Squish message base.                                                     */
  71.  
  72. struct _sqhdr
  73. {
  74.   #define SQHDRID       0xafae4453L
  75.  
  76.   dword id;             /* sqhdr.id must always equal SQHDRID */
  77.  
  78.   FOFS next_frame;      /* Next frame in the linked list */
  79.   FOFS prev_frame;      /* Prior frame in the linked list */
  80.  
  81.   dword frame_length;   /* Length of this frame */
  82.   dword msg_length;     /* Length used in this frame by XMSG, ctrl and text */
  83.   dword clen;           /* Length used in this frame by ctrl info only */
  84.  
  85.   word frame_type;      /* Type of frame -- see above FRAME_XXXX */
  86.   word rsvd;            /* Reserved for future use */
  87. };
  88.  
  89.  
  90.  
  91. /* An individual index entry in <area>.SQI */
  92.  
  93. struct _sqidx
  94. {
  95.   FOFS ofs;                   /* Offset of the frame relating to this msg */
  96.   UMSGID umsgid;              /* Unique message identifier of this msg */
  97.   dword hash;                 /* SquishHash of msg.to for this msg */
  98. };
  99.  
  100.  
  101. /* Header block at offset 0 of <area>.SQD */
  102.  
  103. typedef struct _sqbase
  104. {
  105.   word len;               /* LENGTH OF THIS STRUCTURE! */           /*   0 */
  106.   word rsvd1;             /* reserved */                            /*   2 */
  107.  
  108.   dword num_msg;          /* Number of messages in area */          /*   4 */
  109.   dword high_msg;         /* Highest msg in area. Same as num_msg*/ /*   8 */
  110.   dword skip_msg;         /* Skip killing first x msgs in area */   /*  12 */
  111.   dword high_water;       /* Msg# (not umsgid) of HWM */            /*  16 */
  112.  
  113.   dword uid;              /* Number of the next UMSGID to use */    /*  20 */
  114.  
  115.   byte base[80];          /* Base name of SquishFile */             /*  24 */
  116.  
  117.   FOFS begin_frame;       /* Offset of first frame in file */       /* 104 */
  118.   FOFS last_frame;        /* Offset to last frame in file */        /* 108 */
  119.   FOFS free_frame;        /* Offset of first FREE frame in file */  /* 112 */
  120.   FOFS last_free_frame;   /* Offset of last free frame in file */   /* 116 */
  121.   FOFS end_frame;         /* Pointer to end of file */              /* 120 */
  122.  
  123.   dword max_msg;          /* Max # of msgs to keep in area */       /* 124 */
  124.   word keep_days;         /* Max age of msgs in area (SQPack) */    /* 128 */
  125.   word sz_sqhdr;          /* sizeof(SQHDR) */                       /* 130 */
  126.   byte rsvd2[124];        /* Reserved by Squish for future use*/    /* 132 */
  127.                                                              /* total: 256 */
  128. } SQBASE;
  129.  
  130.  
  131. typedef struct
  132. {
  133.   dword dwUsed;             /* Number of entries used in this seg */
  134.   dword dwMax;              /* Number of entries allocated in this seg */
  135.  
  136.   SQIDX far *psqi;          /* Pointer to index entries for this segment */
  137. } SQIDXSEG;
  138.  
  139.  
  140. /* Handle to a Squish index file */
  141.  
  142. typedef struct
  143. {
  144.   #define ID_HIDX 0x9fee
  145.  
  146.   word id;                            /* Must be ID_HIDX */
  147.   HAREA ha;                           /* Area to which this index belongs */
  148.  
  149.   long lAllocatedRecords;             /* Space allocated in idx file */
  150.   long lDeltaLo;                      /* Low # of changed msg */
  151.   long lDeltaHi;                      /* High # of changed msg */
  152.  
  153.   int fBuffer;                        /* Use index buffer? */
  154.   int cSeg;                           /* Number of segments used */
  155.   SQIDXSEG *pss;                      /* Segments containing messages */
  156. } *HIDX;
  157.  
  158.  
  159.  
  160. /* Private data in handle passed among API functions which handle message   *
  161.  * areas.                                                                   */
  162.  
  163. typedef struct _sqdata
  164. {
  165.   word cbSqbase;          /* Length of the .SQD file header */
  166.   word cbSqhdr;           /* Length of a .SQD frame header */
  167.  
  168.   dword dwMaxMsg;         /* Max number of msgs in area */
  169.   word wMaxDays;          /* Max age (in days) of msgs in area */
  170.   word wSkipMsg;          /* Number of msgs to skip before keeping wMaxMsg */
  171.  
  172.   dword dwHighWater;      /* High water message NUMBER */
  173.   UMSGID uidNext;         /* Next UMSGID to assign */
  174.  
  175.   FOFS foFirst;           /* Offset of first frame in file */
  176.   FOFS foLast;            /* Offset to last frame in file */
  177.   FOFS foFree;            /* Offset of first FREE frame in file */
  178.   FOFS foLastFree;        /* Offset of last free frame in file */
  179.   FOFS foEnd;             /* Pointer to end of file */
  180.  
  181.   FOFS foNext;            /* Next frame in the linked list */
  182.   FOFS foPrev;            /* Prior frame in the linked list */
  183.   FOFS foCur;             /* Current frame position */
  184.  
  185.   word fHaveExclusive;    /* Are we currently updating the base header? */
  186.   word fLocked;           /* Do we have byte 0 locked? */
  187.   word fLockFunc;         /* Number of times we have called Lock w/o Unlock */
  188.  
  189.   int sfd;                /* SquishFile handle */
  190.   int ifd;                /* SquishIndex handle */
  191.  
  192.   SQBASE sqbDelta;        /* Last _sqbase read from .SQD file */
  193.  
  194.   /* Linked lists indicating open resources */
  195.  
  196.   HAREA haNext;           /* Next area in the list of open areas */
  197.   HMSG hmsgOpen;          /* List of open messages */
  198.   HIDX hix;               /* Index handle for current base */
  199. } SQDATA;
  200.  
  201.  
  202. /* Message handle.  This is passed back and forth between all of the        *
  203.  * API functions that handle specific messages.                             */
  204.  
  205. struct _msgh
  206. {
  207.   HAREA ha;                   /* Area to which this message belongs */
  208.   dword id;                   /* Must always equal MSGH_ID */
  209.  
  210.   dword bytes_written;        /* Bytes written to this msg so far */
  211.   dword cur_pos;              /* Current read posn within msg */
  212.  
  213.   /* Squish-specific information starts here */
  214.  
  215.   dword dwMsg;                /* This message number */
  216.  
  217.   /* Frame offset of this message, IF we are reading a message.             *
  218.    *                                                                        *
  219.    * However, if we are writing a message, this may hold one of             *
  220.    * several things, depending on the value of wMode:                       *
  221.    *                                                                        *
  222.    *                                                                        *
  223.    * wMode==MOPEN_CREATE:  If we are writing a completely new message,      *
  224.    *                       this field is zero.  Otherwise, if we are        *
  225.    *                       creating a message on top of an existing         *
  226.    *                       message, this will hold the frame offset of      *
  227.    *                       the old message.                                 *
  228.    * wMode==MOPEN_RW       This holds the offset of the message that        *
  229.    *    or  MOPEN_WRITE    we are rewriting (same as foWrite)               */
  230.  
  231.   FOFS foRead;
  232.  
  233.   /* SQHDR used when reading.                                               *
  234.    *                                                                        *
  235.    * If writing, this will hold the frame header of the message that we     *
  236.    * replaced.  (We only replaced a message if foRead != NULL_FRAME)        */
  237.  
  238.   SQHDR sqhRead;
  239.  
  240.   /* If we are writing a message, this holds the offset of the current      *
  241.    * frame header.  If no frame header has been allocated for the message   *
  242.    * yet, this field will be NULL_FRAME.                                    */
  243.  
  244.   FOFS foWrite;
  245.  
  246.   /* If we are writing a message, this holds the frame that we wrote.  This *
  247.    * SQHDR is only valid when foWrite != NULL_FRAME.                        */
  248.  
  249.   SQHDR sqhWrite;
  250.  
  251.   /* If we know the UMSGID for this message, uidUs is non-zero */
  252.  
  253.   UMSGID uidUs;
  254.  
  255.   dword dwWritePos;           /* Current write position */
  256.   word wMode;                 /* MOPEN_READ, MOPEN_WRITE, or MOPEN_RW */
  257.   word fDiskErr;              /* Has a disk error occurred? */
  258.   word fWritten;              /* Have we already written to this message? */
  259.   HMSG hmsgNext;              /* Next msg in the list of open msgs */
  260. };
  261.  
  262.  
  263.  
  264. /* Squish function prototypes */
  265.  
  266. sword MAPIENTRY SquishCloseArea(HAREA sq);
  267. HMSG  MAPIENTRY SquishOpenMsg(HAREA sq,word mode,dword msgnum);
  268. sword MAPIENTRY SquishCloseMsg(HMSG msgh);
  269. dword MAPIENTRY SquishReadMsg(HMSG msgh, PXMSG msg, dword offset, dword bytes,
  270.                               byte OS2FAR *szText, dword clen, byte OS2FAR *ctxt);
  271. sword MAPIENTRY SquishWriteMsg(HMSG msgh,word append,PXMSG msg,byte OS2FAR *text,dword textlen,dword totlen,dword clen,byte OS2FAR *ctxt);
  272. sword MAPIENTRY SquishKillMsg(HAREA sq,dword msgnum);
  273. sword MAPIENTRY SquishLock(HAREA sq);
  274. sword MAPIENTRY SquishUnlock(HAREA sq);
  275. sword MAPIENTRY SquishSetCurPos(HMSG msgh,dword pos);
  276. dword MAPIENTRY SquishGetCurPos(HMSG msgh);
  277. UMSGID MAPIENTRY SquishMsgnToUid(HAREA sq,dword msgnum);
  278. dword MAPIENTRY SquishUidToMsgn(HAREA sq,UMSGID umsgid,word type);
  279. dword MAPIENTRY SquishGetHighWater(HAREA mh);
  280. sword MAPIENTRY SquishSetHighWater(HAREA sq,dword hwm);
  281. dword MAPIENTRY SquishGetTextLen(HMSG msgh);
  282. dword MAPIENTRY SquishGetCtrlLen(HMSG msgh);
  283. UMSGID MAPIENTRY SquishGetNextUid(HAREA ha);
  284.  
  285. /* Private functions */
  286.  
  287. unsigned _SquishReadMode(HMSG hmsg);
  288. unsigned _SquishWriteMode(HMSG hmsg);
  289. unsigned _SquishCopyBaseToData(HAREA ha, SQBASE *psqb);
  290. unsigned _SquishWriteBaseHeader(HAREA ha, SQBASE *psqb);
  291. unsigned _SquishReadBaseHeader(HAREA ha, SQBASE *psqb);
  292. unsigned _SquishExclusiveBegin(HAREA ha);
  293. unsigned _SquishExclusiveEnd(HAREA ha);
  294. unsigned _SquishCopyDataToBase(HAREA ha, SQBASE *psqb);
  295. unsigned _SquishReadHdr(HAREA ha, FOFS fo, SQHDR *psqh);
  296. unsigned _SquishWriteHdr(HAREA ha, FOFS fo, SQHDR *psqh);
  297. /*unsigned _SquishReadIndexRecord(HAREA ha, dword dwMsg, SQIDX *psqi);*/
  298. /*unsigned _SquishWriteIndexRecord(HAREA ha, dword dwMsg, SQIDX *psqi);*/
  299. FOFS _SquishGetFrameOfs(HAREA ha, dword dwMsg);
  300. /*unsigned _SquishRemoveIndex(HAREA ha, dword dwMsg, SQIDX *psqiOut, SQHDR *psqh);*/
  301. unsigned _SquishSetFrameNext(HAREA ha, FOFS foModify, FOFS foValue);
  302. unsigned _SquishSetFramePrev(HAREA ha, FOFS foModify, FOFS foValue);
  303. unsigned _SquishInsertFreeChain(HAREA ha, FOFS fo, SQHDR *psqh);
  304. /*SQIDX * _SquishAllocIndex(HAREA ha, dword dwMsg, dword *pdwIdxSize);*/
  305. /*unsigned _SquishFreeIndex(HAREA ha, dword dwMsg, SQIDX *psqi,
  306.                           dword dwIdxSize, unsigned fWrite);*/
  307.  
  308. HIDX _SquishOpenIndex(HAREA ha);
  309. int _SquishBeginBuffer(HIDX hix);
  310. int SidxGet(HIDX hix, dword dwMsg, SQIDX *psqi);
  311. int SidxPut(HIDX hix, dword dwMsg, SQIDX *psqi);
  312. unsigned _SquishRemoveIndexEntry(HIDX hix, dword dwMsg, SQIDX *psqiOut,
  313.                                  SQHDR *psqh, int fFixPointers);
  314. unsigned _SquishCloseIndex(HIDX hix);
  315. int _SquishEndBuffer(HIDX hix);
  316. dword _SquishIndexSize(HIDX hix);
  317. unsigned _SquishFixMemoryPointers(HAREA ha, dword dwMsg, SQHDR *psqh);
  318.  
  319. #endif /* __API_SQ_H_DEFINED */
  320.  
  321.