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.

267 lines
8.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. mqtrans.hxx
  5. Abstract:
  6. Falcon (MSMQ) datagram transport specific definitions.
  7. Author:
  8. Edward Reus 04-Jul-1997
  9. Revision History:
  10. --*/
  11. #ifndef __MQTRANS_HXX__
  12. #define __MQTRANS_HXX__
  13. //-------------------------------------------------------------------
  14. // Falcon specific includes. Sorry, we need to include wtypes.h
  15. // and objidl.h in order to compile mq.h (can you say circular
  16. // definition?). This is the price you pay for using such a "high"
  17. // level protocol and run RPC over Falcon over RPC...
  18. //-------------------------------------------------------------------
  19. #ifndef __wtypes_h__
  20. #include <wtypes.h>
  21. #endif
  22. #ifndef __objidl_h__
  23. #include <objidl.h>
  24. #endif
  25. #ifndef __MQ_H__
  26. #include <mq.h>
  27. #endif
  28. //-------------------------------------------------------------------
  29. // Constants:
  30. //-------------------------------------------------------------------
  31. // Turn on to support client private queues:
  32. // #define USE_PRIVATE_QUEUES
  33. #define MAX_PATHNAME_LEN 256
  34. #define MAX_FORMAT_LEN 128
  35. #define MAX_COMPUTERNAME_LEN 255
  36. #define MAX_VAR 20
  37. #define MAX_SEND_VAR 20
  38. #define MAX_RECV_VAR 20
  39. #define MAX_SID_SIZE 256 // A typical SID is 20-30 bytes...
  40. #define MAX_USERNAME_SIZE 256
  41. #define MAX_DOMAIN_SIZE 256
  42. #define UUID_LEN 40
  43. #define TRANSPORTID 0x1D
  44. #define TRANSPORTHOSTID 0x1E
  45. #define PROTSEQ "ncadg_mq"
  46. #define ENDPOINT_MAPPER_EP "EpMapper"
  47. #define MQ_PREFERRED_PDU_SIZE 65535
  48. #define MQ_MAX_PDU_SIZE 65535
  49. #define MQ_MAX_PACKET_SIZE 65535
  50. // 65456
  51. #define MQ_RECEIVE_BUFFER_SIZE 2*MQ_MAX_PACKET_SIZE
  52. #define WS_ASTRISK RPC_STRING_LITERAL("*")
  53. #define WS_SEPARATOR RPC_STRING_LITERAL("\\")
  54. #define WS_PRIVATE_DOLLAR RPC_STRING_LITERAL("\\PRIVATE$\\")
  55. #define WS_DIRECT RPC_STRING_LITERAL("DIRECT=OS:")
  56. // These constants are use for temporary queue management:
  57. #define Q_SVC_PROTSEQ RPC_STRING_LITERAL("ncalrpc")
  58. #define Q_SVC_ENDPOINT RPC_STRING_LITERAL("epmapper")
  59. // These are the MQ Queue Type UUIDs for RPC:
  60. #define SVR_QTYPE_UUID_STR RPC_STRING_LITERAL("bbd97de0-cb4f-11cf-8e62-00aa006b4f2f")
  61. #define CLNT_QTYPE_UUID_STR RPC_STRING_LITERAL("8e482920-cead-11cf-8e68-00aa006b4f2f")
  62. #define CLNT_ADMIN_QTYPE_UUID_STR RPC_STRING_LITERAL("c87ca5c0-ff67-11cf-8ebd-00aa006b4f2f")
  63. #define DEFAULT_PRIORITY 3
  64. #define MAX_QUEUEMAP_ENTRIES 10
  65. // Where key entries are located when reading a message (aMsgPropVar[]):
  66. #define I_MESSAGE_SIZE 1
  67. #define I_MESSAGE_LABEL 2
  68. #define I_AUTHENTICATED 6
  69. #define I_PRIVACY_LEVEL 7
  70. //-------------------------------------------------------------------
  71. // MSMQ API Function Definitions:
  72. //
  73. // The FALCON_API is our access point into Falcon.
  74. //-------------------------------------------------------------------
  75. typedef HRESULT (*P_MQLOCATEBEGIN)( LPWSTR, MQRESTRICTION* ,MQCOLUMNSET*, MQSORTSET*, PHANDLE );
  76. typedef HRESULT (*P_MQLOCATENEXT)( HANDLE, DWORD*, MQPROPVARIANT* );
  77. typedef HRESULT (*P_MQLOCATEEND)( HANDLE );
  78. typedef HRESULT (*P_MQINSTANCETOFORMATNAME)( GUID*, LPWSTR, DWORD* );
  79. typedef HRESULT (*P_MQOPENQUEUE)( LPWSTR, DWORD, DWORD, QUEUEHANDLE* );
  80. typedef HRESULT (*P_MQFREEMEMORY)( PVOID );
  81. typedef HRESULT (*P_MQSENDMESSAGE)( QUEUEHANDLE, MQMSGPROPS*, ITransaction* );
  82. typedef HRESULT (*P_MQRECEIVEMESSAGE)( QUEUEHANDLE, DWORD, DWORD, MQMSGPROPS*,
  83. LPOVERLAPPED, PMQRECEIVECALLBACK, HANDLE, ITransaction* );
  84. typedef HRESULT (*P_MQCLOSEQUEUE)( QUEUEHANDLE );
  85. typedef HRESULT (*P_MQDELETEQUEUE)( LPWSTR );
  86. typedef HRESULT (*P_MQPATHNAMETOFORMATNAME)( LPWSTR, LPWSTR, DWORD* );
  87. typedef HRESULT (*P_MQCREATEQUEUE)( PSECURITY_DESCRIPTOR, MQQUEUEPROPS*, LPWSTR, DWORD* );
  88. typedef HRESULT (*P_MQGETMACHINEPROPERTIES)( LPWSTR, const GUID*, MQQMPROPS* );
  89. typedef HRESULT (*P_MQGETQUEUEPROPERTIES)( LPWSTR, MQQUEUEPROPS* );
  90. typedef HRESULT (*P_MQSETQUEUEPROPERTIES)( LPWSTR, MQQUEUEPROPS* );
  91. typedef struct _FALCON_API
  92. {
  93. // WARNING: The number and order of these functions must match the function string
  94. // array in MQ_Initialize().
  95. P_MQLOCATEBEGIN pMQLocateBegin;
  96. P_MQLOCATENEXT pMQLocateNext;
  97. P_MQLOCATEEND pMQLocateEnd;
  98. P_MQINSTANCETOFORMATNAME pMQInstanceToFormatName;
  99. P_MQOPENQUEUE pMQOpenQueue;
  100. P_MQFREEMEMORY pMQFreeMemory;
  101. P_MQSENDMESSAGE pMQSendMessage;
  102. P_MQRECEIVEMESSAGE pMQReceiveMessage;
  103. P_MQCLOSEQUEUE pMQCloseQueue;
  104. P_MQDELETEQUEUE pMQDeleteQueue;
  105. P_MQPATHNAMETOFORMATNAME pMQPathNameToFormatName;
  106. P_MQCREATEQUEUE pMQCreateQueue;
  107. P_MQGETMACHINEPROPERTIES pMQGetMachineProperties;
  108. P_MQGETQUEUEPROPERTIES pMQGetQueueProperties;
  109. P_MQSETQUEUEPROPERTIES pMQSetQueueProperties;
  110. } FALCON_API;
  111. extern FALCON_API *g_pMqApi;
  112. typedef struct _MQ_ADDRESS
  113. {
  114. QUEUEHANDLE hQueue;
  115. // for the MsgLabel and the QFormat we provide space for Unicode so that our memory management
  116. // is simplified. Then whenever we get a Unicode string from Falcon, we convert it back to ANSI
  117. // in place
  118. RPC_CHAR wsMsgLabel[MQ_MAX_MSG_LABEL_LEN * sizeof(WCHAR)];
  119. RPC_CHAR wsMachine[MAX_COMPUTERNAME_LEN];
  120. RPC_CHAR wsQName[MQ_MAX_Q_NAME_LEN];
  121. RPC_CHAR wsQFormat[MAX_FORMAT_LEN * sizeof(WCHAR)];
  122. BOOL fConnectionFailed;
  123. BOOL fAuthenticated; // Server security tracking.
  124. ULONG ulPrivacyLevel; // Server security tracking.
  125. UCHAR aSidBuffer[MAX_SID_SIZE]; // Server security tracking.
  126. } MQ_ADDRESS;
  127. typedef struct _MQ_OPTIONS
  128. {
  129. BOOL fAck;
  130. ULONG ulDelivery;
  131. ULONG ulPriority;
  132. ULONG ulJournaling;
  133. ULONG ulTimeToReachQueue;
  134. ULONG ulTimeToReceive;
  135. BOOL fAuthenticate;
  136. BOOL fEncrypt;
  137. } MQ_OPTIONS;
  138. // UNICODE/ANSI mappings
  139. #define MQLocateBegin(ctx, r, col, s, e) \
  140. g_pMqApi->pMQLocateBegin(ctx, r, col, s, e)
  141. #define MQLocateNext(e, p, pv) \
  142. g_pMqApi->pMQLocateNext(e, p, pv)
  143. #define MQLocateEnd(e) \
  144. g_pMqApi->pMQLocateEnd(e)
  145. #define MQInstanceToFormatName(g, f, l) \
  146. g_pMqApi->pMQInstanceToFormatName(g, f, l)
  147. #define MQOpenQueue(f, a, s, q) \
  148. g_pMqApi->pMQOpenQueue(f, a, s, q)
  149. #define MQFreeMemory(m) \
  150. g_pMqApi->pMQFreeMemory(m)
  151. #define MQSendMessage(q, p, t) \
  152. g_pMqApi->pMQSendMessage(q, p, t)
  153. #define MQReceiveMessage(s, ti, a, p, o, cb, cr, tr) \
  154. g_pMqApi->pMQReceiveMessage(s, ti, a, p, o, cb, cr, tr)
  155. #define MQCloseQueue(q) \
  156. g_pMqApi->pMQCloseQueue(q)
  157. #define MQDeleteQueue(f) \
  158. g_pMqApi->pMQDeleteQueue(f)
  159. #define MQPathNameToFormatName(p, f, l) \
  160. g_pMqApi->pMQPathNameToFormatName(p, f, l)
  161. #define MQCreateQueue(s, p, f, l) \
  162. g_pMqApi->pMQCreateQueue(s, p, f, l)
  163. #define MQGetMachineProperties(m, g, p) \
  164. g_pMqApi->pMQGetMachineProperties(m, g, p)
  165. #define MQGetQueueProperties(f, p) \
  166. g_pMqApi->pMQGetQueueProperties(f, p)
  167. #define MQSetQueueProperties(f, p) \
  168. g_pMqApi->pMQSetQueueProperties(f, p)
  169. #define MQFreeStringFromProperty(p) \
  170. if ((p)->vt == VT_LPSTR) \
  171. delete ((p)->pszVal); \
  172. else \
  173. { \
  174. ASSERT((p)->vt == VT_LPWSTR); \
  175. MQFreeMemory((p)->pwszVal); \
  176. }
  177. //---------------------------------------------------------------
  178. // CQueueMap
  179. //---------------------------------------------------------------
  180. typedef struct _QUEUEMAP_ENTRY
  181. {
  182. QUEUEHANDLE hQueue;
  183. RPC_CHAR *pwsQFormat;
  184. } QUEUEMAP_ENTRY;
  185. class CQueueMap
  186. {
  187. public:
  188. // Construction
  189. CQueueMap();
  190. BOOL Initialize( DWORD dwMapSize = MAX_QUEUEMAP_ENTRIES );
  191. // Lookup
  192. QUEUEHANDLE Lookup( RPC_CHAR *pwsQFormat );
  193. // Add a new (key,value) pair
  194. BOOL Add( RPC_CHAR *pwsQFormat, QUEUEHANDLE hQueue );
  195. // Find and remove an entry
  196. BOOL Remove( RPC_CHAR *pwsQFormat );
  197. ~CQueueMap();
  198. private:
  199. MUTEX cs;
  200. DWORD dwMapSize;
  201. DWORD dwOldest;
  202. QUEUEMAP_ENTRY *pMap;
  203. RPC_STATUS InitStatus;
  204. };
  205. #endif // __FALCON_HXX