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.

344 lines
8.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Contains class declarations for the Internet Authentication Service
  8. // Template Library (IASTL).
  9. //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #ifndef IASTL_H
  12. #define IASTL_H
  13. //////////
  14. // IASTL must be used in conjuction with ATL.
  15. //////////
  16. #ifndef __ATLCOM_H__
  17. #error iastl.h requires atlcom.h to be included first
  18. #endif
  19. //////////
  20. // MIDL generated header files containing the interfaces that must be
  21. // implemented by a request handler.
  22. //////////
  23. #include <iascomp.h>
  24. #include <iaspolcy.h>
  25. #include <iastrace.h>
  26. //////////
  27. // Common type library describing all of the request handler interfaces. This
  28. // type library is registered during normal IAS installation; thus, individual
  29. // request handlers should not attempt to install or register this type
  30. // library.
  31. //////////
  32. struct __declspec(uuid("6BC09690-0CE6-11D1-BAAE-00C04FC2E20D")) IASTypeLibrary;
  33. //////////
  34. // The entire library is contained within the IASTL namespace.
  35. //////////
  36. namespace IASTL {
  37. ///////////////////////////////////////////////////////////////////////////////
  38. //
  39. // CLASS
  40. //
  41. // IASComponent
  42. //
  43. // DESCRIPTION
  44. //
  45. // Serves as an abstract base class for all components that need to
  46. // implement the IIasComponent interface.
  47. //
  48. ///////////////////////////////////////////////////////////////////////////////
  49. class ATL_NO_VTABLE IASComponent :
  50. public CComObjectRootEx< CComMultiThreadModel >,
  51. public IDispatchImpl< IIasComponent,
  52. &__uuidof(IIasComponent),
  53. &__uuidof(IASTypeLibrary) >,
  54. private IASTraceInitializer
  55. {
  56. public:
  57. // Interfaces supported by all IAS components.
  58. BEGIN_COM_MAP(IASComponent)
  59. COM_INTERFACE_ENTRY_IID(__uuidof(IIasComponent), IIasComponent)
  60. COM_INTERFACE_ENTRY_IID(__uuidof(IDispatch), IDispatch)
  61. END_COM_MAP()
  62. // Possible states for a component.
  63. enum State {
  64. STATE_SHUTDOWN,
  65. STATE_UNINITIALIZED,
  66. STATE_INITIALIZED,
  67. STATE_SUSPENDED,
  68. NUM_STATES,
  69. STATE_UNEXPECTED
  70. };
  71. // Events that may trigger state transitions.
  72. enum Event {
  73. EVENT_INITNEW,
  74. EVENT_INITIALIZE,
  75. EVENT_SUSPEND,
  76. EVENT_RESUME,
  77. EVENT_SHUTDOWN,
  78. NUM_EVENTS
  79. };
  80. // Constructor/destructor.
  81. IASComponent() throw ()
  82. : state(STATE_SHUTDOWN)
  83. { }
  84. // Fire an event on the component.
  85. HRESULT fireEvent(Event event) throw ();
  86. // Returns the state of the component.
  87. State getState() const throw ()
  88. { return state; }
  89. //////////
  90. // IIasComponent.
  91. // The derived class may override these as necessary. All of these
  92. // methods are serialized by an IASTL subclass, so generally no
  93. // additional locking is necessary.
  94. //////////
  95. STDMETHOD(InitNew)()
  96. { return S_OK; }
  97. STDMETHOD(Initialize)()
  98. { return S_OK; }
  99. STDMETHOD(Suspend)()
  100. { return S_OK; }
  101. STDMETHOD(Resume)()
  102. { return S_OK; }
  103. STDMETHOD(Shutdown)()
  104. { return S_OK; }
  105. STDMETHOD(GetProperty)(LONG Id, VARIANT* pValue)
  106. { return DISP_E_MEMBERNOTFOUND; }
  107. STDMETHOD(PutProperty)(LONG Id, VARIANT* pValue)
  108. { return E_NOTIMPL; }
  109. protected:
  110. // This should not be defined by the derived class since it is defined in
  111. // the IASComponentObject<T> class.
  112. virtual HRESULT attemptTransition(Event event) throw () = 0;
  113. private:
  114. // State of the component.
  115. State state;
  116. // State transition matrix governing the component lifecycle.
  117. static const State fsm[NUM_EVENTS][NUM_STATES];
  118. };
  119. ///////////////////////////////////////////////////////////////////////////////
  120. //
  121. // CLASS
  122. //
  123. // IASRequestHandler
  124. //
  125. // DESCRIPTION
  126. //
  127. // Serves as an abstract base class for all IAS request handlers.
  128. //
  129. ///////////////////////////////////////////////////////////////////////////////
  130. class ATL_NO_VTABLE IASRequestHandler :
  131. public IASComponent,
  132. public IDispatchImpl< IRequestHandler,
  133. &__uuidof(IRequestHandler),
  134. &__uuidof(IASTypeLibrary) >
  135. {
  136. public:
  137. // Interfaces supported by all IAS request handlers.
  138. BEGIN_COM_MAP(IASRequestHandler)
  139. COM_INTERFACE_ENTRY_IID(__uuidof(IRequestHandler), IRequestHandler)
  140. COM_INTERFACE_ENTRY_IID(__uuidof(IIasComponent), IIasComponent)
  141. END_COM_MAP()
  142. //////////
  143. // IRequestHandler.
  144. // This should not be defined by the derived class. Instead handlers
  145. // will define either onAsyncRequest or onSyncRequest (q.v.).
  146. //////////
  147. STDMETHOD(OnRequest)(IRequest* pRequest);
  148. protected:
  149. // Must be defined by the derived class to perform actual request
  150. // processing.
  151. virtual void onAsyncRequest(IRequest* pRequest) throw () = 0;
  152. };
  153. //////////
  154. // Obsolete.
  155. //////////
  156. #define IAS_DECLARE_OBJECT_ID(id) \
  157. void getObjectID() const throw () { }
  158. //////////
  159. // Obsolete.
  160. //////////
  161. #define BEGIN_IAS_RESPONSE_MAP()
  162. #define IAS_RESPONSE_ENTRY(val)
  163. #define END_IAS_RESPONSE_MAP()
  164. ///////////////////////////////////////////////////////////////////////////////
  165. //
  166. // CLASS
  167. //
  168. // IASRequestHandlerSync
  169. //
  170. // DESCRIPTION
  171. //
  172. // Extends IASRequestHandler to provide an abstract base class for request
  173. // handlers that process requests synchronously.
  174. //
  175. ///////////////////////////////////////////////////////////////////////////////
  176. class ATL_NO_VTABLE IASRequestHandlerSync
  177. : public IASRequestHandler
  178. {
  179. protected:
  180. // Must not be defined by the derived class.
  181. virtual void onAsyncRequest(IRequest* pRequest) throw ();
  182. // The derived class must define onSyncRequest *instead* of onAsyncRequest.
  183. // The derived class must not call IRequest::ReturnToSource since this will
  184. // be invoked automatically after onSyncRequest completes.
  185. virtual IASREQUESTSTATUS onSyncRequest(IRequest* pRequest) throw () = 0;
  186. };
  187. ///////////////////////////////////////////////////////////////////////////////
  188. //
  189. // CLASS
  190. //
  191. // IASComponentObject<T>
  192. //
  193. // DESCRIPTION
  194. //
  195. // Inherits from the user-defined component to enforce the semantics of the
  196. // component finite state machine.
  197. //
  198. ///////////////////////////////////////////////////////////////////////////////
  199. template <class T>
  200. class ATL_NO_VTABLE IASComponentObject
  201. : public T
  202. {
  203. public:
  204. DECLARE_NOT_AGGREGATABLE( IASComponentObject<T> );
  205. //////////
  206. // IIasComponent
  207. //////////
  208. STDMETHOD(InitNew)()
  209. {
  210. return fireEvent(EVENT_INITNEW);
  211. }
  212. STDMETHOD(Initialize)()
  213. {
  214. return fireEvent(EVENT_INITIALIZE);
  215. }
  216. STDMETHOD(Suspend)()
  217. {
  218. return fireEvent(EVENT_SUSPEND);
  219. }
  220. STDMETHOD(Resume)()
  221. {
  222. return fireEvent(EVENT_RESUME);
  223. }
  224. STDMETHOD(Shutdown)()
  225. {
  226. return fireEvent(EVENT_SHUTDOWN);
  227. }
  228. STDMETHOD(GetProperty)(LONG Id, VARIANT* pValue)
  229. {
  230. // We serialize this method to make it consistent with the others.
  231. Lock();
  232. HRESULT hr = T::GetProperty(Id, pValue);
  233. Unlock();
  234. return hr;
  235. }
  236. STDMETHOD(PutProperty)(LONG Id, VARIANT* pValue)
  237. {
  238. HRESULT hr;
  239. Lock();
  240. // PutProperty is not allowed when the object is shutdown.
  241. if (getState() != STATE_SHUTDOWN)
  242. {
  243. hr = T::PutProperty(Id, pValue);
  244. }
  245. else
  246. {
  247. hr = E_UNEXPECTED;
  248. }
  249. Unlock();
  250. return hr;
  251. }
  252. protected:
  253. //////////
  254. // Attempt to transition the component to a new state.
  255. //////////
  256. virtual HRESULT attemptTransition(IASComponent::Event event) throw ()
  257. {
  258. switch (event)
  259. {
  260. case EVENT_INITNEW:
  261. return T::InitNew();
  262. case EVENT_INITIALIZE:
  263. return T::Initialize();
  264. case EVENT_SUSPEND:
  265. return T::Suspend();
  266. case EVENT_RESUME:
  267. return T::Resume();
  268. case EVENT_SHUTDOWN:
  269. return T::Shutdown();
  270. }
  271. return E_FAIL;
  272. }
  273. };
  274. ///////////////////////////////////////////////////////////////////////////////
  275. //
  276. // CLASS
  277. //
  278. // IASRequestHandlerObject<T>
  279. //
  280. // DESCRIPTION
  281. //
  282. // This is the most derived class in the inheritance hierarchy. This must
  283. // be the class instantiated by ATL. Usually, this is accomplished through
  284. // the ATL Object Map.
  285. //
  286. // EXAMPLE
  287. //
  288. // class MyHandler : public IASRequestHandlerSync
  289. // { };
  290. //
  291. // BEGIN_OBJECT_MAP(ObjectMap)
  292. // OBJECT_ENTRY(__uuidof(MyHandler), IASRequestHandlerObject<MyHandler> )
  293. // END_OBJECT_MAP()
  294. //
  295. ///////////////////////////////////////////////////////////////////////////////
  296. template <class T>
  297. class ATL_NO_VTABLE IASRequestHandlerObject
  298. : public IASComponentObject < T >
  299. { };
  300. //////////
  301. // End of the IASTL namespace.
  302. //////////
  303. }
  304. #endif // IASTL_H