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.

632 lines
15 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: resprot.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 11-07-1996 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <eapp.h>
  18. #include <tchar.h>
  19. #define MAX_ID 10000
  20. #define WITH_TAGS
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Method: CMulticastProtocol::Start
  24. //
  25. // Synopsis:
  26. //
  27. // Arguments: [pwzUrl] --
  28. // [pTrans] --
  29. // [pOIBindInfo] --
  30. // [grfSTI] --
  31. // [dwReserved] --
  32. //
  33. // Returns:
  34. //
  35. // History: 10-29-1996 JohannP (Johann Posch) Created
  36. //
  37. // Notes:
  38. //
  39. //----------------------------------------------------------------------------
  40. STDMETHODIMP CMulticastProtocol::Start(LPCWSTR pwzUrl, IOInetProtocolSink *pTrans, IOInetBindInfo *pOIBindInfo,
  41. DWORD grfSTI, DWORD dwReserved)
  42. {
  43. EProtDebugOut((DEB_PLUGPROT, "%p _IN CMulticastProtocol::Start\n", this));
  44. HRESULT hr = NOERROR;
  45. WCHAR wzURL[MAX_URL_SIZE];
  46. EProtAssert((!_pProtSink && pOIBindInfo && pTrans));
  47. EProtAssert((_pwzUrl == NULL));
  48. hr = CBaseProtocol::Start(pwzUrl,pTrans, pOIBindInfo, grfSTI, dwReserved);
  49. if ( (grfSTI & PI_PARSE_URL) )
  50. {
  51. hr = ParseAndBind(FALSE);
  52. }
  53. else if (hr == NOERROR)
  54. {
  55. // asked to go async as soon as possible
  56. // use the switch mechanism which will \
  57. // call back later on ::Continue
  58. if (grfSTI & PI_FORCE_ASYNC)
  59. {
  60. hr = E_PENDING;
  61. PROTOCOLDATA protdata;
  62. protdata.grfFlags = PI_FORCE_ASYNC;
  63. protdata.dwState = RES_STATE_BIND;
  64. protdata.pData = 0;
  65. protdata.cbData = 0;
  66. _pProtSink->Switch(&protdata);
  67. }
  68. else
  69. {
  70. hr = ParseAndBind(TRUE);
  71. }
  72. }
  73. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::Start (hr:%lx)\n",this, hr));
  74. return hr;
  75. }
  76. //+---------------------------------------------------------------------------
  77. //
  78. // Method: CMulticastProtocol::Continue
  79. //
  80. // Synopsis:
  81. //
  82. // Arguments: [pStateInfoIn] --
  83. //
  84. // Returns:
  85. //
  86. // History: 10-29-1996 JohannP (Johann Posch) Created
  87. //
  88. // Notes:
  89. //
  90. //----------------------------------------------------------------------------
  91. STDMETHODIMP CMulticastProtocol::Continue(PROTOCOLDATA *pStateInfoIn)
  92. {
  93. EProtDebugOut((DEB_PLUGPROT, "%p _IN CMulticastProtocol::Continue\n", this));
  94. HRESULT hr = E_FAIL;
  95. EProtAssert((!pStateInfoIn->pData && pStateInfoIn->cbData && (pStateInfoIn->dwState == RES_STATE_BIND)));
  96. if (pStateInfoIn->dwState == RES_STATE_BIND)
  97. {
  98. hr = ParseAndBind();
  99. }
  100. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::Continue (hr:%lx)\n",this, hr));
  101. return hr;
  102. }
  103. //+---------------------------------------------------------------------------
  104. //
  105. // Method: CMulticastProtocol::Read
  106. //
  107. // Synopsis:
  108. //
  109. // Arguments: [ULONG] --
  110. // [ULONG] --
  111. // [pcbRead] --
  112. //
  113. // Returns:
  114. //
  115. // History: 10-29-1996 JohannP (Johann Posch) Created
  116. //
  117. // Notes:
  118. //
  119. //----------------------------------------------------------------------------
  120. STDMETHODIMP CMulticastProtocol::Read(void *pv,ULONG cb,ULONG *pcbRead)
  121. {
  122. EProtDebugOut((DEB_PLUGPROT, "%p _IN CMulticastProtocol::Read (cb:%ld)\n", this,cb));
  123. HRESULT hr = NOERROR;
  124. if (_cbBuffer > _cbPos)
  125. {
  126. ULONG cbCopy = (cb < (_cbBuffer - _cbPos)) ? cb : _cbBuffer - _cbPos;
  127. memcpy((LPVOID)pv, ((LPBYTE)_pBuffer) + _cbPos, cbCopy);
  128. _cbPos += cbCopy;
  129. *pcbRead = cbCopy;
  130. hr = (_cbPos < _cbBuffer) ? S_OK : S_FALSE;
  131. }
  132. else
  133. {
  134. hr = S_FALSE;
  135. }
  136. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::Read (pcbRead:%ld, hr:%lx)\n",this,*pcbRead, hr));
  137. return hr;
  138. }
  139. //+---------------------------------------------------------------------------
  140. //
  141. // Method: CMulticastProtocol::Seek
  142. //
  143. // Synopsis:
  144. //
  145. // Arguments: [DWORD] --
  146. // [ULARGE_INTEGER] --
  147. // [plibNewPosition] --
  148. //
  149. // Returns:
  150. //
  151. // History: 10-29-1996 JohannP (Johann Posch) Created
  152. //
  153. // Notes: WORK: not done
  154. //
  155. //----------------------------------------------------------------------------
  156. STDMETHODIMP CMulticastProtocol::Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,ULARGE_INTEGER *plibNewPosition)
  157. {
  158. EProtDebugOut((DEB_PLUGPROT, "%p _IN CMulticastProtocol::Seek\n", this));
  159. HRESULT hr = NOERROR;
  160. if (dwOrigin == STREAM_SEEK_SET)
  161. {
  162. if (dlibMove.LowPart >= 0)
  163. {
  164. _cbPos = dlibMove.LowPart;
  165. if (plibNewPosition)
  166. {
  167. plibNewPosition->HighPart = 0;
  168. plibNewPosition->LowPart = _cbPos;
  169. }
  170. }
  171. else
  172. {
  173. hr = STG_E_INVALIDPOINTER;
  174. }
  175. }
  176. else
  177. {
  178. hr = E_NOTIMPL;
  179. }
  180. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::Seek (hr:%lx)\n",this, hr));
  181. return hr;
  182. }
  183. //+---------------------------------------------------------------------------
  184. //
  185. // Method: CMulticastProtocol::LockRequest
  186. //
  187. // Synopsis:
  188. //
  189. // Arguments: [dwOptions] --
  190. //
  191. // Returns:
  192. //
  193. // History: 10-29-1996 JohannP (Johann Posch) Created
  194. //
  195. // Notes:
  196. //
  197. //----------------------------------------------------------------------------
  198. STDMETHODIMP CMulticastProtocol::LockRequest(DWORD dwOptions)
  199. {
  200. EProtDebugOut((DEB_PLUGPROT, "%p _IN CMulticastProtocol::LockRequest\n", this));
  201. HRESULT hr = NOERROR;
  202. if (OpenTempFile())
  203. {
  204. DWORD dwWrite;
  205. if (!WriteFile(_hFile, _pBuffer, _cbBuffer, &dwWrite,NULL))
  206. {
  207. hr = E_FAIL;
  208. }
  209. CloseTempFile();
  210. }
  211. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::LockRequest (hr:%lx)\n",this, hr));
  212. return hr;
  213. }
  214. //+---------------------------------------------------------------------------
  215. //
  216. // Method: CMulticastProtocol::UnlockRequest
  217. //
  218. // Synopsis:
  219. //
  220. // Arguments: (none)
  221. //
  222. // Returns:
  223. //
  224. // History: 10-29-1996 JohannP (Johann Posch) Created
  225. //
  226. // Notes:
  227. //
  228. //----------------------------------------------------------------------------
  229. STDMETHODIMP CMulticastProtocol::UnlockRequest()
  230. {
  231. EProtDebugOut((DEB_PLUGPROT, "%p _IN CMulticastProtocol::UnlockRequest\n", this));
  232. HRESULT hr = NOERROR;
  233. //CloseTempFile();
  234. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::UnlockRequest (hr:%lx)\n",this, hr));
  235. return hr;
  236. }
  237. //+---------------------------------------------------------------------------
  238. //
  239. // Method: CMulticastProtocol::CMulticastProtocol
  240. //
  241. // Synopsis:
  242. //
  243. // Arguments: (none)
  244. //
  245. // Returns:
  246. //
  247. // History: 1-27-96 JohannP (Johann Posch) Created
  248. //
  249. // Notes:
  250. //
  251. //----------------------------------------------------------------------------
  252. CMulticastProtocol::CMulticastProtocol(REFCLSID rclsid, IUnknown *pUnkOuter, IUnknown **ppUnkInner) : CBaseProtocol(rclsid, pUnkOuter, ppUnkInner)
  253. {
  254. EProtDebugOut((DEB_PLUGPROT, "%p _IN CMulticastProtocol::CMulticastProtocol \n", this));
  255. _hInst = NULL;
  256. _cbBuffer = 0;
  257. _pBuffer = 0;
  258. _hgbl = 0;
  259. _cbPos = 0;
  260. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::CMulticastProtocol \n", this));
  261. }
  262. //+---------------------------------------------------------------------------
  263. //
  264. // Method: CMulticastProtocol::~CMulticastProtocol
  265. //
  266. // Synopsis:
  267. //
  268. // Arguments: (none)
  269. //
  270. // Returns:
  271. //
  272. // History: 11-09-1996 JohannP (Johann Posch) Created
  273. //
  274. // Notes:
  275. //
  276. //----------------------------------------------------------------------------
  277. CMulticastProtocol::~CMulticastProtocol()
  278. {
  279. if (_hgbl)
  280. {
  281. UnlockResource(_hgbl);
  282. }
  283. if (_hInst)
  284. {
  285. FreeLibrary(_hInst);
  286. }
  287. EProtDebugOut((DEB_PLUGPROT, "%p _IN/OUT CMulticastProtocol::~CMulticastProtocol \n", this));
  288. }
  289. //+---------------------------------------------------------------------------
  290. //
  291. // Method: CMulticastProtocol::GetResource
  292. //
  293. // Synopsis:
  294. //
  295. // Arguments: [pwzFileName] --
  296. // [pwzResName] --
  297. // [pwzResType] --
  298. //
  299. // Returns:
  300. //
  301. // History: 11-09-1996 JohannP (Johann Posch) Created
  302. //
  303. // Notes:
  304. //
  305. //----------------------------------------------------------------------------
  306. STDMETHODIMP CMulticastProtocol::GetResource(LPCWSTR pwzFileName, LPCWSTR pwzResName, LPCWSTR pwzResType, LPCWSTR pwzMime)
  307. {
  308. EProtDebugOut((DEB_PLUGPROT, "CMulticastProtocol::GetResource\n)"));
  309. HRESULT hr = NOERROR;
  310. DWORD dwError = 0;
  311. HRSRC hrsrc;
  312. LPSTR pszFileName = DupW2A(pwzFileName );
  313. LPSTR pszResName = DupW2A(pwzResName );
  314. LPSTR pszResType = DupW2A(pwzResType );
  315. if (!pszFileName || !pszResName || !pszResType)
  316. {
  317. hr = E_OUTOFMEMORY;
  318. }
  319. else do
  320. {
  321. _pProtSink->ReportProgress(BINDSTATUS_SENDINGREQUEST, pwzResName);
  322. _hInst = LoadLibraryEx(pszFileName, NULL, DONT_RESOLVE_DLL_REFERENCES);
  323. if (!_hInst)
  324. {
  325. hr = INET_E_RESOURCE_NOT_FOUND;
  326. dwError = GetLastError();
  327. break;
  328. }
  329. if (!wcscmp(pwzResName, L"?"))
  330. {
  331. for (int i = 0 ; i < MAX_ID; i++)
  332. {
  333. hrsrc = FindResource(_hInst, (LPSTR)MAKEINTRESOURCE(i), pszResType);
  334. if (hrsrc)
  335. {
  336. EProtDebugOut((DEB_PLUGPROT, "CMulticastProtocol::GetResource (szResName:#%ld, wzRestype:%s\n)",i,pszResType));
  337. i = MAX_ID;
  338. }
  339. }
  340. }
  341. else
  342. {
  343. hrsrc = FindResource(_hInst, pszResName, pszResType);
  344. }
  345. if (!hrsrc)
  346. {
  347. hr = INET_E_OBJECT_NOT_FOUND;
  348. dwError = GetLastError();
  349. break;
  350. }
  351. _hgbl = LoadResource(_hInst, hrsrc);
  352. if (!_hgbl)
  353. {
  354. hr = INET_E_DATA_NOT_AVAILABLE;
  355. dwError = GetLastError();
  356. break;
  357. }
  358. _pBuffer = LockResource(_hgbl);
  359. if (!_pBuffer)
  360. {
  361. hr = INET_E_DATA_NOT_AVAILABLE;
  362. dwError = GetLastError();
  363. break;
  364. }
  365. _cbBuffer = SizeofResource(_hInst, hrsrc);
  366. if (_grfBindF & INTERNET_FLAG_NEED_FILE)
  367. {
  368. LockRequest(0);
  369. }
  370. #ifdef UNUSED
  371. if (OpenTempFile())
  372. {
  373. DWORD dwWrite;
  374. if (!WriteFile(_hFile, _pBuffer, _cbBuffer, &dwWrite,NULL))
  375. {
  376. dwError = GetLastError();
  377. break;
  378. }
  379. CloseTempFile();
  380. }
  381. #endif //UNUSED
  382. hr = NOERROR;
  383. break;
  384. } while (1);
  385. if (dwError || (hr != NOERROR))
  386. {
  387. _pProtSink->ReportResult(hr, dwError, 0);
  388. }
  389. else
  390. {
  391. if (pwzMime)
  392. {
  393. _pProtSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, pwzMime);
  394. }
  395. _bscf |= BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE;
  396. _pProtSink->ReportData(_bscf, _cbBuffer, _cbBuffer);
  397. }
  398. if (pszFileName)
  399. {
  400. delete pszFileName;
  401. }
  402. if (pszResName)
  403. {
  404. delete pszResName;
  405. }
  406. if (pszResType)
  407. {
  408. delete pszResType;
  409. }
  410. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::GetResource (hr:%lx)\n",this, hr));
  411. return hr;
  412. }
  413. //+---------------------------------------------------------------------------
  414. //
  415. // Method: CMulticastProtocol::ParseAndBind
  416. //
  417. // Synopsis:
  418. //
  419. // Arguments: (none)
  420. //
  421. // Returns:
  422. //
  423. // History: 11-09-1996 JohannP (Johann Posch) Created
  424. //
  425. // Notes:
  426. //
  427. //----------------------------------------------------------------------------
  428. STDMETHODIMP CMulticastProtocol::ParseAndBind(BOOL fBind)
  429. {
  430. EProtDebugOut((DEB_PLUGPROT, "%p _IN CMulticastProtocol::ParseAndBind\n", this));
  431. HRESULT hr = MK_E_SYNTAX;
  432. WCHAR wzlURL[MAX_URL_SIZE];
  433. wcscpy(wzlURL, _wzFullURL);
  434. do
  435. {
  436. // check if protocol part
  437. LPWSTR pwz = wcschr(wzlURL, ':');
  438. pwz++;
  439. if (wcsnicmp(pwz, L"//", 2) && wcsnicmp(pwz, L"\\\\", 2))
  440. {
  441. break;
  442. }
  443. // find the file name and path
  444. LPWSTR pwzFileName = pwz + 2;
  445. EProtAssert((pwzFileName));
  446. // the file is
  447. LPWSTR pwz1 = wcsrchr(wzlURL, '/');
  448. if (!pwz1)
  449. {
  450. break;
  451. }
  452. *pwz1 = '\0';
  453. pwz1++;
  454. if (!*pwz1)
  455. {
  456. break;
  457. }
  458. #ifdef WITH_TAGS
  459. LPWSTR pwzResDelimiter = wcschr(pwz1, '?');
  460. if (!pwzResDelimiter)
  461. {
  462. break;
  463. }
  464. LPWSTR pwzResTag = wcsstr(pwz1, L"name:");
  465. if (!pwzResTag)
  466. {
  467. break;
  468. }
  469. LPWSTR pwzTypeTag = wcsstr(pwz1, L"type:");
  470. if (!pwzTypeTag)
  471. {
  472. break;
  473. }
  474. LPWSTR pwzMimeTag = wcsstr(pwz1, L"mime:");
  475. // get the resource name
  476. LPWSTR pwzResName = wcschr(pwzResTag, ':');
  477. pwzResName++;
  478. //find the end of the resource name
  479. LPWSTR pwzResType = wcschr(pwzTypeTag, ':');
  480. pwzResType++;
  481. LPWSTR pwzMime = 0;
  482. if (pwzMimeTag)
  483. {
  484. pwzMime = wcschr(pwzMimeTag, ':');
  485. pwzMime++;
  486. *pwzMimeTag = 0;
  487. }
  488. *pwzResTag = 0;
  489. *pwzTypeTag = 0;
  490. #else
  491. // find the delimiter for the private part
  492. LPWSTR pwzResName = wcschr(pwz1, '?');
  493. if (!pwzResName)
  494. {
  495. break;
  496. }
  497. // get the resource name
  498. pwzResName++;
  499. //find the end of the resource name
  500. LPWSTR pwzResType = wcschr(pwzResName, ' ');
  501. if (!pwzResType)
  502. {
  503. break;
  504. }
  505. *pwzResType = '\0';
  506. pwzResType++;
  507. EProtDebugOut((DEB_PLUGPROT, "CMulticastProtocol::GetResource (wzResName:%ws,pwzResType:%ws\n)",pwzResName,pwzResType));
  508. /*
  509. {
  510. pwzResType = (LPWSTR)MAKEINTRESOURCE(RT_ICON);
  511. EProtDebugOut((DEB_PLUGPROT, "CMulticastProtocol::GetResource (wzResName:%ws,pwzResType:RT_ICON\n)",pwzResName));
  512. }
  513. */
  514. #endif //WITH_TAGS
  515. EProtAssert(((WCHAR *)pwzFileName && (WCHAR *)pwzResName));
  516. if (fBind && pwzFileName && pwzResName && pwzResType)
  517. {
  518. hr = GetResource(pwzFileName, pwzResName, pwzResType, pwzMime);
  519. }
  520. break;
  521. } while (1);
  522. if (hr == MK_E_SYNTAX)
  523. {
  524. _pProtSink->ReportResult(hr, 0, 0);
  525. }
  526. EProtDebugOut((DEB_PLUGPROT, "%p OUT CMulticastProtocol::ParseAndBind (hr:%lx)\n", this,hr));
  527. return hr;
  528. }