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.

286 lines
5.8 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #include "precomp.h"
  8. #include <wbemcli.h>
  9. #include <comutl.h>
  10. #include "msmqcomn.h"
  11. #include "msmqqmgr.h"
  12. static QUEUEPROPID g_aQueuePropID[] = { PROPID_Q_TRANSACTION,
  13. PROPID_Q_PATHNAME,
  14. PROPID_Q_AUTHENTICATE,
  15. PROPID_Q_QUOTA,
  16. PROPID_Q_TYPE };
  17. const DWORD g_cQueueProp = sizeof(g_aQueuePropID) / sizeof(QUEUEPROPID);
  18. #define CALLFUNC(FUNC) m_Api.m_fp ## FUNC
  19. /*************************************************************************
  20. CMsgMsmqQueueMgr
  21. **************************************************************************/
  22. HRESULT CMsgMsmqQueueMgr::EnsureMsmq()
  23. {
  24. HRESULT hr;
  25. CInCritSec ics( &m_cs );
  26. hr = m_Api.Initialize();
  27. if ( FAILED(hr) )
  28. {
  29. return hr;
  30. }
  31. return EnsureMsmqService( m_Api );
  32. }
  33. HRESULT CMsgMsmqQueueMgr::Create( LPCWSTR wszPathName,
  34. GUID guidType,
  35. BOOL bAuth,
  36. DWORD dwQos,
  37. DWORD dwQuota,
  38. PVOID pSecDesc )
  39. {
  40. HRESULT hr;
  41. hr = EnsureMsmq();
  42. if ( FAILED(hr) )
  43. {
  44. return hr;
  45. }
  46. MQPROPVARIANT aPropVar[g_cQueueProp];
  47. BOOL bXact = dwQos == WMIMSG_FLAG_QOS_XACT ? TRUE : FALSE;
  48. //
  49. // transaction
  50. //
  51. aPropVar[0].vt = VT_UI1;
  52. aPropVar[0].bVal = bXact ? MQ_TRANSACTIONAL : MQ_TRANSACTIONAL_NONE;
  53. //
  54. // pathname
  55. //
  56. aPropVar[1].vt = VT_LPWSTR;
  57. aPropVar[1].pwszVal = LPWSTR(wszPathName);
  58. //
  59. // auth
  60. //
  61. aPropVar[2].vt = VT_UI1;
  62. aPropVar[2].bVal = bAuth ? MQ_AUTHENTICATE : MQ_AUTHENTICATE_NONE;
  63. //
  64. // quota
  65. //
  66. aPropVar[3].vt = VT_UI4;
  67. aPropVar[3].ulVal = dwQuota;
  68. //
  69. // type
  70. //
  71. aPropVar[4].vt = VT_CLSID;
  72. aPropVar[4].puuid = &guidType;
  73. MQQUEUEPROPS QueueProps;
  74. QueueProps.cProp = g_cQueueProp;
  75. QueueProps.aPropID = g_aQueuePropID;
  76. QueueProps.aPropVar = aPropVar;
  77. QueueProps.aStatus = NULL;
  78. DWORD dwDummy = 0;
  79. hr = CALLFUNC(MQCreateQueue)( pSecDesc, &QueueProps, NULL, &dwDummy );
  80. if ( FAILED(hr) )
  81. {
  82. return MqResToWmiRes(hr);
  83. }
  84. return hr;
  85. }
  86. HRESULT CMsgMsmqQueueMgr::Destroy( LPCWSTR wszName )
  87. {
  88. ENTER_API_CALL
  89. HRESULT hr;
  90. hr = EnsureMsmq();
  91. if ( FAILED(hr) )
  92. {
  93. return hr;
  94. }
  95. WString wsFormat;
  96. hr = NormalizeQueueName( m_Api, wszName, wsFormat );
  97. if ( FAILED(hr) )
  98. {
  99. return MqResToWmiRes( hr);
  100. }
  101. return CALLFUNC(MQDeleteQueue)( wsFormat );
  102. EXIT_API_CALL
  103. }
  104. HRESULT CMsgMsmqQueueMgr::GetAllNames( GUID guidTypeFilter,
  105. BOOL bPrivateOnly,
  106. LPWSTR** ppwszNames,
  107. ULONG* pcNames )
  108. {
  109. ENTER_API_CALL
  110. HRESULT hr;
  111. *ppwszNames = NULL;
  112. *pcNames = 0;
  113. hr = EnsureMsmq();
  114. if ( FAILED(hr) )
  115. {
  116. return hr;
  117. }
  118. if ( bPrivateOnly != TRUE )
  119. {
  120. return WBEM_E_NOT_SUPPORTED;
  121. }
  122. //
  123. // First get all private queue names.
  124. //
  125. MGMTPROPID MgmtPropID = PROPID_MGMT_MSMQ_PRIVATEQ;
  126. MQPROPVARIANT MgmtPropVar;
  127. MgmtPropVar.vt = VT_LPWSTR | VT_VECTOR;
  128. MQMGMTPROPS MgmtProps;
  129. MgmtProps.cProp = 1;
  130. MgmtProps.aPropID = &MgmtPropID;
  131. MgmtProps.aPropVar = &MgmtPropVar;
  132. MgmtProps.aStatus = NULL;
  133. hr = CALLFUNC(MQMgmtGetInfo)( NULL, L"MACHINE", &MgmtProps );
  134. if ( FAILED(hr) )
  135. {
  136. return MqResToWmiRes( hr );
  137. }
  138. //
  139. // Allocate return array to total number of private queues.
  140. // Because of the filter guid, the actual returned number
  141. // will most likely be smaller.
  142. //
  143. DWORD dwSize = sizeof(LPWSTR) * MgmtPropVar.calpwstr.cElems;
  144. LPWSTR* awszNames = (LPWSTR*)CoTaskMemAlloc( dwSize );
  145. if ( awszNames == NULL )
  146. {
  147. CALLFUNC(MQFreeMemory)( MgmtPropVar.calpwstr.pElems );
  148. return WBEM_E_OUT_OF_MEMORY;
  149. }
  150. //
  151. // for each name, get the queue type guid for it and compare
  152. // with the filter type guid.
  153. //
  154. CLSID guidType;
  155. QUEUEPROPID QueuePropID = PROPID_Q_TYPE;
  156. MQPROPVARIANT QueuePropVar;
  157. QueuePropVar.vt = VT_CLSID;
  158. QueuePropVar.puuid = &guidType;
  159. MQQUEUEPROPS QueueProps;
  160. QueueProps.cProp = 1;
  161. QueueProps.aPropID = &QueuePropID;
  162. QueueProps.aPropVar = &QueuePropVar;
  163. QueueProps.aStatus = NULL;
  164. ULONG cNames = 0;
  165. for( ULONG i=0; i < MgmtPropVar.calpwstr.cElems; i++ )
  166. {
  167. WString wsQueueName;
  168. LPWSTR wszPathname = MgmtPropVar.calpwstr.pElems[i];
  169. hr = NormalizeQueueName( m_Api, wszPathname, wsQueueName );
  170. if ( FAILED(hr) )
  171. {
  172. return MqResToWmiRes( hr );
  173. }
  174. hr = CALLFUNC(MQGetQueueProperties)( wsQueueName, &QueueProps );
  175. if ( FAILED(hr) )
  176. {
  177. continue;
  178. }
  179. if ( guidType == guidTypeFilter )
  180. {
  181. DWORD dwSize = (wcslen(wszPathname)+1)*sizeof(WCHAR);
  182. awszNames[cNames] = (LPWSTR)CoTaskMemAlloc( dwSize );
  183. if ( awszNames[cNames] == NULL )
  184. {
  185. hr = WBEM_E_OUT_OF_MEMORY;
  186. break;
  187. }
  188. wcscpy( awszNames[cNames], wszPathname );
  189. cNames++;
  190. }
  191. }
  192. if ( FAILED(hr) )
  193. {
  194. for( i=0; i < cNames; i++ )
  195. {
  196. CoTaskMemFree( awszNames[i] );
  197. }
  198. CoTaskMemFree( awszNames );
  199. }
  200. CALLFUNC(MQFreeMemory)( MgmtPropVar.calpwstr.pElems );
  201. *ppwszNames = awszNames;
  202. *pcNames = cNames;
  203. return hr;
  204. EXIT_API_CALL
  205. }