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.

212 lines
8.6 KiB

  1. //---------------------------------------------------------------------------------------
  2. //
  3. // @doc
  4. //
  5. // @module pphandlerbase.h
  6. //
  7. // Author: stevefu
  8. //
  9. // Date: 04/28/2000
  10. //
  11. // Copyright <cp> 1999-2000 Microsoft Corporation. All Rights Reserved.
  12. //
  13. //---------------------------------------------------------------------------------------
  14. #if !defined(PPHANDLERBASE_H_INCLUDED__)
  15. #define PPHANDLERBASE_H_INCLUDED__
  16. #pragma once
  17. #if (!defined(_UNICODE) || !defined(UNICODE) )
  18. #error Passport Handler must be built with _UNICODE and UNICODE defined.
  19. #endif // built w/ UNICODE only, all CString are assumed as CStringW
  20. #include "pputils.h"
  21. #include "ppurl.h"
  22. #include "passportexception.h"
  23. #include "ppmgrver.h"
  24. class CPassportLocale;
  25. class CBrowserInfo;
  26. class CPassportCommonUIInfo;
  27. //-----------------------------------------------------------------------------
  28. //
  29. // @class CPassportHandlerBase | non-template interface class.
  30. // If your codes are being used within a Passport ISAPI Handler, you can
  31. // get access to the current active handler by calling
  32. // CPassportHandlerBase::GetPPHandler(). That saves you from passing
  33. // a global pointer everywhere in your codes.
  34. // Note there are some caveats:
  35. // 1. This works on per-thread scope. If you write an async handler,
  36. // you will have some glitch.
  37. // 2. If you have a handler include chain (in a single processing thread),
  38. // only the top level handler is returned by CPassportHandlerBase::GetPPHandler().
  39. // 3. This method does not work with multiple handler DLLs. In other word,
  40. // child ( sub or include )handlers in a different DLL can NOT get to the
  41. // top level handler.
  42. //
  43. // If you have a CPassportHandlerBase object/pointer you can also use
  44. // GetTopHandler to get access to the first handler within a request.
  45. // This does NOT limit to single thread request and works across multiple
  46. // request handler DLL.
  47. //
  48. // Parent and child handlers can also communicate with each other by calling
  49. // AddPerRequestObj, GetPerRequestObj, RemovePerRequestObj. Note you must
  50. // remove all objects before the destrutor of top handler to avoid memory leak.
  51. //
  52. //-----------------------------------------------------------------------------
  53. class CPassportHandlerBase
  54. {
  55. public:
  56. // @cmember static function to retrieve per-thread handler object
  57. inline static CPassportHandlerBase* GetPPHandler()
  58. {
  59. ATLASSERT(m_TlsIndex.x > 0 );
  60. CPassportHandlerBase* h = (CPassportHandlerBase*)TlsGetValue(m_TlsIndex.x);
  61. if ( GetLastError() != 0 ) return NULL;
  62. else return h;
  63. }
  64. // Numeric constants to control parameter translation, can be ORed.
  65. // UNICODE conversion is always performed.
  66. enum INPUT_CONVERSION_FLAG
  67. {
  68. CI_HTML_NUMERIC_DECODE = 0x1,
  69. CI_ESCAPE_SCRIPT_INJECTION = 0x2,
  70. CI_URL_UNESCAPE = 0x4,
  71. CI_FLAG_DEFAULT = CI_HTML_NUMERIC_DECODE
  72. };
  73. enum OUTPUT_CONVERSION_FLAG
  74. {
  75. CO_HTML_NUMERIC_ENCODE = 0x1,
  76. CO_ESCAPE_SCRIPT_INJECTION = 0x2,
  77. CO_URL_ESCAPE = 0x4,
  78. CO_FLAG_DEFAULT = CO_HTML_NUMERIC_ENCODE | CO_ESCAPE_SCRIPT_INJECTION
  79. };
  80. // @cmember retrieve the top level handler object
  81. virtual CPassportHandlerBase* GetTopHandler() = 0;
  82. virtual BOOL IsTopHandler() = 0;
  83. enum
  84. {
  85. OBJID_TOPHANDLER = 0, // reserve ID 0 to support GetTopHandler
  86. OBJID_BASEID_END = 100, // custom ID should be after this one
  87. OBJID_LOGIN_REQUEST = 101 // login request object.
  88. };
  89. // @cmember support per-request object sharing
  90. virtual BOOL AddPerRequestObj(unsigned id, void* pObj) = 0;
  91. virtual BOOL RemovePerRequestObj(unsigned id ) = 0;
  92. virtual void* GetPerRequestObj(unsigned id ) = 0;
  93. // @cmember retrieve global object
  94. virtual HRESULT GetGlobalObj(REFGUID objid, REFIID riid, void**pobj) = 0;
  95. // @cmember retrieve and convert parameter from query string
  96. virtual void GetWParam(LPCSTR szParamName, CStringW& wOut, unsigned flag = CI_FLAG_DEFAULT) = 0;
  97. // @cmember retrieve and convert parameter from query string and/or form variable
  98. virtual void GetWFormVar(LPCSTR szParamName, CStringW& wOut, unsigned flag = CI_FLAG_DEFAULT) = 0;
  99. // @cmember retrieve and convert cookie
  100. virtual void GetWCookie(LPCSTR szParamName, CStringW& wOut, unsigned flag = CI_FLAG_DEFAULT) = 0;
  101. // @cmember retrieve and convert cookie
  102. virtual void GetACookie(LPCSTR szParamName, CStringA& wOut, unsigned flag = CI_FLAG_DEFAULT) = 0;
  103. // @cmember retrieve and convert server variable
  104. virtual void GetWServerVariable(LPCSTR szParamName, CStringW& wOut, unsigned flag = 0) = 0;
  105. virtual void GetAServerVariable(LPCSTR szParamName, CStringA& aOut, unsigned flag = 0) = 0;
  106. // @cmember retrieve and convert a request item from query string, form, cookies
  107. // or server variables.
  108. virtual void GetWItem(LPCSTR szItem, CStringW& wOut, unsigned flag = CI_FLAG_DEFAULT) = 0;
  109. // @cmember retrieve and convert parameter from query string.
  110. // note the contents of parameter must be in ASCII only, not MBCS.
  111. virtual void GetAParam(LPCSTR szParamName, CStringA& aOut, unsigned flag = CI_FLAG_DEFAULT) = 0;
  112. // @cmember retrieve and convert item
  113. // note the contents of retrieved item must be in ASCII only, not MBCS.
  114. virtual void GetAItem( LPCSTR szItemName, CStringA& aOut, unsigned flag = CI_FLAG_DEFAULT) = 0;
  115. // @cmember retrieve a long parameter
  116. virtual long GetParamLong(LPCSTR szParamName) = 0;
  117. // @cmember retrieve a long item
  118. virtual long GetItemLong(LPCSTR szItemName) = 0;
  119. // @cemeber return browser info object
  120. virtual CBrowserInfo* GetBrowserInfo() = 0;
  121. // @cmember retrieve the full locale object
  122. virtual CPassportLocale* GetRequestLocale() = 0 ;
  123. // @cmember retrieve the ui info object
  124. virtual CPassportCommonUIInfo* GetCommonUIInfo() = 0 ;
  125. // @cmember retrieve the http request object
  126. virtual CHttpRequest* GetHttpRequest() = 0 ;
  127. // @cmember retrieve the http response object
  128. virtual CHttpResponse* GetHttpResponse() = 0;
  129. // @cmember MBCS/Unicode helper using codepage for the active request
  130. virtual void Mbcs2Unicode(LPCSTR pszIn, BOOL bNEC, CStringW& wOut) = 0;
  131. // @cmember Unicode/MBCS helper using codepage for the active request
  132. virtual void Unicode2Mbcs(LPCWSTR pwszIn, BOOL bNEC, CStringA& aOut) = 0;
  133. // @cmember add a cookie to the current response
  134. virtual void SetCookie(LPCSTR szName,
  135. LPCSTR szValue,
  136. LPCSTR szExpiration= NULL,
  137. LPCSTR szCookieDomain = NULL,
  138. LPCSTR szCookiePath = NULL,
  139. bool bSecure = false
  140. ) = 0;
  141. // @cmember add a cookie to the current response
  142. virtual void SetCookie(LPCSTR szName,
  143. LPCWSTR szValue,
  144. LPCSTR szExpiration= NULL,
  145. LPCSTR szCookieDomain = NULL,
  146. LPCSTR szCookiePath = NULL,
  147. bool bSecure = false
  148. ) = 0;
  149. // @cmember add a cookie to the current response
  150. virtual void SetCookie(CCookie& cookie) = 0;
  151. // @cmember get domain attribute from PassportManager
  152. virtual HRESULT GetDomainAttribute(
  153. const BSTR bstrAttrName, //@parm the attribute name
  154. LPCWSTR pwszDomain,
  155. CComBSTR& cbstrValue) = 0;
  156. // @cmember sets PP_SERVICE parameter for cobranding
  157. virtual void SetPPService(LPCSTR strService) = 0;
  158. // @cmember sets PP_PAGE parameter for cobranding
  159. virtual void SetPPPage(LPCSTR strPage) = 0;
  160. virtual long GetPassportID() = 0;
  161. #pragma warning( disable: 4172 )
  162. virtual const PPMGRVer & GetPPMgrVersion() { ATLASSERT(false); return PPMGRVer(); };
  163. #pragma warning( default: 4172 )
  164. virtual void AddGlobalCarryThru(CPPUrl &url) { ATLASSERT(false); }
  165. protected:
  166. // @cmember <md m_TlsIndex> is used for Tls purpose. Note this is global to
  167. // the whole DLL.
  168. static struct CTlsIndex
  169. {
  170. DWORD x;
  171. CTlsIndex() { x = TlsAlloc(); }
  172. ~CTlsIndex() { if ( x ) TlsFree(x); }
  173. } m_TlsIndex;
  174. };
  175. //-----------------------------------------------------------------------------
  176. // Static member init.
  177. // Note constructor is called before DllMain() with runtime
  178. // static/global init so that we don't have to force re-write
  179. // DllMain for every single handler DLL
  180. //-----------------------------------------------------------------------------
  181. __declspec(selectany)
  182. struct CPassportHandlerBase::CTlsIndex CPassportHandlerBase::m_TlsIndex;
  183. #endif //PPHANDLERBASE_H_INCLUDED__