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.

447 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: cnetstrm.cxx
  7. //
  8. // Contents: Implements the stream: protocol
  9. //
  10. // Classes: CINetStream
  11. //
  12. // Functions:
  13. //
  14. // History: 5/3/96 Created Craig Critchley [craigc]
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <iapp.h>
  18. #include <shlwapip.h>
  19. PerfDbgTag(tagCINetStream, "Urlmon", "Log CINetStream", DEB_PROT);
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Method: CINetStream::CINetStream
  23. //
  24. // Synopsis: Constructs a stream protcol object
  25. //
  26. // Arguments: rclsid
  27. //
  28. // Returns:
  29. //
  30. // History: 5/3/96 Created Craig Critchley [craigc]
  31. //
  32. // Notes:
  33. //
  34. //----------------------------------------------------------------------------
  35. CINetStream::CINetStream(REFCLSID rclsid, IUnknown *pUnkOuter) : CINet(rclsid,pUnkOuter)
  36. {
  37. DEBUG_ENTER((DBG_APP,
  38. None,
  39. "CINetStream::CINetStream",
  40. "this=%#x, %#x, %#x",
  41. this, &rclsid, pUnkOuter
  42. ));
  43. PerfDbgLog(tagCINetStream, this, "CINetStream::CINetStream");
  44. _dwIsA = DLD_PROTOCOL_STREAM;
  45. _pstm = NULL;
  46. DEBUG_LEAVE(0);
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Method: CINetStream::~CINetStream
  51. //
  52. // Synopsis: destroys a stream protocol object
  53. //
  54. // Arguments:
  55. //
  56. // Returns:
  57. //
  58. // History: 5/3/96 Created Craig Critchley [craigc]
  59. //
  60. // Notes:
  61. //
  62. //----------------------------------------------------------------------------
  63. CINetStream::~CINetStream()
  64. {
  65. DEBUG_ENTER((DBG_APP,
  66. None,
  67. "CINetStream::~CINetStream",
  68. "this=%#x",
  69. this
  70. ));
  71. PerfDbgLog(tagCINetStream, this, "CINetStream::~CInetStream");
  72. if (_pstm)
  73. {
  74. _pstm->Release();
  75. }
  76. DEBUG_LEAVE(0);
  77. }
  78. //+---------------------------------------------------------------------------
  79. //
  80. // Method: CINetStream::INetAsyncOpen
  81. //
  82. // Synopsis: opens and synchronously downloads data from a stream
  83. //
  84. // Arguments: rclsid
  85. //
  86. // Returns:
  87. //
  88. // History: 5/3/96 Created Craig Critchley [craigc]
  89. //
  90. // Notes:
  91. //
  92. //----------------------------------------------------------------------------
  93. HRESULT CINetStream::INetAsyncOpen()
  94. {
  95. DEBUG_ENTER((DBG_APP,
  96. Hresult,
  97. "CINetStream::INetAsyncOpen",
  98. "this=%#x",
  99. this
  100. ));
  101. PerfDbgLog(tagCINetStream, this, "+CINetStream::INetAsyncOpen");
  102. IBindCtx * pbc = 0;
  103. IMoniker * pmk = 0;
  104. IStream * pstm = 0;
  105. IParseDisplayName * pParser = 0;
  106. STATSTG stat;
  107. CLSID clsid;
  108. CHAR szDisplayName[MAX_PATH];
  109. WCHAR wzDisplayName[MAX_PATH];
  110. WCHAR wzProgId[MAX_PATH];
  111. LPSTR pa, psz;
  112. LPWSTR pwz, pwzI;
  113. int cch;
  114. HRESULT hr = E_NOTIMPL;
  115. ULONG cchE;
  116. BOOL fGotMIMEType = FALSE;
  117. ULONG cchServerName, cchObjectName;
  118. ReportNotification(BINDSTATUS_SENDINGREQUEST);
  119. // need one of these
  120. //
  121. if (FAILED(hr = CreateBindCtx(0,&pbc)))
  122. goto End;
  123. // form is mk:@progid:moniker
  124. //
  125. cchServerName = strlen(GetServerName());
  126. cchObjectName = strlen(GetObjectName());
  127. if ((cchServerName + cchObjectName) >= MAX_PATH)
  128. {
  129. hr = E_FAIL;
  130. goto End;
  131. }
  132. strcpy(szDisplayName,GetServerName());
  133. strcat(szDisplayName,psz = GetObjectName());
  134. // if the moniker has a file extension, try to
  135. // determine the MIME type that way...
  136. //
  137. psz = FindFileExtension(psz);
  138. if (psz)
  139. {
  140. char szMime[MAX_PATH];
  141. DWORD cb = MAX_PATH;
  142. if (SUCCEEDED(GetMimeFromExt(psz,szMime,&cb)))
  143. {
  144. ReportNotification(BINDSTATUS_MIMETYPEAVAILABLE, szMime);
  145. fGotMIMEType = TRUE;
  146. }
  147. }
  148. A2W(szDisplayName,wzDisplayName,MAX_PATH);
  149. // find progid
  150. //
  151. for (pwz = wzDisplayName, pwzI = wzProgId; *pwz; pwz++)
  152. {
  153. if (*pwz == '@')
  154. {
  155. pwzI = wzProgId;
  156. }
  157. else if (*pwz == ':')
  158. {
  159. *pwzI = 0;
  160. // the remainder may have a filename with a useful
  161. // extension... just in case, set the filename...
  162. //
  163. LPSTR pszStr = DupW2A(pwz+1);
  164. if (pszStr)
  165. {
  166. ReportNotification(BINDSTATUS_CACHEFILENAMEAVAILABLE, pszStr);
  167. delete pszStr;
  168. }
  169. break;
  170. }
  171. else
  172. {
  173. *pwzI++ = *pwz;
  174. }
  175. }
  176. #if 0
  177. if (FAILED(hr = MkParseDisplayName(pbc,wzDisplayName,&cchE,&pmk)) && pmk)
  178. goto End;
  179. #else
  180. // BUGBUG
  181. //
  182. // MkParseDisplayName was opening another instance of app
  183. // force inproc server. ick.
  184. //
  185. if (FAILED(hr = CLSIDFromProgID(wzProgId,&clsid)))
  186. {
  187. goto End;
  188. }
  189. if (FAILED(hr = CoCreateInstance(clsid,0,CLSCTX_INPROC_SERVER,
  190. IID_IParseDisplayName,(void**)&pParser)))
  191. {
  192. goto End;
  193. }
  194. PProtAssert((pParser));
  195. if (FAILED(hr = pParser->ParseDisplayName(pbc,wzDisplayName,&cchE,&pmk)))
  196. {
  197. goto End;
  198. }
  199. PProtAssert((pmk));
  200. #endif
  201. if (FAILED(hr = pmk->BindToStorage(pbc,0,IID_IStream,(void**)&pstm)))
  202. {
  203. hr = INET_E_RESOURCE_NOT_FOUND;
  204. goto End;
  205. }
  206. PProtAssert((hr != MK_S_ASYNCHRONOUS));
  207. PProtAssert((pstm));
  208. _pstm = pstm;
  209. _pstm->AddRef();
  210. // now we have a stream - stuff it into the trans data
  211. //
  212. if (FAILED(hr = pstm->Stat(&stat,STATFLAG_NONAME)))
  213. {
  214. goto End;
  215. }
  216. _cbTotalBytesRead = stat.cbSize.LowPart;
  217. _cbDataSize = stat.cbSize.LowPart;
  218. ReportResultAndStop(NOERROR, _cbTotalBytesRead, _cbDataSize );
  219. _hrError = INET_E_DONE;
  220. End:
  221. if (FAILED(hr))
  222. {
  223. SetCNetBindResult(GetLastError());
  224. hr = _hrError = INET_E_RESOURCE_NOT_FOUND;
  225. ReportResultAndStop(_hrError);
  226. }
  227. // play nice, no leaks
  228. //
  229. if (pParser)
  230. {
  231. pParser->Release();
  232. }
  233. if (pmk)
  234. {
  235. pmk->Release();
  236. }
  237. if (pbc)
  238. {
  239. pbc->Release();
  240. }
  241. if (pstm)
  242. {
  243. pstm->Release();
  244. }
  245. // make sure I set this any way I get out
  246. //
  247. PProtAssert((hr != E_NOTIMPL));
  248. PerfDbgLog1(tagCINetStream, this, "-CINetStream::INetAsyncOpen (hr:%lx)", hr);
  249. DEBUG_LEAVE(hr);
  250. return hr;
  251. }
  252. //+---------------------------------------------------------------------------
  253. //
  254. // Method: CINetStream::Read
  255. //
  256. // Synopsis:
  257. //
  258. // Arguments: [pBuffer] --
  259. // [cbBytes] --
  260. // [pcbBytes] --
  261. //
  262. // Returns:
  263. //
  264. // History: 10-29-1996 JohannP (Johann Posch) Created
  265. //
  266. // Notes:
  267. //
  268. //----------------------------------------------------------------------------
  269. STDMETHODIMP CINetStream::Read(void *pBuffer, DWORD cbBytes, DWORD *pcbBytes)
  270. {
  271. DEBUG_ENTER((DBG_APP,
  272. Hresult,
  273. "CINetStream::IInternetProtocol::Read",
  274. "this=%#x, %#x, %#x, %#x",
  275. this, pBuffer, cbBytes, pcbBytes
  276. ));
  277. PerfDbgLog(tagCINetStream, this, "+CINetStream::Read");
  278. HRESULT hr = E_FAIL;
  279. PProtAssert((cbBytes && pcbBytes));
  280. if (_pstm)
  281. {
  282. hr = _pstm->Read(pBuffer,cbBytes,pcbBytes);
  283. }
  284. PerfDbgLog4(tagCINetStream, this, "-CINetStream::Read (_hrError:%lx, [hr:%lx,cbBytesAsked:%ld,cbBytesReturned:%ld])",
  285. _hrError, hr, cbBytes, *pcbBytes);
  286. DEBUG_LEAVE(hr);
  287. return hr;
  288. }
  289. //+---------------------------------------------------------------------------
  290. //
  291. // Method: CINetStream::INetSeek
  292. //
  293. // Synopsis:
  294. //
  295. // Arguments: [DWORD] --
  296. // [ULARGE_INTEGER] --
  297. // [plibNewPosition] --
  298. //
  299. // Returns:
  300. //
  301. // History: 10-29-1996 JohannP (Johann Posch) Created
  302. //
  303. // Notes:
  304. //
  305. //----------------------------------------------------------------------------
  306. HRESULT CINetStream::INetSeek(LARGE_INTEGER dlibMove,DWORD dwOrigin,ULARGE_INTEGER *plibNewPosition)
  307. {
  308. DEBUG_ENTER((DBG_APP,
  309. Hresult,
  310. "CINetStream::INetSeek",
  311. "this=%#x",
  312. this, dlibMove, dwOrigin, plibNewPosition
  313. ));
  314. PerfDbgLog(tagCINetStream, this, "+CINetStream::INetSeek");
  315. HRESULT hr = E_FAIL;
  316. if (_pstm)
  317. {
  318. hr = _pstm->Seek(dlibMove, dwOrigin, plibNewPosition);
  319. }
  320. PerfDbgLog1(tagCINetStream, this, "-CINetStream::INetSeek (hr:%lx)", hr);
  321. DEBUG_LEAVE(hr);
  322. return hr;
  323. }
  324. //+---------------------------------------------------------------------------
  325. //
  326. // Method: CINetStream::LockFile
  327. //
  328. // Synopsis:
  329. //
  330. // Arguments:
  331. //
  332. // Returns:
  333. //
  334. // History: 8-13-96 JohannP (Johann Posch) Created
  335. //
  336. // Notes:
  337. //
  338. //----------------------------------------------------------------------------
  339. HRESULT CINetStream::LockFile(BOOL fRetrieve)
  340. {
  341. DEBUG_ENTER((DBG_APP,
  342. Hresult,
  343. "CINetStream::LockFile",
  344. "this=%#x, %B",
  345. this, fRetrieve
  346. ));
  347. PerfDbgLog(tagCINetStream, this, "+CINetStream::LockFile");
  348. HRESULT hr = NOERROR;
  349. // nothing to do for now
  350. PerfDbgLog1(tagCINetStream, this, "-CINetStream::LockFile (hr:%lx)", hr);
  351. DEBUG_LEAVE(hr);
  352. return hr;
  353. }
  354. //+---------------------------------------------------------------------------
  355. //
  356. // Method: CINetStream::UnlockFile
  357. //
  358. // Synopsis: unlocks the file
  359. //
  360. // Arguments: (none)
  361. //
  362. // Returns:
  363. //
  364. // History: 8-13-96 JohannP (Johann Posch) Created
  365. //
  366. // Notes:
  367. //
  368. //----------------------------------------------------------------------------
  369. HRESULT CINetStream::UnlockFile()
  370. {
  371. DEBUG_ENTER((DBG_APP,
  372. Hresult,
  373. "CINetStream::UnlockFile",
  374. "this=%#x",
  375. this
  376. ));
  377. PerfDbgLog(tagCINetStream, this, "+CINetStream::UnlockFile");
  378. HRESULT hr = NOERROR;
  379. // nothing to do for now
  380. PerfDbgLog1(tagCINetStream, this, "-CINetStream::UnlockFile (hr:%lx)", hr);
  381. DEBUG_LEAVE(hr);
  382. return hr;
  383. }