Source code of Windows XP (NT5)
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.

177 lines
4.4 KiB

  1. /**
  2. * Asynchronous pluggable protocol for Applications
  3. *
  4. * Copyright (C) Microsoft Corporation, 2000
  5. */
  6. /////////////////////////////////////////////////////////////////////////////
  7. /////////////////////////////////////////////////////////////////////////////
  8. /////////////////////////////////////////////////////////////////////////////
  9. #include "precomp.h"
  10. #include "app.h"
  11. //LONG g_cAppPObject = 0;
  12. ULONG IncrementDllObjectCount();
  13. ULONG DecrementDllObjectCount();
  14. /////////////////////////////////////////////////////////////////////////////
  15. /////////////////////////////////////////////////////////////////////////////
  16. /////////////////////////////////////////////////////////////////////////////
  17. HRESULT
  18. AppProtocolFactory::QueryInterface(REFIID iid, void **ppv)
  19. {
  20. *ppv = NULL;
  21. if (iid == IID_IUnknown ||
  22. iid == IID_IInternetProtocolInfo)
  23. {
  24. *ppv = (IInternetProtocolInfo *)this;
  25. }
  26. else
  27. if (iid == IID_IClassFactory)
  28. {
  29. *ppv = (IClassFactory *)this;
  30. }
  31. else
  32. {
  33. return E_NOINTERFACE;
  34. }
  35. ((IUnknown *)*ppv)->AddRef();
  36. return S_OK;
  37. }
  38. /////////////////////////////////////////////////////////////////////////////
  39. ULONG
  40. AppProtocolFactory::AddRef()
  41. {
  42. //return InterlockedIncrement(&g_cAppPObject);
  43. return IncrementDllObjectCount();
  44. }
  45. ULONG
  46. AppProtocolFactory::Release()
  47. {
  48. //return InterlockedDecrement(&g_cAppPObject);
  49. return DecrementDllObjectCount();
  50. }
  51. HRESULT
  52. AppProtocolFactory::LockServer(BOOL lock)
  53. {
  54. //return (lock ?
  55. // InterlockedIncrement(&g_cAppPObject) :
  56. // InterlockedDecrement(&g_cAppPObject));
  57. return (lock ? IncrementDllObjectCount() : DecrementDllObjectCount());
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. /////////////////////////////////////////////////////////////////////////////
  61. /////////////////////////////////////////////////////////////////////////////
  62. HRESULT
  63. AppProtocolFactory::CreateInstance(
  64. IUnknown * pUnkOuter,
  65. REFIID iid,
  66. void ** ppv)
  67. {
  68. HRESULT hr = S_OK;
  69. AppProtocol *pProtocol = NULL;
  70. if (pUnkOuter && iid != IID_IUnknown)
  71. {
  72. hr = E_INVALIDARG;
  73. goto exit;
  74. }
  75. if ((pProtocol = new AppProtocol(pUnkOuter)) == NULL)
  76. {
  77. hr = E_OUTOFMEMORY;
  78. goto exit;
  79. }
  80. if (iid == IID_IUnknown)
  81. {
  82. *ppv = (IPrivateUnknown *)pProtocol;
  83. pProtocol->PrivateAddRef();
  84. }
  85. else
  86. {
  87. hr = pProtocol->QueryInterface(iid, ppv);
  88. if (FAILED(hr))
  89. goto exit;
  90. }
  91. exit:
  92. if (pProtocol)
  93. pProtocol->PrivateRelease();
  94. return hr;
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. /////////////////////////////////////////////////////////////////////////////
  98. /////////////////////////////////////////////////////////////////////////////
  99. HRESULT
  100. AppProtocolFactory::CombineUrl(
  101. LPCWSTR,
  102. LPCWSTR,
  103. DWORD,
  104. LPWSTR,
  105. DWORD,
  106. DWORD *,
  107. DWORD)
  108. {
  109. return INET_E_DEFAULT_ACTION;
  110. }
  111. HRESULT
  112. AppProtocolFactory::CompareUrl(LPCWSTR, LPCWSTR, DWORD)
  113. {
  114. return INET_E_DEFAULT_ACTION;
  115. }
  116. HRESULT
  117. AppProtocolFactory::ParseUrl(
  118. LPCWSTR pwzUrl,
  119. PARSEACTION ParseAction,
  120. DWORD ,
  121. LPWSTR pwzResult,
  122. DWORD cchResult,
  123. DWORD * pcchResult,
  124. DWORD )
  125. {
  126. // Only thing we handle is security zones...
  127. if (ParseAction != PARSE_SECURITY_URL && ParseAction != PARSE_SECURITY_DOMAIN)
  128. return INET_E_DEFAULT_ACTION;
  129. // Check to make sure args are okay
  130. if ( pwzUrl == NULL || pwzResult == NULL || cchResult < wcslen(HTTP_SCHEME)+1/*4*/ || wcslen(pwzUrl) < PROTOCOL_NAME_LEN)
  131. return INET_E_DEFAULT_ACTION;
  132. // Check if the protocol starts with app
  133. for(int iter=0; iter<PROTOCOL_NAME_LEN; iter++)
  134. if (towlower(pwzUrl[iter]) != PROTOCOL_NAME[iter])
  135. return INET_E_DEFAULT_ACTION; // Doesn't start with app
  136. // Copy in the corresponding http protocol
  137. wcscpy(pwzResult, HTTP_SCHEME);
  138. wcsncpy(&pwzResult[4], &pwzUrl[PROTOCOL_NAME_LEN], cchResult - 5);
  139. pwzResult[cchResult-1] = NULL;
  140. (*pcchResult) = wcslen(pwzResult);
  141. return S_OK;
  142. }
  143. HRESULT
  144. AppProtocolFactory::QueryInfo(LPCWSTR, QUERYOPTION, DWORD,
  145. LPVOID, DWORD, DWORD *, DWORD)
  146. {
  147. return E_NOTIMPL;
  148. }