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.

406 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: urlmarsh.cxx
  7. //
  8. // Contents: CUrlMarshal methods implementations
  9. // to support custom marshaling
  10. //
  11. // Classes:
  12. //
  13. // Functions:
  14. //
  15. // History: 1-19-96 JohannP (Johann Posch) Created
  16. //
  17. //----------------------------------------------------------------------------
  18. #include <trans.h>
  19. #include "urlmk.hxx"
  20. PerfDbgTag(tagCUrlMarsh, "Urlmon", "Log CUrlMon Marshalling", DEB_URLMON);
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Method: CUrlMon::CanMarshalIID
  24. //
  25. // Synopsis: Checks whether this object supports marshalling this IID.
  26. //
  27. // Arguments: [riid] --
  28. //
  29. // Returns:
  30. //
  31. // History: 1-19-96 JohannP (Johann Posch) Created
  32. //
  33. // Notes:
  34. //
  35. //----------------------------------------------------------------------------
  36. inline BOOL CUrlMon::CanMarshalIID(REFIID riid)
  37. {
  38. DEBUG_ENTER((DBG_MONIKER,
  39. Bool,
  40. "CUrlMon::CanMarshalIID",
  41. "this=%#x, %#x",
  42. this, &riid
  43. ));
  44. // keep this in sync with the QueryInterface
  45. BOOL fRet = (BOOL) (riid == IID_IMoniker);
  46. DEBUG_LEAVE(fRet);
  47. return fRet;
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // Method: CUrlMon::ValidateMarshalParams
  52. //
  53. // Synopsis: Validates the standard set parameters that are passed into most
  54. // of the IMarshal methods
  55. //
  56. // Arguments: [riid] --
  57. // [pvInterface] --
  58. // [dwDestContext] --
  59. // [pvDestContext] --
  60. // [mshlflags] --
  61. //
  62. // Returns:
  63. //
  64. // History: 1-19-96 JohannP (Johann Posch) Created
  65. //
  66. // Notes:
  67. //
  68. //----------------------------------------------------------------------------
  69. HRESULT CUrlMon::ValidateMarshalParams(REFIID riid,void *pvInterface,
  70. DWORD dwDestContext,void *pvDestContext,DWORD mshlflags)
  71. {
  72. DEBUG_ENTER((DBG_MONIKER,
  73. Hresult,
  74. "CUrlMon::ValidateMarshalParams",
  75. "this=%#x, %#x, %#x, %#x, %#x, %#x",
  76. this, &riid, pvInterface, dwDestContext, pvDestContext, mshlflags
  77. ));
  78. PerfDbgLog(tagCUrlMarsh, this, "+CUrlMon::ValidateMarshalParams");
  79. HRESULT hr = NOERROR;
  80. if (CanMarshalIID(riid))
  81. {
  82. UrlMkAssert((dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_LOCAL || dwDestContext == MSHCTX_NOSHAREDMEM));
  83. UrlMkAssert((mshlflags == MSHLFLAGS_NORMAL || mshlflags == MSHLFLAGS_TABLESTRONG));
  84. if ( (dwDestContext != MSHCTX_INPROC && dwDestContext != MSHCTX_LOCAL && dwDestContext != MSHCTX_NOSHAREDMEM)
  85. || (mshlflags != MSHLFLAGS_NORMAL && mshlflags != MSHLFLAGS_TABLESTRONG))
  86. {
  87. hr = E_INVALIDARG;
  88. }
  89. }
  90. else
  91. {
  92. hr = E_NOINTERFACE;
  93. }
  94. PerfDbgLog1(tagCUrlMarsh, this, "-CUrlMon::ValidateMarshalParams (hr:%lx)", hr);
  95. DEBUG_LEAVE(hr);
  96. return hr;
  97. }
  98. //+---------------------------------------------------------------------------
  99. //
  100. // IMarshal methods
  101. //
  102. //+---------------------------------------------------------------------------
  103. //
  104. // Method: CUrlMon::GetUnmarshalClass
  105. //
  106. // Synopsis:
  107. //
  108. // Arguments: [riid] --
  109. // [pvInterface] --
  110. // [dwDestContext] --
  111. // [pvDestContext] --
  112. // [mshlflags] --
  113. // [pCid] --
  114. //
  115. // Returns:
  116. //
  117. // History: 1-19-96 JohannP (Johann Posch) Created
  118. //
  119. // Notes:
  120. //
  121. //----------------------------------------------------------------------------
  122. STDMETHODIMP CUrlMon::GetUnmarshalClass(REFIID riid,void *pvInterface,
  123. DWORD dwDestContext,void *pvDestContext,DWORD mshlflags,CLSID *pCid)
  124. {
  125. DEBUG_ENTER((DBG_MONIKER,
  126. Hresult,
  127. "CUrlMon::IMarshal::GetUnmarshalClass",
  128. "this=%#x, %#x, %#x, %#x, %#x, %#x, %#x",
  129. this, &riid, pvInterface, dwDestContext, pvDestContext, mshlflags, pCid
  130. ));
  131. HRESULT hr;
  132. PerfDbgLog(tagCUrlMarsh, this, "+CUrlMon::GetUnmarshalClass");
  133. hr = ValidateMarshalParams(riid, pvInterface, dwDestContext,pvDestContext, mshlflags);
  134. if (hr == NOERROR)
  135. {
  136. *pCid = (CLSID) CLSID_StdURLMoniker;
  137. }
  138. PerfDbgLog1(tagCUrlMarsh, this, "-CUrlMon::GetUnmarshalClass (hr:%lx)", hr);
  139. DEBUG_LEAVE(hr);
  140. return hr;
  141. }
  142. //+---------------------------------------------------------------------------
  143. //
  144. // Method: CUrlMon::GetMarshalSizeMax
  145. //
  146. // Synopsis:
  147. //
  148. // Arguments: [void] --
  149. // [pvInterface] --
  150. // [dwDestContext] --
  151. // [pvDestContext] --
  152. // [mshlflags] --
  153. // [pSize] --
  154. //
  155. // Returns:
  156. //
  157. // History: 1-19-96 JohannP (Johann Posch) Created
  158. //
  159. // Notes:
  160. //
  161. //----------------------------------------------------------------------------
  162. STDMETHODIMP CUrlMon::GetMarshalSizeMax(REFIID riid,void *pvInterface,
  163. DWORD dwDestContext,void *pvDestContext,DWORD mshlflags,DWORD *pSize)
  164. {
  165. DEBUG_ENTER((DBG_MONIKER,
  166. Hresult,
  167. "CUrlMon::IMarshal::GetMarshalSizeMax",
  168. "this=%#x, %#x, %#x, %#x, %#x, %#x, %#x",
  169. this, &riid, pvInterface, dwDestContext, pvDestContext, mshlflags, pSize
  170. ));
  171. HRESULT hr;
  172. PerfDbgLog(tagCUrlMarsh, this, "+CUrlMon::GetMarshalSizeMax");
  173. if (pSize == NULL)
  174. {
  175. hr = E_INVALIDARG;
  176. }
  177. else
  178. {
  179. hr = ValidateMarshalParams(riid, pvInterface, dwDestContext,pvDestContext, mshlflags);
  180. if (hr == NOERROR)
  181. {
  182. // size of url + extra info
  183. *pSize = (wcslen(_pwzUrl) + 1) * sizeof(WCHAR) + sizeof(ULONG);
  184. // Note: add state info
  185. }
  186. }
  187. PerfDbgLog1(tagCUrlMarsh, this, "-CUrlMon::GetMarshalSizeMax (hr:%lx)", hr);
  188. DEBUG_LEAVE(hr);
  189. return hr;
  190. }
  191. //+---------------------------------------------------------------------------
  192. //
  193. // Method: CUrlMon::MarshalInterface
  194. //
  195. // Synopsis:
  196. //
  197. // Arguments: [REFIID] --
  198. // [riid] --
  199. // [DWORD] --
  200. // [void] --
  201. // [DWORD] --
  202. // [mshlflags] --
  203. //
  204. // Returns:
  205. //
  206. // History: 1-19-96 JohannP (Johann Posch) Created
  207. //
  208. // Notes:
  209. //
  210. //----------------------------------------------------------------------------
  211. STDMETHODIMP CUrlMon::MarshalInterface(IStream *pistm,REFIID riid,
  212. void *pvInterface,DWORD dwDestContext,
  213. void *pvDestContext,DWORD mshlflags)
  214. {
  215. DEBUG_ENTER((DBG_MONIKER,
  216. Hresult,
  217. "CUrlMon::IMarshal::MarshalInterface",
  218. "this=%#x, %#x, %#x, %#x, %#x, %#x, %#x",
  219. this, pistm, &riid, pvInterface, dwDestContext, pvDestContext, mshlflags
  220. ));
  221. HRESULT hr;
  222. PerfDbgLog(tagCUrlMarsh, this, "+CUrlMon::MarshalInterface");
  223. hr = ValidateMarshalParams(riid, pvInterface, dwDestContext,pvDestContext, mshlflags);
  224. if (hr == NOERROR)
  225. {
  226. hr = Save(pistm, FALSE);
  227. }
  228. PerfDbgLog1(tagCUrlMarsh, this, "-CUrlMon::MarshalInterface (hr:%lx)", hr);
  229. DEBUG_LEAVE(hr);
  230. return hr;
  231. }
  232. //+---------------------------------------------------------------------------
  233. //
  234. // Method: CUrlMon::UnmarshalInterface
  235. //
  236. // Synopsis: Unmarshals an Urlmon interface out of a stream
  237. //
  238. // Arguments: [REFIID] --
  239. // [void] --
  240. // [ppvObj] --
  241. //
  242. // Returns:
  243. //
  244. // History: 1-19-96 JohannP (Johann Posch) Created
  245. //
  246. // Notes:
  247. //
  248. //----------------------------------------------------------------------------
  249. STDMETHODIMP CUrlMon::UnmarshalInterface(IStream *pistm,REFIID riid,void ** ppvObj)
  250. {
  251. DEBUG_ENTER((DBG_MONIKER,
  252. Hresult,
  253. "CUrlMon::IMarshal::UnmarshalInterface",
  254. "this=%#x, %#x, %#x, %#x",
  255. this, pistm, &riid, ppvObj
  256. ));
  257. HRESULT hr = NOERROR;
  258. PerfDbgLog(tagCUrlMarsh, this, "+CUrlMon::UnmarshalInterface");
  259. if (ppvObj == NULL)
  260. {
  261. hr = E_INVALIDARG;
  262. }
  263. else if (! CanMarshalIID(riid))
  264. {
  265. *ppvObj = NULL;
  266. hr = E_NOINTERFACE;
  267. }
  268. else
  269. {
  270. *ppvObj = NULL;
  271. hr = Load(pistm);
  272. // call QI to get the requested interface
  273. if (hr == NOERROR)
  274. {
  275. hr = QueryInterface(riid, ppvObj);
  276. }
  277. }
  278. PerfDbgLog1(tagCUrlMarsh, this, "-CUrlMon::UnmarshalInterface (hr:%lx)", hr);
  279. DEBUG_LEAVE(hr);
  280. return hr;
  281. }
  282. STDMETHODIMP CUrlMon::ReleaseMarshalData(IStream *pStm)
  283. {
  284. DEBUG_ENTER((DBG_MONIKER,
  285. Hresult,
  286. "CUrlMon::IMarshal::ReleaseMarshalData",
  287. "this=%#x, %#x",
  288. this, pStm
  289. ));
  290. PerfDbgLog(tagCUrlMarsh, this, "+CUrlMon::ReleaseMarshalData");
  291. PerfDbgLog1(tagCUrlMarsh, this, "-CUrlMon::ReleaseMarshalData (hr:%lx)", NOERROR);
  292. DEBUG_LEAVE(NOERROR);
  293. return NOERROR;
  294. }
  295. STDMETHODIMP CUrlMon::DisconnectObject(DWORD dwReserved)
  296. {
  297. DEBUG_ENTER((DBG_MONIKER,
  298. Hresult,
  299. "CUrlMon::IMarshal::DisconnectObject",
  300. "this=%#x, %#x",
  301. this, dwReserved
  302. ));
  303. PerfDbgLog(tagCUrlMarsh, this, "+CUrlMon::DisconnectObject");
  304. PerfDbgLog1(tagCUrlMarsh, this, "-CUrlMon::DisconnectObject (hr:%lx)", NOERROR);
  305. DEBUG_LEAVE(NOERROR);
  306. return NOERROR;
  307. }
  308. //+---------------------------------------------------------------------------
  309. //
  310. // Method: CUrlMon::GetComparisonData
  311. //
  312. // Synopsis:
  313. //
  314. // Arguments: [pbData] --
  315. // [cbMax] --
  316. // [pcbData] --
  317. //
  318. // Returns:
  319. //
  320. // History: 1-22-96 JohannP (Johann Posch) Created
  321. //
  322. // Notes:
  323. //
  324. //----------------------------------------------------------------------------
  325. STDMETHODIMP CUrlMon::GetComparisonData(byte *pbData, ULONG cbMax, ULONG *pcbData)
  326. {
  327. DEBUG_ENTER((DBG_MONIKER,
  328. Hresult,
  329. "CUrlMon::IROTData::GetComparisonData",
  330. "this=%#x, %#x, %#x, %#x",
  331. this, pbData, cbMax, pcbData
  332. ));
  333. PerfDbgLog(tagCUrlMarsh, this, "+CUrlMon::GetComparisonData");
  334. HRESULT hr = NOERROR;
  335. if (pbData == NULL || pcbData == NULL)
  336. {
  337. hr = E_INVALIDARG;
  338. }
  339. else
  340. {
  341. UrlMkAssert((_pwzUrl != NULL));
  342. *pcbData = (wcslen(_pwzUrl) + 1) * sizeof(WCHAR);
  343. if (*pcbData > cbMax)
  344. {
  345. hr = E_FAIL;
  346. }
  347. else
  348. {
  349. wcscpy((WCHAR*)pbData,_pwzUrl);
  350. }
  351. }
  352. PerfDbgLog1(tagCUrlMarsh, this, "-CUrlMon::GetComparisonData (hr:%lx)", hr);
  353. DEBUG_LEAVE(NOERROR);
  354. return NOERROR;
  355. }