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.

405 lines
10 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. //+---------------------------------------------------------------------------
  19. //
  20. // Method: COhServNameSp::Start
  21. //
  22. // Synopsis:
  23. //
  24. // Arguments: [pwzUrl] --
  25. // [pTrans] --
  26. // [pOIBindInfo] --
  27. // [grfSTI] --
  28. // [dwReserved] --
  29. //
  30. // Returns:
  31. //
  32. // History: 10-29-1996 JohannP (Johann Posch) Created
  33. //
  34. // Notes:
  35. //
  36. //----------------------------------------------------------------------------
  37. STDMETHODIMP COhServNameSp::Start(LPCWSTR pwzUrl, IOInetProtocolSink *pProt, IOInetBindInfo *pOIBindInfo,
  38. DWORD grfSTI, DWORD dwReserved)
  39. {
  40. EProtDebugOut((DEB_PLUGPROT, "%p _IN COhServNameSp::Start\n", this));
  41. HRESULT hr = NOERROR;
  42. WCHAR wzURL[MAX_URL_SIZE];
  43. EProtAssert((!_pProtSink && pOIBindInfo && pProt));
  44. EProtAssert((_pwzUrl == NULL));
  45. hr = CBaseProtocol::Start(pwzUrl,pProt, pOIBindInfo, grfSTI, dwReserved);
  46. if ( (grfSTI & PI_PARSE_URL) )
  47. {
  48. hr = ParseAndStart(FALSE);
  49. }
  50. else if (hr == NOERROR)
  51. {
  52. // asked to go async as soon as possible
  53. // use the switch mechanism which will \
  54. // call back later on ::Continue
  55. if (grfSTI & PI_FORCE_ASYNC)
  56. {
  57. hr = E_PENDING;
  58. PROTOCOLDATA protdata;
  59. protdata.grfFlags = PI_FORCE_ASYNC;
  60. protdata.dwState = RES_STATE_BIND;
  61. protdata.pData = 0;
  62. protdata.cbData = 0;
  63. _pProtSink->Switch(&protdata);
  64. }
  65. else
  66. {
  67. hr = ParseAndStart(TRUE);
  68. }
  69. }
  70. EProtDebugOut((DEB_PLUGPROT, "%p OUT COhServNameSp::Start (hr:%lx)\n",this, hr));
  71. return hr;
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Method: COhServNameSp::Continue
  76. //
  77. // Synopsis:
  78. //
  79. // Arguments: [pStateInfoIn] --
  80. //
  81. // Returns:
  82. //
  83. // History: 10-29-1996 JohannP (Johann Posch) Created
  84. //
  85. // Notes:
  86. //
  87. //----------------------------------------------------------------------------
  88. STDMETHODIMP COhServNameSp::Continue(PROTOCOLDATA *pStateInfoIn)
  89. {
  90. EProtDebugOut((DEB_PLUGPROT, "%p _IN COhServNameSp::Continue\n", this));
  91. HRESULT hr = E_FAIL;
  92. EProtAssert((!pStateInfoIn->pData && pStateInfoIn->cbData && (pStateInfoIn->dwState == RES_STATE_BIND)));
  93. if (pStateInfoIn->dwState == RES_STATE_BIND)
  94. {
  95. hr = ParseAndStart();
  96. }
  97. EProtDebugOut((DEB_PLUGPROT, "%p OUT COhServNameSp::Continue (hr:%lx)\n",this, hr));
  98. return hr;
  99. }
  100. //+---------------------------------------------------------------------------
  101. //
  102. // Method: COhServNameSp::Read
  103. //
  104. // Synopsis:
  105. //
  106. // Arguments: [ULONG] --
  107. // [ULONG] --
  108. // [pcbRead] --
  109. //
  110. // Returns:
  111. //
  112. // History: 10-29-1996 JohannP (Johann Posch) Created
  113. //
  114. // Notes:
  115. //
  116. //----------------------------------------------------------------------------
  117. STDMETHODIMP COhServNameSp::Read(void *pv,ULONG cb,ULONG *pcbRead)
  118. {
  119. EProtDebugOut((DEB_PLUGPROT, "%p _IN COhServNameSp::Read (cb:%ld)\n", this,cb));
  120. HRESULT hr = NOERROR;
  121. if (_pProt)
  122. {
  123. hr = _pProt->Read(pv, cb, pcbRead);
  124. }
  125. else
  126. {
  127. hr = S_FALSE;
  128. }
  129. EProtDebugOut((DEB_PLUGPROT, "%p OUT COhServNameSp::Read (pcbRead:%ld, hr:%lx)\n",this,*pcbRead, hr));
  130. return hr;
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Method: COhServNameSp::Seek
  135. //
  136. // Synopsis:
  137. //
  138. // Arguments: [DWORD] --
  139. // [ULARGE_INTEGER] --
  140. // [plibNewPosition] --
  141. //
  142. // Returns:
  143. //
  144. // History: 10-29-1996 JohannP (Johann Posch) Created
  145. //
  146. // Notes: WORK: not done
  147. //
  148. //----------------------------------------------------------------------------
  149. STDMETHODIMP COhServNameSp::Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,ULARGE_INTEGER *plibNewPosition)
  150. {
  151. EProtDebugOut((DEB_PLUGPROT, "%p _IN COhServNameSp::Seek\n", this));
  152. HRESULT hr = NOERROR;
  153. if (_pProt)
  154. {
  155. hr = _pProt->Seek(dlibMove, dwOrigin, plibNewPosition);
  156. }
  157. else
  158. {
  159. hr = S_FALSE;
  160. }
  161. EProtDebugOut((DEB_PLUGPROT, "%p OUT COhServNameSp::Seek (hr:%lx)\n",this, hr));
  162. return hr;
  163. }
  164. //+---------------------------------------------------------------------------
  165. //
  166. // Method: COhServNameSp::LockRequest
  167. //
  168. // Synopsis:
  169. //
  170. // Arguments: [dwOptions] --
  171. //
  172. // Returns:
  173. //
  174. // History: 10-29-1996 JohannP (Johann Posch) Created
  175. //
  176. // Notes:
  177. //
  178. //----------------------------------------------------------------------------
  179. STDMETHODIMP COhServNameSp::LockRequest(DWORD dwOptions)
  180. {
  181. EProtDebugOut((DEB_PLUGPROT, "%p _IN COhServNameSp::LockRequest\n", this));
  182. HRESULT hr = NOERROR;
  183. if (_pProt)
  184. {
  185. hr = _pProt->LockRequest(dwOptions);
  186. }
  187. EProtDebugOut((DEB_PLUGPROT, "%p OUT COhServNameSp::LockRequest (hr:%lx)\n",this, hr));
  188. return hr;
  189. }
  190. //+---------------------------------------------------------------------------
  191. //
  192. // Method: COhServNameSp::UnlockRequest
  193. //
  194. // Synopsis:
  195. //
  196. // Arguments: (none)
  197. //
  198. // Returns:
  199. //
  200. // History: 10-29-1996 JohannP (Johann Posch) Created
  201. //
  202. // Notes:
  203. //
  204. //----------------------------------------------------------------------------
  205. STDMETHODIMP COhServNameSp::UnlockRequest()
  206. {
  207. EProtDebugOut((DEB_PLUGPROT, "%p _IN COhServNameSp::UnlockRequest\n", this));
  208. HRESULT hr = NOERROR;
  209. if (_pProt)
  210. {
  211. hr = _pProt->UnlockRequest();
  212. }
  213. EProtDebugOut((DEB_PLUGPROT, "%p OUT COhServNameSp::UnlockRequest (hr:%lx)\n",this, hr));
  214. return hr;
  215. }
  216. //+---------------------------------------------------------------------------
  217. //
  218. // Method: COhServNameSp::COhServNameSp
  219. //
  220. // Synopsis:
  221. //
  222. // Arguments: (none)
  223. //
  224. // Returns:
  225. //
  226. // History: 1-27-96 JohannP (Johann Posch) Created
  227. //
  228. // Notes:
  229. //
  230. //----------------------------------------------------------------------------
  231. COhServNameSp::COhServNameSp(REFCLSID rclsid, IUnknown *pUnkOuter, IUnknown **ppUnkInner) : CBaseProtocol(rclsid, pUnkOuter, ppUnkInner)
  232. {
  233. EProtDebugOut((DEB_PLUGPROT, "%p _IN/OUT COhServNameSp::COhServNameSp \n", this));
  234. }
  235. //+---------------------------------------------------------------------------
  236. //
  237. // Method: COhServNameSp::~COhServNameSp
  238. //
  239. // Synopsis:
  240. //
  241. // Arguments: (none)
  242. //
  243. // Returns:
  244. //
  245. // History: 11-09-1996 JohannP (Johann Posch) Created
  246. //
  247. // Notes:
  248. //
  249. //----------------------------------------------------------------------------
  250. COhServNameSp::~COhServNameSp()
  251. {
  252. EProtDebugOut((DEB_PLUGPROT, "%p _IN/OUT COhServNameSp::~COhServNameSp \n", this));
  253. }
  254. //+---------------------------------------------------------------------------
  255. //
  256. // Method: COhServNameSp::ParseAndStart
  257. //
  258. // Synopsis:
  259. //
  260. // Arguments: (none)
  261. //
  262. // Returns:
  263. //
  264. // History: 11-09-1996 JohannP (Johann Posch) Created
  265. //
  266. // Notes:
  267. //
  268. //----------------------------------------------------------------------------
  269. STDMETHODIMP COhServNameSp::ParseAndStart(BOOL fBind)
  270. {
  271. EProtDebugOut((DEB_PLUGPROT, "%p _IN COhServNameSp::ParseAndStart\n", this));
  272. HRESULT hr = INET_E_USE_DEFAULT_PROTOCOLHANDLER;
  273. WCHAR wzUrl[MAX_URL_SIZE];
  274. LPWSTR pwzOhservHttp = L"http://ohserv";
  275. LPWSTR pwzOhservFile = L"file://\\\\ohserv\\http";
  276. LPWSTR pwzOhservRoot = L"\\\\ohserv\\http";
  277. ULONG cServerLen = wcslen(pwzOhservHttp);
  278. do
  279. {
  280. if ( wcsnicmp(_wzFullURL, pwzOhservHttp, cServerLen) )
  281. {
  282. // not http://ohserv - return default error
  283. break;
  284. }
  285. // find the file name and path
  286. LPWSTR pwzRest = _wzFullURL + cServerLen;
  287. EProtAssert((pwzRest));
  288. wcscpy(wzUrl, pwzOhservRoot);
  289. wcscat(wzUrl, pwzRest);
  290. DWORD dwAttr = 0;
  291. {
  292. char szUrl[MAX_URL_SIZE];
  293. W2A(wzUrl, szUrl, MAX_URL_SIZE);
  294. dwAttr = GetFileAttributes(szUrl);
  295. }
  296. if ( (dwAttr == 0xffffffff)
  297. || (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
  298. )
  299. {
  300. break;
  301. }
  302. wcscpy(wzUrl, pwzOhservFile);
  303. wcscat(wzUrl, pwzRest);
  304. // create an APP file
  305. {
  306. IClassFactory *pCF = 0;
  307. hr = CoCreateInstance(CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER,IID_IClassFactory, (void**)&pCF);
  308. if (hr == NOERROR)
  309. {
  310. IUnknown *pUnk = 0;
  311. //IOInetProtocol *pProt = 0;
  312. EProtAssert((pCF));
  313. hr = pCF->CreateInstance((IOInetProtocol *)this, IID_IUnknown, (void **)&_pUnkInner);
  314. if (hr == NOERROR)
  315. {
  316. EProtAssert((_pUnkInner));
  317. hr = (_pUnkInner)->QueryInterface(IID_IOInetProtocol, (void **) &_pProt);
  318. }
  319. // create an instance without aggregation
  320. if (hr == CLASS_E_NOAGGREGATION)
  321. {
  322. hr = pCF->CreateInstance(NULL, IID_IOInetProtocol, (void **) &_pProt);
  323. }
  324. pCF->Release();
  325. {
  326. hr = _pProt->Start(wzUrl, _pProtSink, _pOIBindInfo, _grfSTI, 0);
  327. }
  328. if (hr != NOERROR)
  329. {
  330. hr = INET_E_USE_DEFAULT_PROTOCOLHANDLER;
  331. }
  332. }
  333. }
  334. break;
  335. } while (1);
  336. if (hr == MK_E_SYNTAX)
  337. {
  338. _pProtSink->ReportResult(hr, 0, 0);
  339. }
  340. EProtDebugOut((DEB_PLUGPROT, "%p OUT COhServNameSp::ParseAndStart (hr:%lx)\n", this,hr));
  341. return hr;
  342. }