home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / msgapi38.zip / INCLUDE / MSGAPI.H < prev    next >
C/C++ Source or Header  |  1995-05-27  |  14KB  |  399 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  MSGAPI Source Code, Version 2.00                                       *
  4.  *  Copyright 1989-1991 by Scott J. Dudley.  All rights reserved.          *
  5.  *                                                                         *
  6.  *  MsgAPI main header file                                                *
  7.  *                                                                         *
  8.  *  For complete details of the licensing restrictions, please refer to    *
  9.  *  the licence agreement, which is published in its entirety in           *
  10.  *  README.1ST.                                                            *
  11.  *                                                                         *
  12.  *  USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE       *
  13.  *  MSGAPI LICENSING AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF THIS       *
  14.  *  AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO NOT HAVE    *
  15.  *  THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT ONE OF THE   *
  16.  *  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO USE THIS    *
  17.  *  FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE MSGAPI LICENSING         *
  18.  *  AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH THE   *
  19.  *  AUTHOR.                                                                *
  20.  *                                                                         *
  21.  *  You can contact the author at one of the address listed below:         *
  22.  *                                                                         *
  23.  *  Scott Dudley           FidoNet  1:249/106                              *
  24.  *  777 Downing St.        Internet f106.n249.z1.fidonet.org               *
  25.  *  Kingston, Ont.         BBS      (613) 389-8315   HST/14.4k, 24hrs      *
  26.  *  Canada - K7M 5N3                                                       *
  27.  *                                                                         *
  28.  ***************************************************************************/
  29.  
  30. /* $Id: msgapi.h_v 1.0 1991/11/16 16:16:51 sjd Rel sjd $ */
  31.  
  32. #ifndef __SQAPI_H_DEFINED
  33. #define __SQAPI_H_DEFINED
  34.  
  35. /* #define TSR*/
  36.  
  37. #include "stamp.h"
  38. #include "typedefs.h"
  39. #include "compiler.h"
  40.  
  41. #define MSGAPI
  42.  
  43. #if defined(OS_2)
  44.   #ifndef EXPENTRY
  45.     #define EXPENTRY pascal far
  46.   #endif
  47.     
  48.   #define OS2LOADDS
  49. #else
  50.   #define EXPENTRY pascal
  51.   #define OS2LOADDS
  52. #endif
  53.  
  54.  
  55. #define MSGAREA_NORMAL  0x00
  56. #define MSGAREA_CREATE  0x01
  57. #define MSGAREA_CRIFNEC 0x02
  58.  
  59. #define MSGTYPE_SDM     0x01
  60. #define MSGTYPE_SQUISH  0x02
  61. #define MSGTYPE_ECHO    0x80
  62.  
  63. #define MSGNUM_CUR      ((dword)-1L)
  64. #define MSGNUM_PREV     ((dword)-2L)
  65. #define MSGNUM_NEXT     ((dword)-3L)
  66.  
  67. #define MSGNUM_current  MSGNUM_CUR
  68. #define MSGNUM_previous MSGNUM_PREV
  69. #define MSGNUM_next     MSGNUM_NEXT
  70.  
  71. #define MOPEN_CREATE    0
  72. #define MOPEN_READ      1
  73. #define MOPEN_WRITE     2
  74. #define MOPEN_RW        3
  75.  
  76. struct _msgapi;
  77. struct _msgh;
  78. struct _netaddr;
  79.  
  80. typedef struct _msgapi MSG;
  81. typedef struct _msgh MSGH;
  82. typedef dword UMSGID;
  83. typedef struct _netaddr NETADDR;
  84.  
  85.  
  86.  
  87. struct _minf
  88. {
  89.   word req_version;
  90.   word def_zone;
  91.   word haveshare;  /* filled in by msgapi routines - no need to set this */
  92. };
  93.  
  94.  
  95. /* The network address structure.  The z/n/n/p fields are always             *
  96.  * maintained in parallel to the 'ascii' field, which is simply an ASCII     *
  97.  * representation of the address.  In addition, the 'ascii' field can        *
  98.  * be used for other purposes (such as internet addresses), so the           *
  99.  * contents of this field are implementation-defined, but for most cases,    *
  100.  * should be in the format "1:123/456.7" for Fido addresses.                 */
  101.  
  102. struct _netaddr
  103. {
  104.   word zone;
  105.   word net;
  106.   word node;
  107.   word point;
  108. };
  109.  
  110.  
  111. /* The eXtended message structure.  Translation between this structure, and *
  112.  * the structure used by the individual message base formats, is done       *
  113.  * on-the-fly by the API routines.                                          */
  114.  
  115. typedef struct
  116. {
  117.   dword attr;
  118.  
  119.   /* Bitmasks for 'attr' */
  120.  
  121.   #define MSGPRIVATE 0x0001
  122.   #define MSGCRASH   0x0002
  123.   #define MSGREAD    0x0004
  124.   #define MSGSENT    0x0008
  125.   #define MSGFILE    0x0010
  126.   #define MSGFWD     0x0020
  127.   #define MSGORPHAN  0x0040
  128.   #define MSGKILL    0x0080
  129.   #define MSGLOCAL   0x0100
  130.   #define MSGHOLD    0x0200
  131.   #define MSGXX2     0x0400
  132.   #define MSGFRQ     0x0800
  133.   #define MSGRRQ     0x1000
  134.   #define MSGCPT     0x2000
  135.   #define MSGARQ     0x4000
  136.   #define MSGURQ     0x8000
  137.   #define MSGSCANNED 0x00010000L
  138.  
  139.  
  140.   #define XMSG_FROM_SIZE  36
  141.   #define XMSG_TO_SIZE    36
  142.   #define XMSG_SUBJ_SIZE  72
  143.  
  144.   byte from[XMSG_FROM_SIZE];
  145.   byte to[XMSG_TO_SIZE];
  146.   byte subj[XMSG_SUBJ_SIZE];
  147.  
  148.   NETADDR orig;        /* Origination and destination addresses             */
  149.   NETADDR dest;
  150.  
  151.   struct _stamp date_written;   /* When user wrote the msg (UTC)            */
  152.   struct _stamp date_arrived;   /* When msg arrived on-line (UTC)           */
  153.   sword utc_ofs;                /* Offset from UTC of message writer, in    *
  154.                                  * minutes.                                 */
  155.  
  156.   #define MAX_REPLY 10          /* Max number of stored replies to one msg  */
  157.  
  158.   UMSGID replyto;
  159.   UMSGID replies[MAX_REPLY];
  160.  
  161.   byte __ftsc_date[20];  /* Obsolete date information.  If it weren't for the *
  162.                         * fact that FTSC standards say that one cannot      *
  163.                         * modify an in-transit message, I'd be VERY         *
  164.                         * tempted to axe this field entirely, and recreate  *
  165.                         * an FTSC-compatible date field using               *
  166.                         * the information in 'date_written' upon            *
  167.                         * export.  Nobody should use this field, except     *
  168.                         * possibly for tossers and scanners.  All others    *
  169.                         * should use one of the two binary datestamps,      *
  170.                         * above.                                            */
  171. } XMSG;
  172.  
  173.  
  174.  
  175.  
  176.  
  177. /* This is a 'message area handle', as returned by MsgOpenArea(), and       *
  178.  * required by calls to all other message functions.  This structure        *
  179.  * must always be accessed through the API functions, and never             *
  180.  * modified directly.                                                       */
  181.  
  182. struct _msgapi
  183. {
  184.   #define MSGAPI_ID   0x0201414dL
  185.     
  186.   dword id;                       /* Must always equal MSGAPI_ID */
  187.  
  188.   word len;                       /* LENGTH OF THIS STRUCTURE! */
  189.   word type;
  190.  
  191.   dword num_msg;
  192.   dword cur_msg;
  193.   dword high_msg;
  194.   dword high_water;
  195.  
  196.   word sz_xmsg;
  197.  
  198.   byte locked;                    /* Base is locked from use by other tasks */
  199.   byte isecho;                    /* Is this an EchoMail area?              */
  200.  
  201.   /* Function pointers for manipulating messages within this area.          */
  202.   struct _apifuncs
  203.   {
  204.     sword  (EXPENTRY * CloseArea)(MSG *mh);
  205.     MSGH * (EXPENTRY * OpenMsg)  (MSG *mh,word mode,dword n);
  206.     sword  (EXPENTRY * CloseMsg) (MSGH *msgh);
  207.     dword  (EXPENTRY * ReadMsg)  (MSGH *msgh, XMSG *msg, dword ofs,
  208.                                 dword bytes, byte *text, dword cbyt,
  209.                                 byte *ctxt);
  210.     sword  (EXPENTRY * WriteMsg) (MSGH *msgh,word append,XMSG *msg,
  211.                                 byte *text, dword textlen, dword totlen,
  212.                                 dword clen, byte *ctxt);
  213.     sword  (EXPENTRY * KillMsg)  (MSG *mh, dword msgnum);
  214.     sword  (EXPENTRY * Lock)     (MSG *mh);
  215.     sword  (EXPENTRY * Unlock)   (MSG *mh);
  216.     sword  (EXPENTRY * SetCurPos)(MSGH *msgh, dword pos);
  217.     dword  (EXPENTRY * GetCurPos)(MSGH *msgh);
  218.     UMSGID (EXPENTRY * MsgnToUid)(MSG *mh, dword msgnum);
  219.     dword  (EXPENTRY * UidToMsgn)(MSG *mh,UMSGID umsgid,word type);
  220.     dword  (EXPENTRY * GetHighWater)(MSG *mh);
  221.     sword  (EXPENTRY * SetHighWater)(MSG *mh, dword hwm);
  222.     dword  (EXPENTRY * GetTextLen)(MSGH *msgh);
  223.     dword  (EXPENTRY * GetCtrlLen)(MSGH *msgh);
  224.   } *api;
  225.  
  226.   /* Pointer to application-specific data.  API_SQ.C and API_SDM.C use      *
  227.    * this for different things, so again, no applications should muck       *
  228.    * with anything in here.                                                 */
  229.  
  230.   void /*far*/ *apidata;
  231. };
  232.  
  233.  
  234.  
  235.  
  236. /* This is a 'dummy' message handle.  The other message handlers (contained *
  237.  * in API_SQ.C and API_SDM.C) will define their own structures, with some   *
  238.  * application-specified variables instead of other[].  Applications should *
  239.  * not mess with anything inside the _msgh (or MSGH) structure.             */
  240.  
  241. #define MSGH_ID  0x0302484dL
  242.  
  243. #if !defined(MSGAPI_HANDLERS) && !defined(NO_MSGH_DEF)
  244. struct _msgh
  245. {
  246.   MSG *sq;
  247.   dword id;
  248.  
  249.   dword bytes_written;
  250.   dword cur_pos;
  251. };
  252. #endif
  253.  
  254.  
  255.  
  256. #include "api_brow.h"
  257.  
  258.  
  259.  
  260.  
  261.  
  262. /* This variable is modified whenever an error occurs with the Msg...()     *
  263.  * functions.  If msgapierr==0, then no error occurred.                     */
  264.  
  265. extern word _stdc msgapierr;
  266. /*extern word _stdc haveshare;*/
  267. extern struct _minf _stdc mi;
  268.  
  269. #ifdef TSR
  270.   #define IMS_ID    0x4453u
  271.   #define IMS_INTR  0x32
  272. #endif
  273.  
  274. #if defined(TSR) && defined(MSGAPI_PROC)
  275.   extern void * (_stdc *memalloc)(word len);
  276.   extern void (_stdc *memfree)(void *block);
  277.  
  278.   #define palloc(s)     (*memalloc)(s)
  279.   #define pfree(s)      (*memfree)(s)
  280.   #define farpalloc(s)  palloc(s)
  281.   #define farpfree(s)   pfree(s)
  282. #else
  283.   #define palloc(s)     malloc(s)
  284.   #define pfree(s)      free(s)
  285.   #define farpalloc(s)  farmalloc(s)
  286.   #define farpfree(s)   farfree(s)
  287. #endif
  288.  
  289.  
  290. /* Constants for 'type' argument of MsgUidToMsgn() */
  291.  
  292. #define UID_EXACT     0x00
  293. #define UID_NEXT      0x01
  294. #define UID_PREV      0x02
  295.  
  296.  
  297. /* Values for 'msgapierr', above. */
  298.  
  299. #define MERR_NONE   0     /* No error                                       */
  300. #define MERR_BADH   1     /* Invalid handle passed to function              */
  301. #define MERR_BADF   2     /* Invalid or corrupted file                      */
  302. #define MERR_NOMEM  3     /* Not enough memory for specified operation      */
  303. #define MERR_NODS   4     /* Maybe not enough disk space for operation      */
  304. #define MERR_NOENT  5     /* File/message does not exist                    */
  305. #define MERR_BADA   6     /* Bad argument passed to msgapi function         */
  306. #define MERR_EOPEN  7     /* Couldn't close - messages still open           */
  307.  
  308.  
  309. /* Now, a set of macros, which call the specified API function.  These      *
  310.  * will map calls for 'MsgOpenMsg()' into 'SquishOpenMsg()',                *
  311.  * 'SdmOpenMsg()', or '<insert fave message type here>'.  Applications      *
  312.  * should always call these macros, instead of trying to call the           *
  313.  * manipulation functions directly.                                         */
  314.  
  315. #define MsgCloseArea(mh)       (*(mh)->api->CloseArea) (mh)
  316. #define MsgOpenMsg(mh,mode,n)  (*(mh)->api->OpenMsg)          (mh,mode,n)
  317. #define MsgCloseMsg(msgh)      ((*(((struct _msgh *)msgh)->sq->api->CloseMsg))(msgh))
  318. #define MsgReadMsg(msgh,msg,ofs,b,t,cl,ct) (*(((struct _msgh *)msgh)->sq->api->ReadMsg))(msgh,msg,ofs,b,t,cl,ct)
  319. #define MsgWriteMsg(gh,a,m,t,tl,ttl,cl,ct) (*(((struct _msgh *)gh)->sq->api->WriteMsg))(gh,a,m,t,tl,ttl,cl,ct)
  320. #define MsgKillMsg(mh,msgnum)  (*(mh)->api->KillMsg)(mh,msgnum)
  321. #define MsgLock(mh)            (*(mh)->api->Lock)(mh)
  322. #define MsgUnlock(mh)          (*(mh)->api->Unlock)(mh)
  323. #define MsgGetCurPos(msgh)     (*(((struct _msgh *)msgh)->sq->api->GetCurPos))(msgh)
  324. #define MsgSetCurPos(msgh,pos) (*(((struct _msgh *)msgh)->sq->api->SetCurPos))(msgh,pos)
  325. #define MsgMsgnToUid(mh,msgn)  (*(mh)->api->MsgnToUid)(mh,msgn)
  326. #define MsgUidToMsgn(mh,umsgid,t) (*(mh)->api->UidToMsgn)(mh,umsgid,t)
  327. #define MsgGetHighWater(mh)   (*(mh)->api->GetHighWater)(mh)
  328. #define MsgSetHighWater(mh,n) (*(mh)->api->SetHighWater)(mh,n)
  329. #define MsgGetTextLen(msgh)   (*(((struct _msgh *)msgh)->sq->api->GetTextLen))(msgh)
  330. #define MsgGetCtrlLen(msgh)   (*(((struct _msgh *)msgh)->sq->api->GetCtrlLen))(msgh)
  331.  
  332. /* These don't actually call any functions, but are macros used to access    *
  333.  * private data inside the _msgh structure.                                  */
  334.  
  335. #define MsgCurMsg(mh)         ((mh)->cur_msg)
  336. #define MsgNumMsg(mh)         ((mh)->num_msg)
  337. #define MsgHighMsg(mh)        ((mh)->high_msg)
  338.  
  339. #define MsgGetCurMsg(mh)      ((mh)->cur_msg)
  340. #define MsgGetNumMsg(mh)      ((mh)->num_msg)
  341. #define MsgGetHighMsg(mh)     ((mh)->high_msg)
  342.  
  343. sword EXPENTRY MsgOpenApi(struct _minf *minf);
  344. sword EXPENTRY MsgCloseApi(void);
  345.  
  346. MSG * EXPENTRY MsgOpenArea(byte *name,word mode,word type);
  347. sword EXPENTRY MsgValidate(word type,byte *name);
  348. sword EXPENTRY MsgBrowseArea(BROWSE *b);
  349.  
  350. sword MSGAPI InvalidMsgh(MSGH *msgh);
  351. sword MSGAPI InvalidMh(MSG *mh);
  352.  
  353. void EXPENTRY SquishSetMaxMsg(MSG *sq, dword max_msgs, dword skip_msgs, dword age);
  354. dword EXPENTRY SquishHash(byte *f);
  355.  
  356.  
  357.  
  358. MSG * MSGAPI SdmOpenArea(byte *name,word mode,word type);
  359. sword MSGAPI SdmValidate(byte *name);
  360.  
  361. MSG * MSGAPI SquishOpenArea(byte *name,word mode,word type);
  362. sword MSGAPI SquishValidate(byte *name);
  363.  
  364.  
  365. byte * EXPENTRY CvtCtrlToKludge(byte *ctrl);
  366. byte * EXPENTRY GetCtrlToken(byte *where,byte *what);
  367. byte * EXPENTRY CopyToControlBuf(byte *txt, byte **newtext, unsigned *length);
  368. void EXPENTRY ConvertControlInfo(byte *ctrl,NETADDR *orig,NETADDR *dest);
  369. word EXPENTRY NumKludges(char *txt);
  370. void EXPENTRY RemoveFromCtrl(byte *ctrl,byte *what);
  371.  
  372. #if !(defined(OS_2))
  373. sword far pascal farread(sword handle,byte far *buf,word len);
  374. sword far pascal farwrite(sword handle,byte far *buf,word len);
  375. #endif
  376. byte * _fast Address(NETADDR *a);
  377. byte * StripNasties(byte *str);
  378.  
  379. #ifdef __MSDOS__
  380.   sword far pascal shareloaded(void);
  381. #else
  382.   #define shareloaded() TRUE
  383. #endif
  384.  
  385. #if defined(__IBMC__) || defined(__EMX__) || defined(__WATCOMC__)
  386.   #pragma pack()
  387. #elif defined(__BORLANDC__)
  388.   #pragma option -a.
  389. #elif defined(__WATCOMC__)
  390.   #pragma pack()
  391. #endif
  392.  
  393. #endif
  394.  
  395.  
  396.  
  397.  
  398.  
  399.