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.

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