Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: defhndlr.h
  7. //
  8. // Contents: class declaration for the default handler
  9. //
  10. // Classes: CDefObject
  11. //
  12. // Functions:
  13. //
  14. // History: dd-mmm-yy Author Comment
  15. //
  16. // 11-17-95 JohannP (Johann Posch) Architectural change:
  17. // Default handler will talk to a handler object
  18. // on the server site (ServerHandler). The serverhandler
  19. // communicates with the default handler via the
  20. // clientsitehandler. See document: "The Ole Server Handler".
  21. //
  22. // 06-Sep-95 davidwor removed SetHostNames atoms and replaced with
  23. // m_pHostNames and m_ibCntrObj members
  24. // 01-Feb-95 t-ScottH added Dump method to CDefObject
  25. // added DHFlag to indicate aggregation
  26. // (_DEBUG only)
  27. // changed private member from IOleAdviseHolder *
  28. // to COAHolder * (it is what we instantiate)
  29. // 15-Nov-94 alexgo optimized, removed 16bit burfiness
  30. // (nested classes and multiple BOOLs)
  31. // 25-Jan-94 alexgo first pass at converting to Cairo-style
  32. // memory allocations.
  33. // 02-Nov-93 alexgo 32bit port
  34. //
  35. //--------------------------------------------------------------------------
  36. #include <utils.h>
  37. #include "olepres.h"
  38. #include "olecache.h"
  39. #include "dacache.h"
  40. #include "oaholder.h"
  41. #ifdef SERVER_HANDLER
  42. #include <srvhdl.h>
  43. class CEmbServerWrapper;
  44. #endif SERVER_HANDLER
  45. // default handler flags
  46. typedef enum tagDHFlags
  47. {
  48. DH_SAME_AS_LOAD = 0x0001,
  49. DH_CONTAINED_OBJECT = 0x0002, // indicates an embedding
  50. DH_LOCKED_CONTAINER = 0x0004,
  51. DH_FORCED_RUNNING = 0x0008,
  52. DH_EMBEDDING = 0x0010, // link or an embedding?
  53. DH_INIT_NEW = 0x0020,
  54. DH_STATIC = 0x0040,
  55. DH_INPROC_HANDLER = 0x0080,
  56. DH_DELAY_CREATE = 0x0100,
  57. DH_COM_OUTEROBJECT = 0x0200,
  58. DH_UNMARSHALED = 0x0400,
  59. DH_CLEANEDUP = 0x0800,
  60. DH_OLE1SERVER = 0x1000,
  61. DH_APICREATE = 0x2000,
  62. #ifdef _DEBUG
  63. DH_AGGREGATED = 0x00010000,
  64. DH_LOCKFAILED = 0x00020000,
  65. DH_WILLUNLOCK = 0x00040000
  66. #endif // _DEBUG
  67. } DHFlags;
  68. //+-------------------------------------------------------------------------
  69. //
  70. // Class: CDefObject
  71. //
  72. // Purpose: The default handler class. The object acts as a surrogate,
  73. // or handler for an out-of-process server exe.
  74. //
  75. // Interface: The default handler implements
  76. // IDataObject
  77. // IOleObject
  78. // IPersistStorage
  79. // IRunnableObject
  80. // IExternalConnection
  81. // IAdviseSink
  82. //
  83. // History: dd-mmm-yy Author Comment
  84. // 01-Feb-95 t-ScottH added Dump method (_DEBUG only)
  85. // 15-Nov-94 alexgo memory optimization
  86. // 02-Nov-93 alexgo 32bit port
  87. //
  88. // Notes:
  89. //
  90. //--------------------------------------------------------------------------
  91. class CDefObject : public CRefExportCount, public IDataObject,
  92. public IOleObject, public IPersistStorage, public IRunnableObject,
  93. public IExternalConnection, public CThreadCheck
  94. {
  95. public:
  96. static IUnknown *Create (IUnknown *pUnkOuter,
  97. REFCLSID clsidClass, DWORD flags, IClassFactory *pCF);
  98. class CPrivUnknown : public IUnknown
  99. {
  100. public:
  101. STDMETHOD(QueryInterface) ( REFIID riid, LPVOID FAR* ppvObj);
  102. STDMETHOD_(ULONG,AddRef) (void);
  103. STDMETHOD_(ULONG,Release) (void);
  104. };
  105. friend class CPrivUnknown;
  106. CPrivUnknown m_Unknown;
  107. // IUnknown methods
  108. STDMETHOD(QueryInterface) ( REFIID riid, LPVOID FAR* ppvObj);
  109. STDMETHOD_(ULONG,AddRef) (void);
  110. STDMETHOD_(ULONG,Release) (void);
  111. // IDataObject methods
  112. INTERNAL_(IDataObject *) GetDataDelegate(void);
  113. STDMETHOD(GetData) ( LPFORMATETC pformatetcIn,
  114. LPSTGMEDIUM pmedium );
  115. STDMETHOD(GetDataHere) ( LPFORMATETC pformatetc,
  116. LPSTGMEDIUM pmedium );
  117. STDMETHOD(QueryGetData) ( LPFORMATETC pformatetc );
  118. STDMETHOD(GetCanonicalFormatEtc) ( LPFORMATETC pformatetc,
  119. LPFORMATETC pformatetcOut);
  120. STDMETHOD(SetData) ( LPFORMATETC pformatetc,
  121. LPSTGMEDIUM pmedium, BOOL fRelease);
  122. STDMETHOD(EnumFormatEtc) ( DWORD dwDirection,
  123. LPENUMFORMATETC FAR* ppenumFormatEtc);
  124. STDMETHOD(DAdvise) ( FORMATETC FAR* pFormatetc, DWORD advf,
  125. IAdviseSink FAR* pAdvSink,
  126. DWORD FAR* pdwConnection);
  127. STDMETHOD(DUnadvise) ( DWORD dwConnection);
  128. STDMETHOD(EnumDAdvise) ( LPENUMSTATDATA FAR* ppenumAdvise);
  129. // IOleObject methods
  130. INTERNAL_(IOleObject *)GetOleDelegate();
  131. STDMETHOD(SetClientSite) ( LPOLECLIENTSITE pClientSite);
  132. STDMETHOD(GetClientSite) ( LPOLECLIENTSITE FAR* ppClientSite);
  133. STDMETHOD(SetHostNames) ( LPCOLESTR szContainerApp,
  134. LPCOLESTR szContainerObj);
  135. STDMETHOD(Close) ( DWORD reserved);
  136. STDMETHOD(SetMoniker) ( DWORD dwWhichMoniker, LPMONIKER pmk);
  137. STDMETHOD(GetMoniker) ( DWORD dwAssign, DWORD dwWhichMoniker,
  138. LPMONIKER FAR* ppmk);
  139. STDMETHOD(InitFromData) ( LPDATAOBJECT pDataObject,
  140. BOOL fCreation,
  141. DWORD dwReserved);
  142. STDMETHOD(GetClipboardData) ( DWORD dwReserved,
  143. LPDATAOBJECT FAR* ppDataObject);
  144. STDMETHOD(DoVerb) ( LONG iVerb,
  145. LPMSG lpmsg,
  146. LPOLECLIENTSITE pActiveSite,
  147. LONG lindex,
  148. HWND hwndParent,
  149. const RECT FAR* lprcPosRect);
  150. STDMETHOD(EnumVerbs) ( IEnumOLEVERB FAR* FAR* ppenumOleVerb);
  151. STDMETHOD(Update) (void);
  152. STDMETHOD(IsUpToDate) (void);
  153. STDMETHOD(GetUserClassID) ( CLSID FAR* pClsid);
  154. STDMETHOD(GetUserType) ( DWORD dwFormOfType,
  155. LPOLESTR FAR* pszUserType);
  156. STDMETHOD(SetExtent) ( DWORD dwDrawAspect, LPSIZEL lpsizel);
  157. STDMETHOD(GetExtent) ( DWORD dwDrawAspect, LPSIZEL lpsizel);
  158. STDMETHOD(Advise)(IAdviseSink FAR* pAdvSink,
  159. DWORD FAR* pdwConnection);
  160. STDMETHOD(Unadvise)( DWORD dwConnection);
  161. STDMETHOD(EnumAdvise) ( LPENUMSTATDATA FAR* ppenumAdvise);
  162. STDMETHOD(GetMiscStatus) ( DWORD dwAspect,
  163. DWORD FAR* pdwStatus);
  164. STDMETHOD(SetColorScheme) ( LPLOGPALETTE lpLogpal);
  165. // IPeristStorage methods
  166. INTERNAL_(IPersistStorage *) GetPSDelegate(void);
  167. STDMETHOD(GetClassID) ( LPCLSID pClassID);
  168. STDMETHOD(IsDirty) (void);
  169. STDMETHOD(InitNew) ( LPSTORAGE pstg);
  170. STDMETHOD(Load) ( LPSTORAGE pstg);
  171. STDMETHOD(Save) ( LPSTORAGE pstgSave, BOOL fSameAsLoad);
  172. STDMETHOD(SaveCompleted) ( LPSTORAGE pstgNew);
  173. STDMETHOD(HandsOffStorage) ( void);
  174. // IRunnable Object methods
  175. STDMETHOD(GetRunningClass) (LPCLSID lpClsid);
  176. STDMETHOD(Run) (LPBINDCTX pbc);
  177. STDMETHOD_(BOOL, IsRunning) (void);
  178. STDMETHOD(LockRunning)(BOOL fLock, BOOL fLastUnlockCloses);
  179. STDMETHOD(SetContainedObject)(BOOL fContained);
  180. INTERNAL Stop(void);
  181. // IExternalConnection methods
  182. STDMETHOD_(DWORD, AddConnection) (THIS_ DWORD extconn,
  183. DWORD reserved);
  184. STDMETHOD_(DWORD, ReleaseConnection) (THIS_ DWORD extconn,
  185. DWORD reserved, BOOL fLastReleaseCloses);
  186. // NOTE: the advise sink has a separate controlling unknown from the
  187. // other interfaces; the lifetime of the memory for this implementation
  188. // is still the same as the default handler. The ramifications of
  189. // this are that when the default handler goes away it must make sure
  190. // that all pointers back to the sink are released; see the special
  191. // code in the dtor of the default handler.
  192. class CAdvSinkImpl : public IAdviseSink
  193. {
  194. public:
  195. // IUnknown methods
  196. STDMETHOD(QueryInterface) ( REFIID iid, LPVOID FAR* ppvObj);
  197. STDMETHOD_(ULONG,AddRef) (void);
  198. STDMETHOD_(ULONG,Release) (void);
  199. // *** IAdviseSink methods ***
  200. STDMETHOD_(void,OnDataChange)( FORMATETC FAR* pFormatetc,
  201. STGMEDIUM FAR* pStgmed);
  202. STDMETHOD_(void,OnViewChange)( DWORD aspects, LONG lindex);
  203. STDMETHOD_(void,OnRename)( IMoniker FAR* pmk);
  204. STDMETHOD_(void,OnSave)(void);
  205. STDMETHOD_(void,OnClose)(void);
  206. };
  207. friend class CAdvSinkImpl;
  208. CAdvSinkImpl m_AdviseSink;
  209. #ifdef _DEBUG
  210. HRESULT Dump(char **ppszDump, ULONG ulFlag, int nIndentLevel);
  211. // need to be able to access CDefObject private data members in the
  212. // following debugger extension APIs
  213. // this allows the debugger extension APIs to copy memory from the
  214. // debuggee process memory to the debugger's process memory
  215. // this is required since the Dump method follows pointers to other
  216. // structures and classes
  217. friend DEBUG_EXTENSION_API(dump_defobject);
  218. #endif // _DEBUG
  219. private:
  220. CDefObject (IUnknown *pUnkOuter);
  221. virtual ~CDefObject (void);
  222. virtual void CleanupFn(void);
  223. INTERNAL_(ULONG) CheckDelete(ULONG ulRet);
  224. INTERNAL GetClassBits(CLSID FAR* pClsidBits);
  225. INTERNAL CreateDelegate(void);
  226. INTERNAL DoConversionIfSpecialClass(LPSTORAGE pstg);
  227. // Member Variables for Server Handler.
  228. #ifdef SERVER_HANDLER
  229. CEmbServerWrapper* m_pEmbSrvHndlrWrapper; // Pointer to local wrapping interface.
  230. HRESULT m_hresultClsidUser; // hresult from call to GetUserClassID
  231. HRESULT m_hresultContentMiscStatus; // hresult from Call to GetMiscStatus for DVASPECT_CONTENT
  232. CLSID m_clsidUser; // clsid returned by GetUserClassID
  233. DWORD m_ContentMiscStatusUser; // MiscStatus returned be GetMiscStatus for DVASPECT_CONTENT
  234. // Todo: Move to EmbServerWrapper
  235. IOleClientSite * m_pRunClientSite; // ClientSite used when Run was Called.
  236. #endif // SERVER_HANDLER
  237. // Member variables for caching MiscStatus bits
  238. HRESULT m_ContentSRVMSHResult;
  239. DWORD m_ContentSRVMSBits;
  240. HRESULT m_ContentREGMSHResult;
  241. DWORD m_ContentREGMSBits;
  242. IOleObject * m_pOleDelegate;
  243. IDataObject * m_pDataDelegate;
  244. IPersistStorage * m_pPSDelegate;
  245. DWORD m_cConnections;
  246. IUnknown * m_pUnkOuter;
  247. CLSID m_clsidServer; // clsid of app we will run
  248. CLSID m_clsidBits; // clsid of bits on disk;
  249. // NULL init
  250. DWORD m_flags; // handler flags
  251. DWORD m_dwObjFlags; // OBJFLAGS of OLESTREAM
  252. IClassFactory * m_pCFDelegate; // only set if delayed create
  253. IUnknown * m_pUnkDelegate;
  254. IProxyManager * m_pProxyMgr;
  255. // m_fForcedRunning indicates that the container forced the object
  256. // running via ::Run or DoVerb. Handlers (EMBDHLP_INPROC_HANDLER) can
  257. // can go running implicitly via marshaling (usually via moniker bind)
  258. // and thus we actually use pProxyMgr->IsConnected to answer IsRunning.
  259. // Distinguishes between embeddings and links. We cannot use
  260. // m_pStg because it gets set to NULL in HandsOffStorage.
  261. // data cache
  262. COleCache * m_pCOleCache; // pointer to COleCache
  263. // ole advise info
  264. COAHolder * m_pOAHolder;
  265. DWORD m_dwConnOle; // if not 0L, ole advise conn.
  266. // info passed to server on run
  267. IOleClientSite * m_pAppClientSite;
  268. IStorage * m_pStg; // may be NULL
  269. char * m_pHostNames; // store both host name strings
  270. DWORD m_ibCntrObj; // offset into m_pHostNames
  271. LPDATAADVCACHE m_pDataAdvCache;
  272. };