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.

276 lines
6.9 KiB

  1. /*++=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. w3sobj.h
  5. Abstract:
  6. Header for the W3Spoof class & related functions, etc.
  7. Author:
  8. Paul M Midgen (pmidge) 07-June-2000
  9. Revision History:
  10. 07-June-2000 pmidge
  11. Created
  12. 17-July-2000 pmidge
  13. Added class factory & IW3Spoof interface.
  14. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--*/
  15. #ifndef _W3SOBJ_H_
  16. #define _W3SOBJ_H_
  17. #include "common.h"
  18. class IOCTX
  19. {
  20. public:
  21. IOCTX(IOTYPE iot, SOCKET s);
  22. ~IOCTX();
  23. IOTYPE Type(void);
  24. BOOL AllocateWSABuffer(DWORD size, LPVOID pv);
  25. void FreeWSABuffer(void);
  26. BOOL ResizeWSABuffer(DWORD size);
  27. void DisableIoCompletion(void);
  28. void AddRef(void);
  29. void Release(void);
  30. public:
  31. PIOCTX pthis;
  32. OVERLAPPED overlapped;
  33. SOCKET socket;
  34. LPVOID sockbuf;
  35. PHOSTINFO local;
  36. PHOSTINFO remote;
  37. LPWSTR clientid;
  38. WSABUF* pwsa;
  39. DWORD bufsize;
  40. PSESSIONOBJ session;
  41. DWORD bytes;
  42. DWORD flags;
  43. DWORD error;
  44. private:
  45. LONG _cRefs;
  46. IOTYPE _iot;
  47. };
  48. DWORD WINAPI ThreadFunc(LPVOID lpv);
  49. class CW3Spoof : public IW3Spoof,
  50. public IThreadPool,
  51. public IW3SpoofClientSupport,
  52. public IExternalConnection,
  53. public IConnectionPointContainer
  54. {
  55. public:
  56. DECLAREIUNKNOWN();
  57. // IConfig
  58. HRESULT __stdcall SetOption(DWORD dwOption, LPDWORD lpdwValue);
  59. HRESULT __stdcall GetOption(DWORD dwOption, LPDWORD lpdwValue);
  60. //
  61. // IW3Spoof
  62. //
  63. HRESULT __stdcall GetRuntime(IW3SpoofRuntime** pprt);
  64. HRESULT __stdcall GetTypeLibrary(ITypeLib** pptl);
  65. HRESULT __stdcall GetScriptEngine(IActiveScript** ppas);
  66. HRESULT __stdcall GetScriptPath(LPWSTR client, LPWSTR* path);
  67. HRESULT __stdcall Notify(LPWSTR clientid, PSESSIONOBJ pso, STATE state);
  68. HRESULT __stdcall WaitForUnload(void);
  69. HRESULT __stdcall Terminate(void);
  70. //
  71. // IThreadPool
  72. //
  73. HRESULT __stdcall GetStatus(PIOCTX* ppioc, LPBOOL pbQuit);
  74. HRESULT __stdcall GetSession(LPWSTR clientid, PSESSIONOBJ* ppso);
  75. HRESULT __stdcall Register(SOCKET s);
  76. DECLAREIDISPATCH();
  77. //
  78. // IW3SpoofClientSupport
  79. //
  80. HRESULT __stdcall RegisterClient(BSTR Client, BSTR ScriptPath);
  81. HRESULT __stdcall RevokeClient(BSTR Client);
  82. //
  83. // IExternalConnection
  84. //
  85. DWORD __stdcall AddConnection(DWORD type, DWORD reserved);
  86. DWORD __stdcall ReleaseConnection(DWORD type, DWORD reserved, BOOL bCloseIfLast);
  87. //
  88. // IConnectionPointContainer
  89. //
  90. HRESULT __stdcall EnumConnectionPoints(IEnumConnectionPoints** ppEnum);
  91. HRESULT __stdcall FindConnectionPoint(REFIID riid, IConnectionPoint** ppCP);
  92. //
  93. // Class methods
  94. //
  95. CW3Spoof();
  96. ~CW3Spoof();
  97. static HRESULT Create(IW3Spoof** ppw3s);
  98. private:
  99. DWORD _Initialize(void);
  100. void _LoadRegDefaults(void);
  101. BOOL _InitializeThreads(void);
  102. void _TerminateThreads(void);
  103. DWORD _QueueAccept(void);
  104. BOOL _CompleteAccept(PIOCTX pioc);
  105. BOOL _DisconnectSocket(PIOCTX pioc, BOOL fNBGC);
  106. void _SetState(STATE st);
  107. private:
  108. LONG m_cRefs;
  109. LONG m_cExtRefs;
  110. HANDLE m_evtServerUnload;
  111. STATE m_state;
  112. PRUNTIME m_prt;
  113. ITypeLib* m_ptl;
  114. IActiveScript* m_pas;
  115. PSTRINGMAP m_clientmap;
  116. PSTRINGMAP m_sessionmap;
  117. DWORD m_dwPoolSize;
  118. DWORD m_dwMaxActiveThreads;
  119. USHORT m_usServerPort;
  120. LPHANDLE m_arThreads;
  121. SOCKET m_sListen;
  122. HANDLE m_hIOCP;
  123. LONG m_AcceptQueueStatus;
  124. LONG m_MaxQueuedAccepts;
  125. LONG m_PendingAccepts;
  126. public:
  127. //
  128. // connection point object
  129. //
  130. class CW3SpoofEventsCP : public IConnectionPoint
  131. {
  132. public:
  133. //
  134. // IUnknown
  135. //
  136. HRESULT __stdcall QueryInterface(REFIID riid, void** ppv);
  137. ULONG __stdcall AddRef(void);
  138. ULONG __stdcall Release(void);
  139. //
  140. // IConnectionPoint
  141. //
  142. HRESULT __stdcall GetConnectionInterface(IID* pIID);
  143. HRESULT __stdcall GetConnectionPointContainer(IConnectionPointContainer** ppCPC);
  144. HRESULT __stdcall Advise(IUnknown* punkSink, LPDWORD pdwCookie);
  145. HRESULT __stdcall Unadvise(DWORD dwCookie);
  146. HRESULT __stdcall EnumConnections(IEnumConnections** ppEnum);
  147. //
  148. // object methods
  149. //
  150. CW3SpoofEventsCP()
  151. {
  152. m_cRefs = 0L;
  153. m_cConnections = 0L;
  154. m_dwCookie = 0L;
  155. m_pSite = NULL;
  156. m_pSink = NULL;
  157. }
  158. ~CW3SpoofEventsCP() {}
  159. void FireOnSessionOpen(LPWSTR clientid)
  160. {
  161. if(m_pSink)
  162. {
  163. m_pSink->OnSessionOpen(clientid);
  164. }
  165. }
  166. void FireOnSessionStateChange(LPWSTR clientid, STATE state)
  167. {
  168. if(m_pSink)
  169. {
  170. m_pSink->OnSessionStateChange(clientid, state);
  171. }
  172. }
  173. void FireOnSessionClose(LPWSTR clientid)
  174. {
  175. if(m_pSink)
  176. {
  177. m_pSink->OnSessionClose(clientid);
  178. }
  179. }
  180. void SetSite(IW3Spoof* pSite)
  181. {
  182. m_pSite = pSite;
  183. }
  184. private:
  185. LONG m_cRefs;
  186. DWORD m_cConnections;
  187. DWORD m_dwCookie;
  188. IW3Spoof* m_pSite;
  189. IW3SpoofEvents* m_pSink;
  190. };
  191. friend class CW3SpoofEventsCP;
  192. private:
  193. CW3SpoofEventsCP m_CP;
  194. };
  195. class CFactory : public IClassFactory
  196. {
  197. public:
  198. //
  199. // IUnknown
  200. //
  201. HRESULT __stdcall QueryInterface(REFIID riid, void** ppv);
  202. ULONG __stdcall AddRef(void);
  203. ULONG __stdcall Release(void);
  204. //
  205. // IClassFactory
  206. //
  207. HRESULT __stdcall CreateInstance(IUnknown* pContainer, REFIID riid, void** ppv);
  208. HRESULT __stdcall LockServer(BOOL fLock);
  209. //
  210. // Class methods
  211. //
  212. CFactory();
  213. ~CFactory();
  214. static HRESULT Create(CFactory** ppCF);
  215. HRESULT Activate(void);
  216. HRESULT Terminate(void);
  217. private:
  218. HRESULT _RegisterTypeLibrary(BOOL fMode);
  219. HRESULT _RegisterServer(BOOL fMode);
  220. HRESULT _RegisterClassFactory(BOOL fMode);
  221. IW3Spoof* m_pw3s;
  222. DWORD m_dwCookie;
  223. LONG m_cRefs;
  224. LONG m_cLocks;
  225. };
  226. #endif /* _W3SOBJ_H_ */