home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / mapi / win16 / dev / sample.ms / msp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  26.9 KB  |  827 lines

  1. /*
  2.  *  M S P . H
  3.  *
  4.  *  Definitions for the MAPI Sample Message Store Provider.
  5.  *
  6.  *  Copyright 1992-1995 Microsoft Corporation.  All Rights Reserved.
  7.  */
  8.  
  9. #ifdef WIN32
  10. #define _INC_OLE
  11. #define INC_OLE2 /* Get the OLE2 stuff */
  12. #define INC_RPC  /* harmless on NT 3.5; Win95 needs it */
  13. #endif
  14.  
  15. #include <windows.h>
  16. #include <ole2.h>
  17.  
  18. #include <mapispi.h>
  19. #include <mapidbg.h>
  20. #include <mapiwin.h>
  21. #include <mapiutil.h>
  22. #include <mapival.h>
  23. #include <smpms.h>
  24.  
  25. #include <mapidefs.h>
  26. #include <mapicode.h>
  27. #include <mapitags.h>
  28. #include <mapiguid.h>
  29.  
  30. #include <imessage.h>
  31.  
  32. #include <limits.h>
  33. #include <memory.h>
  34.  
  35. #if defined(WIN32)
  36. #define OLE_CHAR WCHAR
  37. #else
  38. #define OLE_CHAR char
  39. #endif
  40.  
  41. #define VALIDATE
  42.  
  43. #ifdef VALIDATE
  44. #define OBJ_ValidateParameters(pobj, eMethod, cbObj, _lpVtbl)               \
  45.     {   ValidateParameters(eMethod, (LPVOID)&pobj);                         \
  46.         if (IsBadWritePtr(pobj, cbObj) || (pobj)->lpVtbl != _lpVtbl)        \
  47.             return(ResultFromScode(MAPI_E_INVALID_PARAMETER)); }
  48.  
  49. #define OBJ_CheckParameters(pobj, eMethod, cbObj, _lpVtbl)                  \
  50.     {   CheckParameters(eMethod, (LPVOID)&pobj);                            \
  51.         AssertSz(!IsBadWritePtr(pobj, cbObj) && (pobj)->lpVtbl == _lpVtbl,  \
  52.             "Bad object pointer"); }
  53. #else
  54. #define OBJ_ValidateParameters(pobj, eMethod, cbObj, lpVtbl)
  55. #define OBJ_CheckParameters(pobj, eMethod, cbObj, lpVtbl)
  56. #endif /* VALIDATE */
  57.  
  58. typedef LPVOID *PPV;
  59.  
  60. #define NUM_RETRIES 6           /* number of times to retry opening a file */
  61.  
  62. /* Per-instance data. */
  63. typedef struct
  64. {
  65.     UINT        cRef;
  66.     LPMALLOC    lpmalloc;
  67. } INST, *PINST;
  68.  
  69. /* Linked Memory Routines */
  70. typedef struct _lmr
  71. {
  72.     LPALLOCATEBUFFER    lpAllocBuf;
  73.     LPALLOCATEMORE      lpAllocMore;
  74.     LPFREEBUFFER        lpFreeBuf;
  75. }   LMR, *PLMR;
  76.  
  77. #define         LMAlloc(plmr, lcb, ppv)             ((plmr)->lpAllocBuf(lcb, ppv))
  78. #define         LMAllocMore(plmr, lcb, pvLink, ppv) ((plmr)->lpAllocMore(lcb, pvLink, ppv))
  79. #define         LMFree(plmr, pv)                    ((plmr)->lpFreeBuf(pv))
  80.  
  81. #define IsBadIfacePtr(param, iface)                 \
  82.             (IsBadReadPtr((param), sizeof(iface))   \
  83.         ||  IsBadReadPtr((param)->lpVtbl, sizeof(iface##Vtbl)))
  84.  
  85. #define SMPMS_VERSION   (0x03)  /* For MAPI 1.0 */
  86.  
  87. typedef struct _EID             /* Sample Message Store EntryID */
  88. {
  89.     BYTE abFlags[4];
  90.     MAPIUID uidResource;
  91.     BYTE bVersion;
  92.     BYTE bVerPad[3];
  93.     TCHAR szPath[1];
  94. } EID, *PEID;
  95.  
  96. #define CbNewEID(_cbPath) \
  97.     (offsetof(EID,szPath) + (_cbPath)*sizeof(CHAR))
  98.  
  99. /* This includes the NULL terminator */
  100. #define CbEID(_peid) \
  101.     (offsetof(EID,szPath) + \
  102.     (((UINT)(lstrlen((_peid)->szPath)))*sizeof(CHAR)) + sizeof(CHAR))
  103.  
  104. /* This includes the NULL */
  105. #define CbEIDPath(peid) (CbEID(peid)-CbNewEID(0))
  106.  
  107. #define PR_FILENAME_SEQUENCE_NUMBER PROP_TAG(PT_LONG,       0x6600)
  108. #define PR_SMS_CONTENTS_SORT_ORDER  PROP_TAG(PT_MV_LONG,    0x6601)
  109.  
  110. #if defined(WIN32)
  111. #define CRITICAL_SECTION_MEMBERS    CRITICAL_SECTION cs;
  112. #define CRITICAL_SECTION_MEMBERS_P  CRITICAL_SECTION *pcs;
  113. #else
  114. #define CRITICAL_SECTION_MEMBERS
  115. #define CRITICAL_SECTION_MEMBERS_P
  116. #endif
  117.  
  118. /* Object typedefs ------------------------------------------------------- */
  119.  
  120. typedef struct _OBJ     OBJ,        * POBJ,     ** PPOBJ;
  121. typedef struct _MSP     MSP,        * PMSP,     ** PPMSP;
  122. typedef struct _MSL     MSL,        * PMSL,     ** PPMSL;
  123. typedef struct _IMS     IMS,        * PIMS,     ** PPIMS;
  124. typedef struct _IFLD    IFLD,       * PIFLD,    ** PPIFLD;
  125. typedef struct _IMSG    IMSG,       * PIMSG,    ** PPIMSG;
  126. typedef struct _IATCH   IATCH,      * PIATCH,   ** PPIATCH;
  127. typedef struct _STM     STM,        * PSTM,     ** PPSTM;
  128. typedef struct _STG     STG,        * PSTG,     ** PPSTG;
  129.  
  130. /* Standard Object --------------------------------------------------------- */
  131.  
  132. #undef  INTERFACE
  133. #define INTERFACE struct _OBJ
  134.  
  135. #undef  MAPIMETHOD_
  136. #define MAPIMETHOD_(type, method)   MAPIMETHOD_DECLARE(type, method, OBJ_)
  137.         MAPI_IUNKNOWN_METHODS(IMPL)
  138. #undef  MAPIMETHOD_
  139. #define MAPIMETHOD_(type, method)   STDMETHOD_(type, method)
  140.  
  141. DECLARE_MAPI_INTERFACE(OBJ_)
  142. {
  143.     MAPI_IUNKNOWN_METHODS(IMPL)
  144. };
  145.  
  146. #define STANDARD_OBJECT_MEMBERS     \
  147.     LONG                cRef;       \
  148.     WORD                wType;      \
  149.     WORD                wFlags;     \
  150.     POBJ                pobjParent; \
  151.     POBJ                pobjNext;   \
  152.     POBJ                pobjHead;   \
  153.     PIMS                pims;       \
  154.     CRITICAL_SECTION_MEMBERS_P      \
  155.  
  156. /* NOTE: If you modify this enumeration, you must also update various */
  157. /* structures in mspobj.c which use the type as an index into lookup tables */
  158. enum {
  159.     OT_MSPROVIDER,
  160.     OT_MSLOGON,
  161.     OT_MSGSTORE,
  162.     OT_FOLDER,
  163.     OT_MESSAGE,
  164.     OT_ATTACH,
  165.     OT_STREAM,
  166.     OT_TABLE,
  167.     OT_MAX,
  168. };
  169.  
  170. #define OBJF_MODIFY     ((WORD)0x0001)
  171.  
  172. struct _OBJ
  173. {
  174.     OBJ_Vtbl *      lpVtbl;
  175.     STANDARD_OBJECT_MEMBERS
  176. };
  177.  
  178. typedef void (*LPFNNEUTER)(POBJ);
  179. extern LPFNNEUTER rgfnNeuter[];
  180.  
  181. #define OBJ_SetFlag(pobj, f)    ((pobj)->wFlags |=  (f))
  182. #define OBJ_ClearFlag(pobj, f)  ((pobj)->wFlags &= ~(f))
  183. #define OBJ_TestFlag(pobj, f)   ((pobj)->wFlags &   (f))
  184.  
  185. #ifdef WIN32
  186. #define OBJ_Initialize(pobj, _vtbl, _wType, _pims, _pcs)    \
  187.     (pobj)->lpVtbl      = _vtbl;    \
  188.     (pobj)->cRef        = 1;        \
  189.     (pobj)->wType       = _wType;   \
  190.     (pobj)->pims        = _pims;    \
  191.     (pobj)->pcs         = _pcs;
  192. #else
  193. #define OBJ_Initialize(pobj, _vtbl, _wType, _pims, _pcs)    \
  194.     (pobj)->lpVtbl      = _vtbl;    \
  195.     (pobj)->cRef        = 1;        \
  196.     (pobj)->wType       = _wType;   \
  197.     (pobj)->pims        = _pims;
  198. #endif
  199.  
  200. #define OBJ_EnterCriticalSection(pobj)  EnterCriticalSection((pobj)->pcs)
  201. #define OBJ_LeaveCriticalSection(pobj)  LeaveCriticalSection((pobj)->pcs)
  202. #define MSP_EnterCriticalSection(pmsp)  OBJ_EnterCriticalSection((POBJ)pmsp)
  203. #define MSP_LeaveCriticalSection(pmsp)  OBJ_LeaveCriticalSection((POBJ)pmsp)
  204. #define IMS_EnterCriticalSection(pims)  OBJ_EnterCriticalSection((POBJ)pims)
  205. #define IMS_LeaveCriticalSection(pims)  OBJ_LeaveCriticalSection((POBJ)pims)
  206.  
  207. /*
  208.  *  MSPOBJ.C
  209.  */
  210.  
  211. BOOL    FQueryInterface(int wType, REFIID riid);
  212.  
  213. void    OBJ_Enqueue(POBJ pobj, POBJ pobjParent);
  214. void    OBJ_Dequeue(POBJ pobj);
  215. void    OBJ_Destroy(POBJ pobj);
  216.  
  217. extern CHAR szFolderTemplate[];         /*  "*.fld"         */
  218. extern CHAR szMessageTemplate[];        /*  "*.msg"         */
  219. extern CHAR szPropertyFileName[];       /*  "folder.prp"    */
  220. extern CHAR szHierarchyFileName[];      /*  "hierarch.tbl"  */
  221. extern CHAR szContentsFileName[];       /*  "contents.tbl"  */
  222. extern CHAR szOutgoingFileName[];       /*  "outgoing.tbl"  */
  223.  
  224. /*
  225.  *  MSPRFS.C
  226.  */
  227.  
  228. /* Manifest constants */
  229.  
  230. #define RFS_CREATE      ((ULONG) 0x00000001)
  231.  
  232. /* Typedefs */
  233.  
  234. typedef struct _RFS         /* Receive Folder Storage */
  235. {
  236.     LPTSTR szFile;          /* Name of docfile containing RecFldr settings */
  237. } RFS, * PRFS;
  238.  
  239. typedef struct _RFN         /* A single RFS Node */
  240. {
  241.     LPTSTR szClass;         /* Name of the message class */
  242.     LPTSTR szName;          /* Relative path name of receive folder, i.e. */
  243.                             /* EntryID minus the GUID                     */
  244. } RFN, * PRFN;
  245.  
  246. /* Exported functions */
  247.  
  248. BOOL FIsValidMessageClass(LPTSTR szMessageClass);
  249. HRESULT OpenRFS (LPTSTR szStoreRoot, LPTSTR szFile, ULONG ulFlags,
  250.     PRFS * lpprfs);
  251. HRESULT GetRFN (PRFS prfs, LPTSTR szClassName, PRFN * pprfn);
  252. VOID    FreeRFN (PRFN prfn);
  253. HRESULT DeleteRFN (PRFS prfs, LPTSTR szClassName);
  254. HRESULT AddRFN (PRFS, PRFN prfn);
  255. HRESULT CloseRFS (PRFS prfs);
  256.  
  257. /*
  258.  *  MSPMS.C
  259.  */
  260.  
  261. /* Manifest constants */
  262.  
  263. #define IMS_CREATE      ((WORD) 0x0002)
  264. #define IMS_INVALID     ((WORD) 0x0004)
  265.  
  266. /* Typedefs */
  267.  
  268. #undef  INTERFACE
  269. #define INTERFACE   struct _IMS
  270.  
  271. #undef  MAPIMETHOD_
  272. #define MAPIMETHOD_(type, method)   MAPIMETHOD_DECLARE(type, method, IMS_)
  273.         MAPI_IUNKNOWN_METHODS(IMPL)
  274.         MAPI_IMAPIPROP_METHODS(IMPL)
  275.         MAPI_IMSGSTORE_METHODS(IMPL)    
  276. #undef  MAPIMETHOD_
  277. #define MAPIMETHOD_(type, method)   MAPIMETHOD_TYPEDEF(type, method, IMS_)
  278.         MAPI_IUNKNOWN_METHODS(IMPL)
  279.         MAPI_IMAPIPROP_METHODS(IMPL)
  280.         MAPI_IMSGSTORE_METHODS(IMPL)
  281. #undef  MAPIMETHOD_
  282. #define MAPIMETHOD_(type, method)   STDMETHOD_(type, method)
  283.  
  284. DECLARE_MAPI_INTERFACE(IMS_)
  285. {
  286.     MAPI_IUNKNOWN_METHODS(IMPL)
  287.     MAPI_IMAPIPROP_METHODS(IMPL)
  288.     MAPI_IMSGSTORE_METHODS(IMPL)    
  289. };
  290.  
  291. struct _IMS             /* Implementation of IMsgStore */
  292. {
  293.     IMS_Vtbl *      lpVtbl;     /* -> vtblIMS */
  294.     STANDARD_OBJECT_MEMBERS
  295.     LPTSTR      szStorePath;    /* Full path to the store root */
  296.     MAPIUID     uidResource;    /* Message Store unique identifier */
  297.     LPTSTR      szProps;        /* Full path to property docfile */
  298.     PMSL        pmsl;           /* Logon object (MAPI session stuff) */
  299.     PMSP        pmsp;           /* Provider object (global stuff) */
  300.     LMR         lmr;            /* Linked memory routines */
  301.     PRFS        prfs;           /* Struct handling access to receive folder */
  302.     LPMAPISUP   psup;           /* MAPI Support object */
  303.     SBinary     eidStore;       /* PR_STORE_ENTRYID */
  304.     LPTABLEDATA lptblOutgoing;  /* outgoing queue for this store */
  305.     HANDLE      hOGQueueMutex;  /* Mutex for reading/writing the OG Queue */
  306.     FILETIME    ftOGQueue;      /* The time of the OQ file when we read it */
  307.     ULONG       cOutgoingViews; /* number of views open on the outgoing queue */
  308.     ULONG       ulOQConn;       /* Connection for OQ unadvise */
  309.     HANDLE      hContTblMutex;  /* Mutex for reading/writing ALL cont tbls */
  310.     ULONG       ulTblConn;      /* Connection for Tbl unadvise */
  311.     LPMSGSESS   pmsgsess;       /* IMSG Session to create all messages within */
  312.     ULONG       ulFlagsSLT;     /* Flags for StoreLogoffTransports */
  313. };
  314.  
  315. #define MSF_SPOOLER         ((WORD)0x8000)
  316.  
  317. /* Outgoing Queue Notification Block (ONB) */
  318. /* This is the format of our extended cross-process notification for the */
  319. /* outgoing queue table. We use this to update the table data in other */
  320. /* processes after we change it in the originating process. The changes */
  321. /* that we pass across are either deleting a row (for example, when the */
  322. /* spooler calls FinishedMsg), or adding a row (for example, when the */
  323. /* client submits a message). */
  324.  
  325. typedef struct _ONB
  326. {
  327.     FILETIME ftBeforeUpdate;    /* time of the file before updating */
  328.     FILETIME ftAfterUpdate;     /* time of the file after applying the update */
  329.     LPVOID  pvRef;              /* memory offset from originating process */
  330.     ULONG   cbNtf;              /* # of bytes in abNtf (the flat notif below) */
  331.     BYTE    abNtf[1];           /* the update to apply to the table */
  332. } ONB, * PONB;
  333.  
  334. #define CbNewONB(_cb)       (offsetof(ONB,abNtf) + (_cb))
  335. #define CbONB(_ponb) \
  336.     (offsetof(ONB,abNtf) + (UINT)((_ponb)->cbNtf))
  337.  
  338.  
  339. /* Table Notification Block (TNB) */
  340. /* This is the format of our extended cross-process notification for */
  341. /* Contents and Hierarchy Tables. We use this notification to update a */
  342. /* table in other processes after we change it in the originating process. */
  343. /* The notification consists of an object notification containing the */
  344. /* entryids we need. The fnev tells the event type. We only use two of */
  345. /* the entryids in the object notification. The ParentID fields refer to */
  346. /* the parent folder of the table we need to update. The EntryID fields */
  347. /* refer to the object that changed within the folder. The ulObjType field */
  348. /* will be either MAPI_MESSAGE (for contents table changes) or MAPI_FOLDER */
  349. /* (for hierarchy table changes).  All other fields in the structure are */
  350. /* unused and should be set to 0. */
  351.  
  352. typedef struct _TNB
  353. {
  354.     ULONG   ulTableEvent;   /* TABLE_ROW_ (ADDED, DELETED, MODIFIED) */
  355.     LPVOID  pvRef;          /* memory offset from originating process */
  356.     ULONG   cbNtf;          /* # of bytes in abNtf (the flat notif below) */
  357.     BYTE    abNtf[1];       /* an object notification */
  358. } TNB, * PTNB;
  359.  
  360. #define CbNewTNB(_cb)       (offsetof(TNB,abNtf) + (_cb))
  361. #define CbTNB(_ptnb) \
  362.     (offsetof(TNB,abNtf) + (UINT)((_ptnb)->cbNtf))
  363.  
  364.  
  365. /* Exported functions */
  366. HRESULT HrOpenIMSPropsFileRetry(LPMSGSESS pmsgsess, LPTSTR szFile, PLMR plmr,
  367.     LPMAPISUP psup, BOOL fModify, LPMESSAGE * lppmsg);
  368. BOOL IMS_IsInvalid(PIMS pims);
  369.  
  370. /* Constructors */
  371.  
  372. HRESULT HrNewIMS(LPTSTR szStorePath, LPTSTR szStoreProps, PMSP pmsp,
  373.     PMSL pmsl, PRFS prfs, LPPROFSECT pps, LPMAPISUP psup, BOOL fCreate,
  374.     PIMS *ppims);
  375.  
  376. /* Non-virtual public methods */
  377.  
  378. void IMS_Neuter(PIMS pims);
  379. HRESULT HrInitIMSProps (PIMS pims, LPTSTR szPswd);
  380. VOID GetResourceUID (PIMS pims, LPMAPIUID lpuid);
  381. HRESULT HrUniqueFileName (PIMS pims, ULONG * lpulSeqNumber, LPTSTR *
  382.     lppszNewName);
  383. BOOL FIsInvalidEID (ULONG, PEID, PIMS);
  384. /* Others */
  385.  
  386. STDAPI_(void) MsgReleaseStg (ULONG ulCallerData, LPMESSAGE lpMessage);
  387. long STDAPICALLTYPE LSMSNotifCallback (LPVOID lpvContext,
  388.     ULONG cNotif, LPNOTIFICATION lpNotifs);
  389.  
  390. /* column properties for outgoing queue */
  391. #define OUTGOING_COLUMNS    13      /* number of columns in outgoing queue */
  392. static const SizedSPropTagArray(OUTGOING_COLUMNS, sptaOutgoing) =
  393. {
  394.     OUTGOING_COLUMNS,
  395.     {
  396.         PR_ENTRYID,
  397.         PR_SUBMIT_FLAGS,
  398.         PR_INSTANCE_KEY,    /* the index column */
  399.         PR_DISPLAY_TO,
  400.         PR_DISPLAY_CC,
  401.         PR_DISPLAY_BCC,
  402.         PR_SENDER_NAME,
  403.         PR_SUBJECT,
  404.         PR_CLIENT_SUBMIT_TIME,
  405.         PR_PRIORITY,
  406.         PR_MESSAGE_FLAGS,
  407.         PR_MESSAGE_SIZE,
  408.         PR_SPOOLER_STATUS
  409.     }
  410. };
  411.  
  412.  
  413. /*
  414.  *  MSPFLD.C
  415.  */
  416.  
  417. #define FAILED_SEARCH   (INVALID_HANDLE_VALUE)
  418.  
  419. #define MODIFY_INDEX    1       /* index of LAST_MODIFICATION_TIME in tables */
  420.  
  421. /* column properties for contents tables */
  422. #define CONTENTS_COLUMNS    22      /* number of columns in a table of messages */
  423. static const SizedSPropTagArray(CONTENTS_COLUMNS, sPropTagsContents) =
  424. {
  425.     CONTENTS_COLUMNS,
  426.     {
  427.         PR_ENTRYID,
  428.         PR_LAST_MODIFICATION_TIME,  /* must be in position MODIFY_INDEX */
  429.         PR_INSTANCE_KEY,            /* the index column */
  430.         PR_HASATTACH,
  431.         PR_SUBJECT,
  432.         PR_SENDER_NAME,
  433.         PR_DISPLAY_TO,
  434.         PR_DISPLAY_CC,
  435.         PR_CLIENT_SUBMIT_TIME,
  436.         PR_MESSAGE_DELIVERY_TIME,
  437.         PR_MESSAGE_FLAGS,
  438.         PR_PRIORITY,
  439.         PR_CONVERSATION_KEY,
  440.         PR_SEARCH_KEY,
  441.         PR_ICON,
  442.         PR_MINI_ICON,
  443.         PR_SENSITIVITY,
  444.         PR_MESSAGE_CLASS,
  445.         PR_RECORD_KEY,
  446.         PR_SPOOLER_STATUS,
  447.         PR_SENT_REPRESENTING_NAME,
  448.         PR_MSG_STATUS
  449.     }
  450. };
  451.  
  452. /* column properties for hierarchy tables */
  453. #define HIERARCHY_COLUMNS   12
  454. static const SizedSPropTagArray(HIERARCHY_COLUMNS, sPropTagsHierarchy) =
  455. {
  456.     HIERARCHY_COLUMNS,
  457.     {
  458.         PR_ENTRYID,
  459.         PR_LAST_MODIFICATION_TIME, /* must be in postion MODIFY_INDEX */
  460.         PR_DISPLAY_NAME,    /* the folder name */
  461.         PR_INSTANCE_KEY,    /* the index column */
  462.         PR_OBJECT_TYPE,
  463.         PR_COMMENT,
  464.         PR_CONTENT_COUNT,
  465.         PR_CONTENT_UNREAD,
  466.         PR_STATUS,
  467.         PR_SUBFOLDERS,
  468.         PR_FOLDER_TYPE,
  469.         PR_DEPTH            /* depth in hierarchy, must be last */
  470.     }
  471. } ;
  472.  
  473. #undef  INTERFACE
  474. #define INTERFACE struct _IFLD
  475.     
  476. #undef  MAPIMETHOD_
  477. #define MAPIMETHOD_(type, method)   MAPIMETHOD_DECLARE(type, method, IFLD_)
  478.         MAPI_IUNKNOWN_METHODS(IMPL)
  479.         MAPI_IMAPIPROP_METHODS(IMPL)
  480.         MAPI_IMAPICONTAINER_METHODS(IMPL)
  481.         MAPI_IMAPIFOLDER_METHODS(IMPL)
  482. #undef  MAPIMETHOD_
  483. #define MAPIMETHOD_(type, method)   MAPIMETHOD_TYPEDEF(type, method, IFLD_)
  484.         MAPI_IUNKNOWN_METHODS(IMPL)
  485.         MAPI_IMAPIPROP_METHODS(IMPL)
  486.         MAPI_IMAPICONTAINER_METHODS(IMPL)
  487.         MAPI_IMAPIFOLDER_METHODS(IMPL)
  488. #undef  MAPIMETHOD_
  489. #define MAPIMETHOD_(type, method)   STDMETHOD_(type, method)
  490.  
  491. DECLARE_MAPI_INTERFACE(IFLD_)
  492. {
  493.     MAPI_IUNKNOWN_METHODS(IMPL)
  494.     MAPI_IMAPIPROP_METHODS(IMPL)
  495.     MAPI_IMAPICONTAINER_METHODS(IMPL)
  496.     MAPI_IMAPIFOLDER_METHODS(IMPL)
  497. };
  498.  
  499. extern IFLD_Vtbl    vtblIFLD;
  500.  
  501. /* we store PR_ENTRYID, PR_PARENT_ENTRYID and PR_INSTANCE_KEY internally */
  502. #define cpropIFLDInternal       3
  503.  
  504. /* Folder's instance data */
  505. struct _IFLD
  506. {
  507.     IFLD_Vtbl *     lpVtbl; /* -> vtblIFLD */
  508.     STANDARD_OBJECT_MEMBERS
  509.     PEID peid;                  /* EntryID of this folder */
  510.     ULONG           cval;       /* # of internal props */
  511.     LPSPropValue    pval;       /* internal prop values */
  512.     LPTABLEDATA lptblContents;  /* contents table for this folder */
  513.     ULONG cContentsViews;       /* number of views open on contents table*/
  514.     LPTABLEDATA lptblHierarchy; /* hierarchy table for this folder */
  515.     ULONG cHierarchyViews;      /* number of views open on hierarchy table */
  516. };
  517.  
  518. HRESULT HrNewIFLD(PEID peid, PIMS pims, BOOL fModify, PIFLD * ppifld);
  519. HRESULT HrCreateFolderStorage(PIFLD pifld, ULONG ulFolderType,
  520.     LPSTR szFolderName, LPSTR szFolderComment, BOOL fCreateDir,
  521.     PIMS pims, PEID *ppeid);
  522. HRESULT HrNewEID (PIFLD, PIMS, LPTSTR, ULONG *, PEID *);
  523. HRESULT HrIncrementOneROProp(PIFLD pifld, LONG lDelta, ULONG ulPT);
  524. HRESULT HrIsParent(PEID peidParent, PEID peidChild, BOOL *pfIsParent);
  525. HRESULT HrGetFileModTime(LPTSTR szStorePath, LPTSTR szFileName,
  526.     FILETIME *pft);
  527. HRESULT HrFullPathName (LPSTR, LPSTR, LPSTR, LPSTR *);
  528. HRESULT HrFullToRelative(LPTSTR, PIMS, LPTSTR *);
  529. HRESULT HrOpenPropertyMessageRetry(PEID peid, PIMS pims,
  530.     BOOL fModifyExclusive, LPMESSAGE *lppmsg);
  531. HRESULT HrFindFirstID( PIFLD, LPTSTR, ULONG *, LPTSTR *, HANDLE *,
  532.                     WIN32_FIND_DATA *, PEID *);
  533. HRESULT HrFindNextID( PIFLD, ULONG, LPTSTR, HANDLE, WIN32_FIND_DATA *, PEID *);
  534. void CloseIDSearch( HANDLE *, LPTSTR *);
  535. HRESULT HrFullToRelative( LPTSTR, PIMS, LPTSTR *);
  536. HRESULT HrUpdateRow(PIMS pims, LPTABLEDATA lptbl, PEID peid,
  537.     LPSPropTagArray pPTA, FILETIME *pft, ULONG ulObjType);
  538. void    IFLD_Neuter (PIFLD);
  539. void ChangeTable(PIMS pims, PEID peidTable, PEID peidObject,
  540.     ULONG ulObjType, ULONG ulTableEvent, BOOL fSendNotif);
  541. HRESULT HrRemoveRow( LPTABLEDATA lptbl, PEID peid);
  542.  
  543. /*
  544.  *  MSPMSG.C
  545.  */
  546.  
  547. #undef  INTERFACE
  548. #define INTERFACE struct _IMSG
  549.     
  550. #undef  MAPIMETHOD_
  551. #define MAPIMETHOD_(type, method)   MAPIMETHOD_DECLARE(type, method, IMSG_)
  552.         MAPI_IUNKNOWN_METHODS(IMPL)
  553.         MAPI_IMAPIPROP_METHODS(IMPL)
  554.         MAPI_IMESSAGE_METHODS(IMPL)
  555. #undef  MAPIMETHOD_
  556. #define MAPIMETHOD_(type, method)   MAPIMETHOD_TYPEDEF(type, method, IMSG_)
  557.         MAPI_IUNKNOWN_METHODS(IMPL)
  558.         MAPI_IMAPIPROP_METHODS(IMPL)
  559.         MAPI_IMESSAGE_METHODS(IMPL)
  560. #undef  MAPIMETHOD_
  561. #define MAPIMETHOD_(type, method)   STDMETHOD_(type, method)
  562.  
  563. DECLARE_MAPI_INTERFACE(IMSG_)
  564. {
  565.     MAPI_IUNKNOWN_METHODS(IMPL)
  566.     MAPI_IMAPIPROP_METHODS(IMPL)
  567.     MAPI_IMESSAGE_METHODS(IMPL)
  568. };
  569.  
  570. extern IMSG_Vtbl    vtblIMSG;
  571.  
  572. struct _IMSG            /* Implementation of IMessage */
  573. {
  574.     IMSG_Vtbl * lpVtbl; /* -> vtblIMSG */
  575.     STANDARD_OBJECT_MEMBERS
  576.     LPMESSAGE       lpmsg;
  577.     PEID            peid;
  578.     ULONG           cval;
  579.     LPSPropValue    pval;
  580. };
  581.  
  582. #define MSGF_NEWLYCREATED           ((WORD)0x4000)
  583. #define MSGF_MSGINMSG               ((WORD)0x2000)
  584. #define MSGF_FRESH                  ((WORD)0x1000)
  585. #define MSGF_CREATEDSTORAGE         ((WORD)0x0800)
  586.  
  587. #define SET         1
  588. #define UNSET       2
  589. #define DONT_SAVE   4
  590.  
  591. /* Exported functions */
  592.  
  593. HRESULT HrNewIMSG(PEID peid, PIMS pims, BOOL fCreate, BOOL fModify,
  594.     ULONG ulSeqNum, LPSTR *pszFull, PIMSG *ppimsg);
  595. HRESULT HrSetFlags(PIMSG, ULONG, ULONG, ULONG); 
  596. HRESULT NewIMSGInIATCH (LPMESSAGE lpmsg, POBJ pobj, PIMSG * ppimsg);
  597. HRESULT InitIMSGProps(PIMSG pimsg);
  598. void IMSG_Neuter (PIMSG);
  599. HRESULT HrSetInternalProps(PLMR plmr, ULONG cprop, LPSPropValue *ppval,
  600.     ULONG *pcval, PEID peid, PEID peidParent, ULONG ulSeqNum);
  601.  
  602. /*
  603.  *  MSPATCH.C
  604.  */
  605.  
  606. #undef  INTERFACE
  607. #define INTERFACE struct _IATCH
  608.     
  609. #undef  MAPIMETHOD_
  610. #define MAPIMETHOD_(type, method)   MAPIMETHOD_DECLARE(type, method, IATCH_)
  611.         MAPI_IUNKNOWN_METHODS(IMPL)
  612.         MAPI_IMAPIPROP_METHODS(IMPL)
  613.         MAPI_IATTACH_METHODS(IMPL)
  614. #undef  MAPIMETHOD_
  615. #define MAPIMETHOD_(type, method)   MAPIMETHOD_TYPEDEF(type, method, IATCH_)
  616.         MAPI_IUNKNOWN_METHODS(IMPL)
  617.         MAPI_IMAPIPROP_METHODS(IMPL)
  618.         MAPI_IATTACH_METHODS(IMPL)
  619. #undef  MAPIMETHOD_
  620. #define MAPIMETHOD_(type, method)   STDMETHOD_(type, method)
  621.  
  622. DECLARE_MAPI_INTERFACE(IATCH_)
  623. {
  624.     MAPI_IUNKNOWN_METHODS(IMPL)
  625.     MAPI_IMAPIPROP_METHODS(IMPL)
  626.     MAPI_IATTACH_METHODS(IMPL)
  627. };
  628.  
  629. extern IATCH_Vtbl   vtblIATCH;
  630.  
  631. struct _IATCH           /* Implementation of IAttach */
  632. {
  633.     IATCH_Vtbl *    lpVtbl; /* -> vtblIATCH */
  634.     STANDARD_OBJECT_MEMBERS
  635.     LPATTACH lpattach;
  636. };
  637.  
  638. /* Exported functions */
  639.  
  640. HRESULT HrNewIATCH(LPATTACH lpattach, PIMSG pimsg, BOOL fModify,
  641.     PIATCH * ppiatch);
  642. void IATCH_Neuter (PIATCH piatch);
  643.  
  644. /*
  645.  *  MSPGLE.C
  646.  */
  647.  
  648. HRESULT MapScodeSz (SCODE scArg, PIMS pims, LPTSTR * lppszError);
  649.  
  650. /*
  651.  *  MSPMISC.C
  652.  */
  653.  
  654. /* length in chars of file extension including . (no NULL) */
  655. #define CCH_EXT         4
  656.  
  657. /* length in chars of the base portion of a local name (no NULL) */
  658. #define CCH_BASE        8
  659.  
  660. /* length in chars of a local name of a message or folder, including NULL */
  661. #define CCH_NAME            (CCH_BASE + CCH_EXT + 1)
  662.  
  663. #define FOLDER_EXT      TEXT( ".fld" )  /* extension for folder directory names */
  664. #define MESSAGE_EXT     TEXT( ".msg" )  /* File name extension for messages */
  665. #define TEMP_EXT        TEXT( ".tmp" )  /* File name extension for messages */
  666.  
  667. /* Filename extension for read-receipt messages   */
  668. #define READRECEIPT_EXT TEXT( ".rrt" )
  669.  
  670. SCODE ScAlloc(ULONG lcb, LPVOID *ppv);
  671. SCODE ScAllocZ(ULONG lcb, LPVOID *ppv);
  672. SCODE ScRealloc(ULONG lcb, LPVOID pvOrig, LPVOID * ppv);
  673. void FreeNull(LPVOID pv);
  674. SCODE LMAllocZ(PLMR plmr, ULONG lcb, LPVOID *ppv);
  675. SCODE ScInitMSInstance(LPMALLOC lpmalloc);
  676. void DeinitMSInstance(void);
  677.  
  678. #define HrAlloc(a,b)        ResultFromScode(ScAlloc((a), (b)))
  679. #define HrAllocZ(a,b)       ResultFromScode(ScAllocZ((a), (b)))
  680. #define HrRealloc(a,b,c)    ResultFromScode(ScRealloc((a), (b), (c)))
  681.  
  682. LPTSTR SzBaseName (PEID);
  683.  
  684. BOOL FCheckEIDType(PEID peid, LPSTR szExt);
  685. BOOL FIsRoot (PEID peid);
  686. BOOL FIsFolder (PEID peid);
  687. BOOL FIsUnsavedMsg (PIMSG pimsg);
  688. #define FIsMessage(_peid)       FCheckEIDType((_peid), MESSAGE_EXT)
  689. #define FIsUnsavedEID(_peid)    FCheckEIDType((_peid), TEMP_EXT)
  690.  
  691. HRESULT HrDeconstructEID (PEID peid, LPMAPIUID * lppuid,
  692.     LPTSTR * lppszPath, LPTSTR * lppszFile);
  693. HRESULT HrAppendPath (LPTSTR szBase, LPTSTR szAppend, LPTSTR *
  694.     lppszFullPath);
  695. BOOL FAppendPathNoMem (LPTSTR szBase, LPTSTR szAppend,
  696.     ULONG cchFullPath, LPTSTR szFullPath);
  697. void ReplaceExt(LPTSTR szFile, LPTSTR szExt);
  698. HRESULT HrConstructEID(LPMAPIUID lpuidStore, PLMR plmr, LPSTR szNewName,
  699.     PEID *ppeidNew);
  700. HRESULT HrGetParentEID (PLMR, PEID, PEID *);
  701. HRESULT HrOpenParent(PIMS pims, PEID peid, ULONG ulFlags, PIFLD *ppifld);
  702.  
  703. void FreePropArrays (LPSPropValue *,
  704.     LPSPropTagArray *, LPSPropAttrArray *);
  705. HRESULT HrAllocPropArrays (ULONG, LPSPropValue *,
  706.     LPSPropTagArray *, LPSPropAttrArray *);
  707.  
  708. HRESULT HrWrap_GetProps(HRESULT hr, PIMS pims, ULONG cvalInt,
  709.     LPSPropValue pvalInt, ULONG * lpcValues, LPSPropValue * ppval,
  710.     BOOL fStore, BOOL fTagsSpecified);
  711.  
  712. BOOL FIsSubmittedMessage(PIMS pims, PEID peid);
  713.  
  714. HRESULT HrOpenIMsgSession(LPMSGSESS *ppmsgsess);
  715. HRESULT HrOpenIMsg(LPMSGSESS pmsgsess, LPSTR szFile, PLMR plmr, LPMAPISUP psup,
  716.     BOOL fCreate, BOOL fModify, BOOL fExclusive, LPMESSAGE *lppmsg);
  717.  
  718. HRESULT HrSetOneROProp(LPMESSAGE lpmsg, PLMR plmr, ULONG ulPT, LPVOID pv);
  719. HRESULT HrGetSingleProp(LPMAPIPROP pmprop, PLMR plmr, ULONG ulPT, LPVOID pv);
  720. HRESULT HrSetSingleProp(LPMAPIPROP pmprop, PLMR plmr, ULONG ulPT, LPVOID pv);
  721.  
  722. BOOL FContainsProp(ULONG ulPropTag, LPSPropTagArray ptaga);
  723.  
  724.  
  725. /*
  726.  *  MSPROVIDER object.
  727.  *  Returned by MSProviderInit() routine.
  728.  *  One is created for each Session logged
  729.  *  into this store provider on this process.
  730.  */
  731.  
  732. #undef  INTERFACE
  733. #define INTERFACE struct _MSP
  734.  
  735. #undef  MAPIMETHOD_
  736. #define MAPIMETHOD_(type, method)   MAPIMETHOD_DECLARE(type, method, MSP_)
  737.         MAPI_IUNKNOWN_METHODS(IMPL)
  738.         MAPI_IMSPROVIDER_METHODS(IMPL)
  739. #undef  MAPIMETHOD_
  740. #define MAPIMETHOD_(type, method)   MAPIMETHOD_TYPEDEF(type, method, MSP_)
  741.         MAPI_IUNKNOWN_METHODS(IMPL)
  742.         MAPI_IMSPROVIDER_METHODS(IMPL)
  743. #undef  MAPIMETHOD_
  744. #define MAPIMETHOD_(type, method)   STDMETHOD_(type, method)
  745.  
  746. DECLARE_MAPI_INTERFACE(MSP_)
  747. {
  748.     MAPI_IUNKNOWN_METHODS(IMPL)
  749.     MAPI_IMSPROVIDER_METHODS(IMPL)
  750. };
  751.  
  752. extern MSP_Vtbl vtblMSP;
  753.  
  754. struct _MSP
  755. {
  756.     MSP_Vtbl *  lpVtbl;         /* -> vtblMSP */
  757.     STANDARD_OBJECT_MEMBERS
  758.     CRITICAL_SECTION_MEMBERS        /* Critical section (WIN32 only) */
  759.     HINSTANCE       hInst;          /* Instance handle */
  760.     LMR             lmr;            /* Linked memory routines */
  761.     IFDBG(BOOL      fInvalid;)      /* TRUE if invalid (DEBUG only) */
  762. };
  763.  
  764. /*
  765.  *  LOGON object.
  766.  *  Returned from MSP_Logon().
  767.  *  Called by MAPI.DLL.  Equivalent to the IMSGSTORE object
  768.  *  returned on the same call but is used by MAPI instead of the client.
  769.  */
  770.  
  771. #undef  INTERFACE
  772. #define INTERFACE struct _MSL
  773.  
  774. #undef  MAPIMETHOD_
  775. #define MAPIMETHOD_(type, method)   MAPIMETHOD_DECLARE(type, method, MSL_)
  776.         MAPI_IUNKNOWN_METHODS(IMPL)
  777.         MAPI_IMSLOGON_METHODS(IMPL)
  778. #undef  MAPIMETHOD_
  779. #define MAPIMETHOD_(type, method)   MAPIMETHOD_TYPEDEF(type, method, MSL_)
  780.         MAPI_IUNKNOWN_METHODS(IMPL)
  781.         MAPI_IMSLOGON_METHODS(IMPL)
  782. #undef  MAPIMETHOD_
  783. #define MAPIMETHOD_(type, method)   STDMETHOD_(type, method)
  784.  
  785. DECLARE_MAPI_INTERFACE(MSL_)
  786. {
  787.     MAPI_IUNKNOWN_METHODS(IMPL)
  788.     MAPI_IMSLOGON_METHODS(IMPL)
  789. };
  790.  
  791. extern MSL_Vtbl vtblMSL;
  792. extern MAPIUID uidProvider;
  793.  
  794. struct _MSL
  795. {
  796.     MSL_Vtbl *      lpVtbl;     /* -> vtblMSL */
  797.     STANDARD_OBJECT_MEMBERS
  798.     CRITICAL_SECTION_MEMBERS        /* Critical section (WIN32) */
  799.     LMR                 lmr;        /* Linked memory routines */
  800.     IFDBG(BOOL          fInvalid;)  /* TRUE if invalid (DEBUG only) */
  801. };
  802.  
  803.  
  804. /*
  805.  *  MSPTBL.C
  806.  */
  807.  
  808. HRESULT HrGetTableName(POBJ, LPSTR, LPSTR, LPSTR *);
  809. HRESULT HrSyncOutgoingTable(LPTABLEDATA lptbl, PIMS pims);
  810. HRESULT HrSyncContentsTable(PIFLD pifld, BOOL fWriteTable);
  811. HRESULT HrReadTableFromDisk(LPTABLEDATA, POBJ, LPSTR, ULONG, LPSTR);
  812. HRESULT HrWriteTableOnDisk(LPTABLEDATA, POBJ, LPSTR, LPSTR);
  813.  
  814. /*
  815.  *  MSPNTFY.C
  816.  */
  817.  
  818. HRESULT HrUpdateOutgoingQueue(PIMS pims, PIMSG pimsg, PEID peid,
  819.     ULONG ulTableEvent);
  820. HRESULT HrSetupPrivateNotifications(PIMS pims);
  821. HRESULT HrNewOutgoingTableData(PIMS pims);
  822. HRESULT HrCreateOGQueueMutex(HANDLE *phQMutex);
  823.  
  824. HRESULT HrSendNotif(PIMS pims, PEID peidParent, PEID peidObject,
  825.     ULONG ulTableEvent, ULONG ulObjType);
  826.  
  827.