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.

532 lines
12 KiB

  1. /******************************************************************
  2. PingTask.H -- Task object definitions
  3. Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  4. Description:
  5. *******************************************************************/
  6. #ifndef _CPingTask_H_
  7. #define _CPingTask_H_
  8. #define SYSTEM_PROPERTY_CLASS L"__CLASS"
  9. #define SYSTEM_PROPERTY_SUPERCLASS L"__SUPERCLASS"
  10. #define SYSTEM_PROPERTY_DYNASTY L"__DYNASTY"
  11. #define SYSTEM_PROPERTY_DERIVATION L"__DERIVATION"
  12. #define SYSTEM_PROPERTY_GENUS L"__GENUS"
  13. #define SYSTEM_PROPERTY_NAMESPACE L"__NAMESPACE"
  14. #define SYSTEM_PROPERTY_PROPERTY_COUNT L"__PROPERTY_COUNT"
  15. #define SYSTEM_PROPERTY_SERVER L"__SERVER"
  16. #define SYSTEM_PROPERTY_RELPATH L"__RELPATH"
  17. #define SYSTEM_PROPERTY_PATH L"__PATH"
  18. #define PING_MAX_IPS ( MAX_OPT_SIZE / 4 /*sizeof(ULONG)*/ )
  19. extern const WCHAR *Ping_Address;
  20. extern const WCHAR *Ping_Timeout;
  21. extern const WCHAR *Ping_TimeToLive;
  22. extern const WCHAR *Ping_BufferSize;
  23. extern const WCHAR *Ping_NoFragmentation;
  24. extern const WCHAR *Ping_TypeofService;
  25. extern const WCHAR *Ping_RecordRoute;
  26. extern const WCHAR *Ping_TimestampRoute;
  27. extern const WCHAR *Ping_SourceRouteType;
  28. extern const WCHAR *Ping_SourceRoute;
  29. extern const WCHAR *Ping_ResolveAddressNames;
  30. #define PING_ADDRESS_INDEX 0
  31. #define PING_TIMEOUT_INDEX 1
  32. #define PING_TIMETOLIVE_INDEX 2
  33. #define PING_BUFFERSIZE_INDEX 3
  34. #define PING_NOFRAGMENTATION_INDEX 4
  35. #define PING_TYPEOFSERVICE_INDEX 5
  36. #define PING_RECORDROUTE_INDEX 6
  37. #define PING_TIMESTAMPROUTE_INDEX 7
  38. #define PING_SOURCEROUTETYPE_INDEX 8
  39. #define PING_SOURCEROUTE_INDEX 9
  40. #define PING_RESOLVEADDRESSNAMES_INDEX 10
  41. class CPingTaskObject;
  42. class CPingCallBackObject : public WmiTask < ULONG >
  43. {
  44. private:
  45. CPingTaskObject *m_ParentTask;
  46. UCHAR *m_ReplyBuffer;
  47. UCHAR *m_SendBuffer;
  48. ULONG m_Address;
  49. ULONG m_TimeToLive;
  50. ULONG m_Timeout;
  51. ULONG m_SendSize;
  52. ULONG m_ReplySize;
  53. BOOL m_NoFragmentation;
  54. ULONG m_TypeofService;
  55. ULONG m_RecordRoute;
  56. ULONG m_TimestampRoute;
  57. ULONG m_SourceRouteType;
  58. CStringW m_AddressString;
  59. CStringW m_SourceRoute;
  60. ULONG m_SourceRouteArray[PING_MAX_IPS];
  61. ULONG m_SourceRouteCount;
  62. BOOL m_ResolveAddress;
  63. HANDLE m_IcmpHandle;
  64. ULONG m_ResolveError;
  65. BOOL ParseSourceRoute();
  66. void SendError(DWORD a_ErrMsgID, HRESULT a_HRes);
  67. BOOL GetIcmpHandle();
  68. public:
  69. //Simple access methods
  70. UCHAR* GetReplyBuffer() { return m_ReplyBuffer ; }
  71. UCHAR* GetSendBuffer() { return m_SendBuffer ; }
  72. ULONG GetAddress() { return m_Address ; }
  73. LPCWSTR GetAddressString() { return m_AddressString ; }
  74. ULONG GetTimeToLive() { return m_TimeToLive ; }
  75. ULONG GetTimeout() { return m_Timeout ; }
  76. ULONG GetSendSize() { return m_SendSize ; }
  77. ULONG GetReplySize() { return m_ReplySize ; }
  78. BOOL GetNoFragmentation() { return m_NoFragmentation ; }
  79. ULONG GetTypeofService() { return m_TimeToLive ; }
  80. ULONG GetRecordRoute() { return m_RecordRoute ; }
  81. ULONG GetTimestampRoute() { return m_TimestampRoute ; }
  82. ULONG GetSourceRouteType() { return m_SourceRouteType ; }
  83. LPCWSTR GetSourceRoute() { return m_SourceRoute ; }
  84. ULONG* GetSourceRouteArray() { return m_SourceRouteArray ; }
  85. ULONG GetSourceRouteCount() { return m_SourceRouteCount ; }
  86. BOOL GetResolveAddress() { return m_ResolveAddress ; }
  87. ULONG GetResolveError() { return m_ResolveError ; }
  88. //Async call routines
  89. void HandleResponse();
  90. void SendEcho();
  91. CPingCallBackObject(
  92. CPingTaskObject *a_ParentTask,
  93. LPCWSTR a_AddressString,
  94. ULONG a_Address,
  95. ULONG a_TimeToLive,
  96. ULONG a_Timeout,
  97. ULONG a_SendSize,
  98. BOOL a_NoFragmentation,
  99. ULONG a_TypeofService,
  100. ULONG a_RecordRoute,
  101. ULONG a_TimestampRoute,
  102. ULONG a_SourceRouteType,
  103. LPCWSTR a_SourceRoute,
  104. BOOL a_ResolveAddress,
  105. ULONG a_ResolveError
  106. );
  107. WmiStatusCode Process ( WmiThread <ULONG> &a_Thread ) ;
  108. void Disconnect() { m_ParentTask = NULL ; }
  109. ~CPingCallBackObject();
  110. };
  111. class CPingTaskObject
  112. {
  113. private:
  114. protected:
  115. class CPingErrorObject
  116. {
  117. private:
  118. LPWSTR m_Description;
  119. HRESULT m_Status;
  120. public:
  121. CPingErrorObject(): m_Description(NULL), m_Status (S_OK) {}
  122. void SetInfo(LPCWSTR a_description, HRESULT a_status);
  123. HRESULT GetStatus() const { return m_Status; }
  124. LPCWSTR GetDescription() const { return m_Description; }
  125. ~CPingErrorObject();
  126. };
  127. CPingErrorObject m_ErrorObject ;
  128. IWbemObjectSink *m_NotificationHandler ;
  129. IWbemContext *m_Ctx ;
  130. CPingProvider *m_Provider ;
  131. HANDLE m_ThreadToken ;
  132. CRITICAL_SECTION m_CS;
  133. LONG m_PingCount;
  134. void SetErrorInfo(DWORD a_ErrMsgID, HRESULT a_HRes, BOOL a_Force = FALSE);
  135. HRESULT Icmp_DecodeAndIndicate (CPingCallBackObject *a_Reply);
  136. HRESULT Icmp_IndicateResolveError (CPingCallBackObject *a_Reply);
  137. void IPAddressToString(_variant_t &a_var, ULONG a_Val, BOOL a_Resolve);
  138. void DecrementPingCount();
  139. HRESULT SetInstanceKeys(IWbemClassObject *a_Inst , CPingCallBackObject *a_Reply);
  140. HRESULT SetStringProperty(
  141. IWbemClassObject *a_Inst,
  142. LPCWSTR a_name,
  143. LPCWSTR a_val
  144. ) ;
  145. HRESULT SetBOOLProperty(
  146. IWbemClassObject *a_Inst,
  147. LPCWSTR a_name,
  148. BOOL a_val
  149. ) ;
  150. HRESULT SetUint32Property(
  151. IWbemClassObject *a_Inst,
  152. LPCWSTR a_name,
  153. ULONG a_val
  154. ) ;
  155. HRESULT SetUint32ArrayProperty(
  156. IWbemClassObject *a_Inst ,
  157. LPCWSTR a_Name ,
  158. ULONG* a_Vals ,
  159. ULONG a_Count
  160. ) ;
  161. HRESULT SetIPProperty(
  162. IWbemClassObject *a_Inst ,
  163. LPCWSTR a_Name ,
  164. ULONG a_Val ,
  165. BOOL a_Resolve
  166. ) ;
  167. HRESULT SetIPArrayProperty(
  168. IWbemClassObject *a_Inst ,
  169. LPCWSTR a_Name ,
  170. ULONG* a_Vals ,
  171. ULONG a_Count ,
  172. BOOL a_Resolve
  173. ) ;
  174. HRESULT Icmp_DecodeResponse (
  175. PICMP_ECHO_REPLY a_Reply ,
  176. ULONG &a_RouteSourceCount ,
  177. ULONG *&a_RouteSource ,
  178. ULONG &a_TimestampCount ,
  179. ULONG *&a_TimestampRoute ,
  180. ULONG *&a_Timestamp
  181. ) ;
  182. HRESULT Icmp_RequestResponse (
  183. LPCWSTR a_AddressString ,
  184. ULONG a_Address ,
  185. ULONG a_TimeToLive ,
  186. ULONG a_Timeout ,
  187. ULONG a_SendSize ,
  188. BOOL a_NoFragmentation ,
  189. ULONG a_TypeofService ,
  190. ULONG a_RecordRoute ,
  191. ULONG a_TimestampRoute ,
  192. ULONG a_SourceRouteType ,
  193. LPCWSTR a_SourceRoute,
  194. BOOL a_ResolveAddress,
  195. ULONG a_ResolveError
  196. ) ;
  197. BOOL GetClassObject ( IWbemClassObject **a_ppClass ) ;
  198. BOOL SetProperties(CPingCallBackObject *a_Response) ;
  199. BOOL GetStatusObject ( IWbemClassObject **a_NotifyObject ) ;
  200. public:
  201. CPingTaskObject (
  202. CPingProvider *a_Provider ,
  203. IWbemObjectSink *a_NotificationHandler ,
  204. IWbemContext *a_Ctx
  205. ) ;
  206. virtual void HandleResponse (CPingCallBackObject *a_reply) = 0 ;
  207. virtual void HandleErrorResponse (DWORD a_ErrMsgID, HRESULT a_HRes) = 0 ;
  208. BOOL GetThreadToken();
  209. BOOL SetThreadToken(BOOL a_Reset);
  210. static HRESULT Icmp_ResolveAddress ( LPCWSTR a_Path , ULONG &a_IpAddress , DWORD *a_pdwErr = NULL ) ;
  211. virtual ~CPingTaskObject () ;
  212. } ;
  213. class CPingGetAsync : public CPingTaskObject
  214. {
  215. private:
  216. wchar_t *m_ObjectPath ;
  217. ParsedObjectPath *m_ParsedObjectPath ;
  218. CObjectPathParser m_ObjectPathParser ;
  219. protected:
  220. HRESULT GetDefaultTTL ( DWORD &a_TimeToLive ) ;
  221. public:
  222. ~CPingGetAsync () ;
  223. CPingGetAsync (
  224. CPingProvider *a_Provider ,
  225. wchar_t *a_ObjectPath ,
  226. ULONG a_Flag ,
  227. IWbemObjectSink *a_NotificationHandler ,
  228. IWbemContext *pCtx
  229. ) ;
  230. BOOL GetObject () ;
  231. BOOL PerformGet () ;
  232. void HandleResponse (CPingCallBackObject *a_reply) ;
  233. void HandleErrorResponse (DWORD a_ErrMsgID, HRESULT a_HRes) ;
  234. } ;
  235. class CPingQueryAsync : public CPingTaskObject, public QueryPreprocessor
  236. {
  237. private:
  238. wchar_t *m_QueryFormat ;
  239. wchar_t *m_Query ;
  240. QueryPreprocessor :: QuadState Compare (
  241. wchar_t *a_Operand1 ,
  242. wchar_t *a_Operand2 ,
  243. DWORD a_Operand1Func ,
  244. DWORD a_Operand2Func ,
  245. WmiTreeNode &a_OperatorType
  246. ) ;
  247. QueryPreprocessor :: QuadState Compare (
  248. LONG a_Operand1 ,
  249. LONG a_Operand2 ,
  250. DWORD a_Operand1Func ,
  251. DWORD a_Operand2Func ,
  252. WmiTreeNode &a_OperatorType
  253. ) ;
  254. QueryPreprocessor :: QuadState CompareString (
  255. IWbemClassObject *a_ClassObject ,
  256. BSTR a_PropertyName ,
  257. WmiTreeNode *a_Operator ,
  258. WmiTreeNode *a_Operand
  259. ) ;
  260. QueryPreprocessor :: QuadState CompareInteger (
  261. IWbemClassObject *a_ClassObject ,
  262. BSTR a_PropertyName ,
  263. WmiTreeNode *a_Operator ,
  264. WmiTreeNode *a_Operand
  265. ) ;
  266. HRESULT RecurseAddress (
  267. void *pMethodContext,
  268. PartitionSet *a_PartitionSet
  269. ) ;
  270. HRESULT RecurseTimeOut (
  271. void *pMethodContext,
  272. wchar_t *a_AddressString ,
  273. ULONG a_Address ,
  274. PartitionSet *a_PartitionSet ,
  275. ULONG a_ResolveError
  276. ) ;
  277. HRESULT RecurseTimeToLive (
  278. void *pMethodContext,
  279. wchar_t *a_AddressString ,
  280. ULONG a_Address ,
  281. ULONG a_TimeOut ,
  282. PartitionSet *a_PartitionSet ,
  283. ULONG a_ResolveError
  284. ) ;
  285. HRESULT RecurseBufferSize (
  286. void *pMethodContext,
  287. wchar_t *a_AddressString ,
  288. ULONG a_Address ,
  289. ULONG a_TimeOut ,
  290. ULONG a_TimeToLive ,
  291. PartitionSet *a_PartitionSet ,
  292. ULONG a_ResolveError
  293. ) ;
  294. HRESULT RecurseNoFragmentation (
  295. void *pMethodContext,
  296. wchar_t *a_AddressString ,
  297. ULONG a_Address ,
  298. ULONG a_TimeOut ,
  299. ULONG a_TimeToLive,
  300. ULONG a_SendSize,
  301. PartitionSet *a_PartitionSet ,
  302. ULONG a_ResolveError
  303. ) ;
  304. HRESULT RecurseTypeOfService (
  305. void *pMethodContext,
  306. wchar_t *a_AddressString ,
  307. ULONG a_Address ,
  308. ULONG a_TimeOut ,
  309. ULONG a_TimeToLive,
  310. ULONG a_SendSize,
  311. BOOL a_NoFragmentation ,
  312. PartitionSet *a_PartitionSet ,
  313. ULONG a_ResolveError
  314. ) ;
  315. HRESULT RecurseRecordRoute (
  316. void *pMethodContext,
  317. wchar_t *a_AddressString ,
  318. ULONG a_Address ,
  319. ULONG a_TimeOut ,
  320. ULONG a_TimeToLive,
  321. ULONG a_SendSize,
  322. BOOL a_NoFragmentation ,
  323. ULONG a_TypeOfService,
  324. PartitionSet *a_PartitionSet ,
  325. ULONG a_ResolveError
  326. ) ;
  327. HRESULT RecurseTimestampRoute (
  328. void *pMethodContext,
  329. wchar_t *a_AddressString ,
  330. ULONG a_Address ,
  331. ULONG a_TimeOut ,
  332. ULONG a_TimeToLive,
  333. ULONG a_SendSize,
  334. BOOL a_NoFragmentation ,
  335. ULONG a_TypeOfService,
  336. ULONG a_RecordRoute,
  337. PartitionSet *a_PartitionSet ,
  338. ULONG a_ResolveError
  339. ) ;
  340. HRESULT RecurseSourceRouteType (
  341. void *pMethodContext,
  342. wchar_t *a_AddressString ,
  343. ULONG a_Address ,
  344. ULONG a_TimeOut ,
  345. ULONG a_TimeToLive,
  346. ULONG a_SendSize,
  347. BOOL a_NoFragmentation ,
  348. ULONG a_TypeOfService,
  349. ULONG a_RecordRoute,
  350. ULONG a_TimestampRoute,
  351. PartitionSet *a_PartitionSet ,
  352. ULONG a_ResolveError
  353. ) ;
  354. HRESULT RecurseSourceRoute (
  355. void *pMethodContext,
  356. wchar_t *a_AddressString ,
  357. ULONG a_Address ,
  358. ULONG a_TimeOut ,
  359. ULONG a_TimeToLive,
  360. ULONG a_SendSize,
  361. BOOL a_NoFragmentation ,
  362. ULONG a_TypeOfService,
  363. ULONG a_RecordRoute,
  364. ULONG a_TimestampRoute,
  365. ULONG a_SourceRouteType,
  366. PartitionSet *a_PartitionSet ,
  367. ULONG a_ResolveError
  368. ) ;
  369. HRESULT RecurseResolveAddressNames (
  370. void *pMethodContext,
  371. wchar_t *a_AddressString ,
  372. ULONG a_Address ,
  373. ULONG a_TimeOut ,
  374. ULONG a_TimeToLive,
  375. ULONG a_SendSize,
  376. BOOL a_NoFragmentation ,
  377. ULONG a_TypeOfService,
  378. ULONG a_RecordRoute,
  379. ULONG a_TimestampRoute,
  380. ULONG a_SourceRouteType,
  381. LPCWSTR a_SourceRoute,
  382. PartitionSet *a_PartitionSet ,
  383. ULONG a_ResolveError
  384. );
  385. protected:
  386. // Reading Functions
  387. //============================
  388. WmiTreeNode *AllocTypeNode (
  389. void *a_Context ,
  390. BSTR a_PropertyName ,
  391. VARIANT &a_Variant ,
  392. WmiValueNode :: WmiValueFunction a_PropertyFunction ,
  393. WmiValueNode :: WmiValueFunction a_ConstantFunction ,
  394. WmiTreeNode *a_Parent
  395. ) ;
  396. QuadState InvariantEvaluate (
  397. void *a_Context ,
  398. WmiTreeNode *a_Operator ,
  399. WmiTreeNode *a_Operand
  400. ) ;
  401. WmiRangeNode *AllocInfiniteRangeNode (
  402. void *a_Context ,
  403. BSTR a_PropertyName
  404. ) ;
  405. virtual DWORD GetPriority ( BSTR a_PropertyName ) ;
  406. public:
  407. CPingQueryAsync (
  408. CPingProvider *a_Provider ,
  409. BSTR a_QueryFormat ,
  410. BSTR a_Query ,
  411. ULONG a_Flag ,
  412. IWbemObjectSink *a_NotificationHandler ,
  413. IWbemContext *pCtx
  414. ) ;
  415. ~CPingQueryAsync () ;
  416. BOOL ExecQuery () ;
  417. void HandleResponse (CPingCallBackObject *a_reply) ;
  418. void HandleErrorResponse (DWORD a_ErrMsgID, HRESULT a_HRes) ;
  419. } ;
  420. #endif //_CPingTask_H_