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.

370 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. isvcinfo.hxx
  5. Abstract:
  6. This header file declares the INTERNET SERVICES INFO object.
  7. This class serves as a base class for all the functions exported
  8. as part of commnon services DLL for Internet services.
  9. Author:
  10. Murali R. Krishnan ( MuraliK ) 28-July-1995
  11. Environment:
  12. Win32 User Mode
  13. Project:
  14. Internet Services Common DLL
  15. Revision History:
  16. Murali R. Krishnan (MuraliK) 21-Dec-1995 Support for ISRPC component
  17. --*/
  18. # ifndef _ISVC_INFO_HXX_
  19. # define _ISVC_INFO_HXX_
  20. /************************************************************
  21. * Include Headers
  22. ************************************************************/
  23. # include "string.hxx"
  24. # include "tsres.hxx"
  25. # include "eventlog.hxx"
  26. extern "C" {
  27. # include "inetcom.h"
  28. # include "inetinfo.h"
  29. # include "tcpsvcs.h"
  30. # include "rpc.h"
  31. # include "svcloc.h"
  32. };
  33. # include "isrpc.hxx"
  34. # include "inetlog.h"
  35. #ifdef CHICAGO
  36. #undef ASSERT
  37. #define ASSERT TCP_ASSERT
  38. #endif
  39. //
  40. // Following constants are used for maintaining state of the log object
  41. //
  42. enum ILOG_STATES {
  43. ILOG_OFF = 0, // logging is shut down.
  44. ILOG_ACTIVE, // logging is active and working fine
  45. ILOG_SUSPENDED // logging is temporarily suspended.
  46. };
  47. /************************************************************
  48. * Type Definitions
  49. ************************************************************/
  50. class ISVC_INFO;
  51. // these functions get called back with the pointer to isvcinfo object
  52. // along with supplied context parameter.
  53. typedef BOOL (*TS_PFN_SVC_ENUM)( IN ISVC_INFO * pIsvcInfo,
  54. IN PVOID pContext );
  55. class ISVC_INFO {
  56. public:
  57. dllexp
  58. ISVC_INFO(
  59. IN DWORD dwServiceId,
  60. IN LPCTSTR lpszServiceName,
  61. IN LPCTSTR lpszModuleName,
  62. IN LPCTSTR lpszRegParamKey
  63. );
  64. dllexp
  65. virtual ~ISVC_INFO(VOID);
  66. //
  67. // VIRTUAL methods
  68. //
  69. dllexp virtual BOOL IsValid(VOID) const { return (m_fValid); }
  70. dllexp
  71. virtual BOOL
  72. ReadParamsFromRegistry( IN FIELD_CONTROL fc);
  73. dllexp
  74. virtual BOOL SetConfiguration( IN PVOID pConfig);
  75. dllexp
  76. virtual BOOL GetConfiguration( IN OUT PVOID pConfig);
  77. dllexp
  78. virtual DWORD
  79. QueryCurrentServiceState( VOID) const
  80. // derived object should maintain state
  81. { return ( SERVICE_STOPPED); }
  82. //
  83. // Parameter access methods. Note that string or non-trivial admin data
  84. // items must have the read lock taken.
  85. //
  86. dllexp LIST_ENTRY & QueryListEntry( VOID)
  87. { return ( m_listEntry); }
  88. dllexp DWORD QueryServiceId( VOID ) const
  89. { return ( m_dwServiceId ); }
  90. dllexp LPCTSTR QueryServiceName(VOID) const
  91. { return (m_strServiceName.QueryStr()); }
  92. dllexp LPCTSTR QueryRegParamKey(VOID) const
  93. { return m_strParametersKey.QueryStr(); }
  94. dllexp LPCTSTR QueryAdminName(VOID) const
  95. { ASSERT( m_cReadLocks ); return m_strAdminName.QueryStr(); }
  96. dllexp LPCTSTR QueryAdminEmail(VOID) const
  97. { ASSERT( m_cReadLocks ); return m_strAdminEmail.QueryStr(); }
  98. dllexp LPCTSTR QueryServerComment(VOID) const
  99. { ASSERT( m_cReadLocks ); return m_strServerComment.QueryStr(); }
  100. dllexp DWORD QueryMaxConnections( VOID ) const
  101. { return m_dwMaxConnections; }
  102. dllexp DWORD QueryConnectionTimeout( VOID ) const
  103. { return m_dwConnectionTimeout; }
  104. dllexp LPCTSTR QueryModuleName( VOID) const
  105. { return ( m_strModuleName.QueryStr()); }
  106. dllexp EVENT_LOG * QueryEventLog(VOID) { return (&m_EventLog); }
  107. dllexp HMODULE QueryHandleForModule(VOID) const { return (m_hModule); }
  108. //
  109. // IPC related functions
  110. //
  111. dllexp VOID SetTcpsvcsGlobalData( IN PTCPSVCS_GLOBAL_DATA ptgData)
  112. { m_pTcpsvcsGlobalData = ptgData; }
  113. dllexp PTCPSVCS_GLOBAL_DATA QueryTcpsvcsGlobalData( VOID) const
  114. { return ( m_pTcpsvcsGlobalData); }
  115. dllexp DWORD InitializeIpc( IN UCHAR * pszProtseq,
  116. IN UCHAR * pszEndpoint,
  117. IN RPC_IF_HANDLE rpcIfHandle)
  118. { // standby function, till everyone changes the code over....
  119. return ( InitializeIpc( rpcIfHandle));
  120. }
  121. dllexp DWORD InitializeIpc( IN RPC_IF_HANDLE rpcIfHandle);
  122. dllexp DWORD CleanupIpc( IN RPC_IF_HANDLE rpcIfHandle);
  123. dllexp DWORD InitializeDiscovery( IN LPINET_BINDINGS pExtraInetBindings);
  124. dllexp DWORD TerminateDiscovery( VOID);
  125. //
  126. // Data access protection methods
  127. //
  128. dllexp VOID
  129. LockThisForRead( VOID )
  130. {
  131. m_tslock.Lock( TSRES_LOCK_READ );
  132. ASSERT( InterlockedIncrement( &m_cReadLocks ) > 0);
  133. }
  134. dllexp VOID
  135. LockThisForWrite( VOID )
  136. {
  137. m_tslock.Lock( TSRES_LOCK_WRITE );
  138. ASSERT( m_cReadLocks == 0);
  139. }
  140. dllexp VOID
  141. UnlockThis( VOID )
  142. {
  143. #if DBG
  144. if ( m_cReadLocks ) // If non-zero, then this is a read unlock
  145. InterlockedDecrement( &m_cReadLocks );
  146. #endif
  147. m_tslock.Unlock();
  148. }
  149. //
  150. // Miscellaneous methods
  151. //
  152. dllexp BOOL
  153. LoadStr( OUT STR & str, IN DWORD dwResId) const;
  154. //
  155. // Event log related API
  156. //
  157. dllexp VOID
  158. LogEvent(
  159. IN DWORD idMessage, // id for log message
  160. IN WORD cSubStrings, // count of substrings
  161. IN const CHAR * apszSubStrings[], // substrings in the message
  162. IN DWORD errCode = 0 // error code if any
  163. )
  164. {
  165. m_EventLog.LogEvent( idMessage, cSubStrings,
  166. apszSubStrings, errCode);
  167. }
  168. dllexp VOID
  169. LogEvent(
  170. IN DWORD idMessage, // id for log message
  171. IN WORD cSubStrings, // count of substrings
  172. IN WCHAR * apszSubStrings[], // substrings in the message
  173. IN DWORD errCode = 0 // error code if any
  174. )
  175. {
  176. m_EventLog.LogEvent( idMessage, cSubStrings,
  177. apszSubStrings, errCode);
  178. }
  179. //
  180. // Logging related APIs. They call logging apis only if logging is on.
  181. //
  182. INETLOG_HANDLE QueryInetLog(VOID) const { return (m_hInetLog); }
  183. dllexp
  184. DWORD
  185. LogInformation( IN const INETLOG_INFORMATIONA * pInetLogInfo,
  186. OUT LPSTR pszErrorMessage,
  187. IN OUT LPDWORD lpcchErrorMessage);
  188. dllexp
  189. DWORD
  190. LogInformation( IN const INETLOG_INFORMATIONW * pInetLogInfo,
  191. OUT LPWSTR pszErrorMessage,
  192. IN OUT LPDWORD lpcchErrorMessage);
  193. dllexp BOOL
  194. TerminateLogging( VOID);
  195. # if DBG
  196. virtual VOID Print( VOID) const;
  197. # endif // DBG
  198. protected:
  199. LONG m_cReadLocks; // tracks number of outstanding reads
  200. private:
  201. BOOL m_fValid; // indicates if this object is valid
  202. DWORD m_fIpcStarted : 1;
  203. DWORD m_fSvcLocationDone : 1;
  204. BOOL m_fEnableSvcLocation;
  205. ISRPC m_isrpc;
  206. TS_RESOURCE m_tslock; // protects the service specific data
  207. PTCPSVCS_GLOBAL_DATA m_pTcpsvcsGlobalData;
  208. DWORD m_dwMaxConnections;
  209. DWORD m_dwConnectionTimeout;
  210. DWORD m_dwServiceId; // Id for the service
  211. STR m_strServiceName;// string with service name
  212. STR m_strModuleName; // (eg: foo.dll) for loading resources
  213. HMODULE m_hModule; // cached module handle
  214. //
  215. // location in registry where the parameters key containing common
  216. // service specific data may be found.
  217. //
  218. STR m_strParametersKey;
  219. STR m_strAdminName;
  220. STR m_strAdminEmail;
  221. STR m_strServerComment;
  222. EVENT_LOG m_EventLog; // eventlog object for logging events
  223. INETLOG_HANDLE m_hInetLog; // Request Log object
  224. BOOL m_fLoggingOn; // keeps track of status if logging is on
  225. // for use with InterlockedExchange, use following as LONG
  226. LONG m_lLoggingState;
  227. LIST_ENTRY m_listEntry; // to link all ISVC_INFO objects
  228. dllexp RPC_STATUS StartRpcServerListen( VOID) const
  229. { return m_pTcpsvcsGlobalData->StartRpcServerListen(); }
  230. dllexp RPC_STATUS StopRpcServerListen( VOID) const
  231. { return m_pTcpsvcsGlobalData->StopRpcServerListen(); }
  232. //
  233. // class STATIC data and member functions definitions
  234. //
  235. // Primarily keeps track of list of active services.
  236. //
  237. public:
  238. static BOOL InitializeServiceInfo(VOID);
  239. static VOID CleanupServiceInfo(VOID);
  240. //
  241. // EnumerateServiceInfo() is used for enumerating active services.
  242. // It calls the function pfnEnum for each running service that matches
  243. // services mask in dwServices.
  244. //
  245. static BOOL
  246. EnumerateServiceInfo( IN TS_PFN_SVC_ENUM pfnEnum,
  247. IN PVOID pContext,
  248. IN DWORD dwServices
  249. );
  250. private:
  251. static LIST_ENTRY sm_ServiceInfoListHead;
  252. static DWORD sm_nServices;
  253. static BOOL sm_fInitialized;
  254. static CRITICAL_SECTION sm_csLock; // lock for list mods.
  255. static BOOL InsertInServiceInfoList(IN ISVC_INFO * pIsvcInfo);
  256. static BOOL RemoveFromServiceInfoList(IN ISVC_INFO * pIsvcInfo);
  257. }; // class ISVC_INFO
  258. typedef ISVC_INFO FAR * PISVC_INFO;
  259. typedef ISVC_INFO FAR * LPISVC_INFO;
  260. # endif // _ISVC_INFO_HXX_
  261. /************************ End of File ***********************/