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