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.

621 lines
14 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. binding.hxx
  5. Abstract:
  6. The class representing a DCE binding lives here. A DCE binding
  7. consists of an optional object UUID, an RPC protocol sequence, a
  8. network address, an optional endpoint, and zero or more network
  9. options.
  10. Author:
  11. Michael Montague (mikemon) 04-Nov-1991
  12. Revision History:
  13. --*/
  14. #ifndef __BINDING_HXX__
  15. #define __BINDING_HXX__
  16. class BINDING_HANDLE;
  17. class DCE_BINDING
  18. /*++
  19. Class Description:
  20. Instances of this class represent an internalized form of a string
  21. binding. In particular, a string binding can be used to construct
  22. an instance of DCE_BINDING. We parse the string binding into
  23. its components and convert the object UUID from a string to a
  24. UUID.
  25. Fields:
  26. ObjectUuid - Contains the object uuid for this binding. This
  27. field will always contain a valid object uuid. If no object
  28. uuid was specified in the string binding used to create an
  29. instance, then ObjectUuid will be the NULL UUID.
  30. RpcProtocolSequence - Contains the rpc protocol sequence for this
  31. binding. This field will always either point to a string or
  32. be zero.
  33. NetworkAddress - Contains the network addres for this binding. This
  34. field will always be zero or point to a string (which is the
  35. network address for this dce binding).
  36. Endpoint - Contains the endpoint for this binding, which will either
  37. pointer to a string or be zero.
  38. Options - Contains the optional network options for this binding.
  39. As will the other fields, this field will either point to a string,
  40. or be zero.
  41. --*/
  42. {
  43. private:
  44. RPC_CHAR * RpcProtocolSequence;
  45. RPC_CHAR * NetworkAddress;
  46. RPC_CHAR * Endpoint;
  47. RPC_CHAR * Options;
  48. RPC_UUID ObjectUuid;
  49. public:
  50. DCE_BINDING (
  51. IN RPC_CHAR PAPI * ObjectUuid OPTIONAL,
  52. IN RPC_CHAR PAPI * RpcProtocolSequence OPTIONAL,
  53. IN RPC_CHAR PAPI * NetworkAddress OPTIONAL,
  54. IN RPC_CHAR PAPI * Endpoint OPTIONAL,
  55. IN RPC_CHAR PAPI * Options OPTIONAL,
  56. OUT RPC_STATUS PAPI * Status
  57. );
  58. DCE_BINDING (
  59. IN RPC_CHAR PAPI * StringBinding,
  60. OUT RPC_STATUS PAPI * Status
  61. );
  62. ~DCE_BINDING (
  63. );
  64. RPC_CHAR PAPI *
  65. StringBindingCompose (
  66. IN RPC_UUID PAPI * Uuid OPTIONAL,
  67. IN BOOL fStatic = 0
  68. );
  69. RPC_CHAR PAPI *
  70. ObjectUuidCompose (
  71. OUT RPC_STATUS PAPI * Status
  72. );
  73. RPC_CHAR PAPI *
  74. RpcProtocolSequenceCompose (
  75. OUT RPC_STATUS PAPI * Status
  76. );
  77. RPC_CHAR PAPI *
  78. NetworkAddressCompose (
  79. OUT RPC_STATUS PAPI * Status
  80. );
  81. RPC_CHAR PAPI *
  82. EndpointCompose (
  83. OUT RPC_STATUS PAPI * Status
  84. );
  85. RPC_CHAR PAPI *
  86. OptionsCompose (
  87. OUT RPC_STATUS PAPI * Status
  88. );
  89. BINDING_HANDLE *
  90. CreateBindingHandle (
  91. OUT RPC_STATUS PAPI * Status
  92. );
  93. RPC_CHAR *
  94. InqNetworkAddress (
  95. );
  96. RPC_CHAR *
  97. InqEndpoint (
  98. );
  99. BOOL
  100. IsNullEndpoint (
  101. void
  102. );
  103. RPC_CHAR *
  104. InqNetworkOptions (
  105. );
  106. RPC_CHAR *
  107. InqRpcProtocolSequence (
  108. );
  109. void
  110. AddEndpoint(
  111. IN RPC_CHAR *Endpoint
  112. );
  113. RPC_STATUS
  114. ResolveEndpointIfNecessary (
  115. IN PRPC_CLIENT_INTERFACE RpcInterfaceInformation,
  116. IN RPC_UUID * ObjectUuid,
  117. IN OUT void PAPI * PAPI * EpLookupHandle,
  118. IN BOOL UseEpMapperEp,
  119. IN unsigned ConnTimeout,
  120. IN ULONG CallTimeout,
  121. IN CLIENT_AUTH_INFO *AuthInfo OPTIONAL
  122. );
  123. int
  124. Compare (
  125. IN DCE_BINDING * DceBinding,
  126. OUT BOOL *fOnlyEndpointDiffers
  127. );
  128. int
  129. CompareWithoutSecurityOptions (
  130. IN DCE_BINDING * DceBinding,
  131. OUT BOOL *fOnlyEndpointDiffers
  132. );
  133. DCE_BINDING *
  134. DuplicateDceBinding (
  135. );
  136. void
  137. MakePartiallyBound (
  138. );
  139. BOOL
  140. MaybeMakePartiallyBound (
  141. IN PRPC_CLIENT_INTERFACE RpcInterfaceInformation,
  142. IN RPC_UUID * ObjectUuid
  143. );
  144. BOOL
  145. IsNamedPipeTransport (
  146. )
  147. {
  148. return (RpcpStringCompare(RpcProtocolSequence, RPC_CONST_STRING("ncacn_np")) == 0);
  149. }
  150. };
  151. inline RPC_CHAR *
  152. DCE_BINDING::InqNetworkAddress (
  153. )
  154. /*++
  155. Routine Description:
  156. A pointer to the network address for this address is returned.
  157. --*/
  158. {
  159. return(NetworkAddress);
  160. }
  161. inline RPC_CHAR *
  162. DCE_BINDING::InqEndpoint (
  163. )
  164. /*++
  165. Routine Description:
  166. A pointer to the endpoint for this address is returned.
  167. --*/
  168. {
  169. return(Endpoint);
  170. }
  171. inline BOOL
  172. DCE_BINDING::IsNullEndpoint (
  173. void
  174. )
  175. /*++
  176. Routine Description:
  177. Returns non-zero if the endpoint
  178. is NULL.
  179. --*/
  180. {
  181. return ((Endpoint == NULL) || (Endpoint[0] == 0));
  182. }
  183. inline RPC_CHAR *
  184. DCE_BINDING::InqNetworkOptions (
  185. )
  186. /*++
  187. Routine Description:
  188. A pointer to the network options for this address is returned.
  189. --*/
  190. {
  191. return(Options);
  192. }
  193. inline RPC_CHAR *
  194. DCE_BINDING::InqRpcProtocolSequence (
  195. )
  196. /*++
  197. Routine Description:
  198. A pointer to the rpc protocol sequence for this binding is returned.
  199. --*/
  200. {
  201. return(RpcProtocolSequence);
  202. }
  203. #define MAX_PROTSEQ_LENGTH MAX_DLLNAME_LENGTH
  204. class LOADABLE_TRANSPORT;
  205. class TRANS_INFO
  206. /*++
  207. Class Description:
  208. Fields:
  209. pTransportInterface - Contains all of the required information about
  210. a loadable transport so that we can make use of it.
  211. --*/
  212. {
  213. private:
  214. RPC_TRANSPORT_INTERFACE pTransportInterface;
  215. LOADABLE_TRANSPORT *LoadableTrans ;
  216. RPC_CHAR RpcProtocolSequence[MAX_PROTSEQ_LENGTH + 1];
  217. public:
  218. TRANS_INFO (
  219. IN RPC_TRANSPORT_INTERFACE pTransportInterface,
  220. IN RPC_CHAR *ProtocolSeq,
  221. IN LOADABLE_TRANSPORT *LoadableTrans
  222. ) ;
  223. BOOL
  224. MatchProtseq(
  225. IN RPC_CHAR *ProtocolSeq
  226. ) ;
  227. BOOL
  228. MatchId (
  229. IN unsigned short Id
  230. );
  231. RPC_TRANSPORT_INTERFACE
  232. InqTransInfo (
  233. );
  234. RPC_STATUS
  235. StartServerIfNecessary(
  236. );
  237. RPC_STATUS
  238. CreateThread (
  239. );
  240. };
  241. inline
  242. TRANS_INFO::TRANS_INFO (
  243. IN RPC_TRANSPORT_INTERFACE pTransportInterface,
  244. IN RPC_CHAR *ProtocolSeq,
  245. IN LOADABLE_TRANSPORT *LoadableTrans
  246. )
  247. {
  248. this->pTransportInterface = pTransportInterface ;
  249. RpcpStringCopy(RpcProtocolSequence, ProtocolSeq) ;
  250. this->LoadableTrans = LoadableTrans ;
  251. }
  252. inline BOOL
  253. TRANS_INFO::MatchProtseq(
  254. IN RPC_CHAR *ProtocolSeq
  255. )
  256. {
  257. if (RpcpStringCompare(ProtocolSeq, RpcProtocolSequence) == 0)
  258. {
  259. return 1 ;
  260. }
  261. return 0;
  262. }
  263. inline BOOL
  264. TRANS_INFO::MatchId (
  265. IN unsigned short Id
  266. )
  267. {
  268. if (pTransportInterface->TransId == Id)
  269. {
  270. return 1;
  271. }
  272. return 0;
  273. }
  274. inline RPC_TRANSPORT_INTERFACE
  275. TRANS_INFO::InqTransInfo (
  276. )
  277. {
  278. return pTransportInterface ;
  279. }
  280. NEW_SDICT (TRANS_INFO);
  281. class LOADABLE_TRANSPORT
  282. /*++
  283. Class Description:
  284. This class is used as an item in a dictionary of loaded loadable
  285. transports. It contains the information we are interested in,
  286. the RPC_TRANSPORT_INTERFACE, as well as the name of the dll we loaded
  287. the transport interface from. The dll name is the key to the
  288. dictionary.
  289. Fields:
  290. DllName - Contains the name of the dll from which we loaded
  291. this transport interface.
  292. LoadedDll - Contains the dll which we had to load to get the transport
  293. support. We need to save this information so that under Windows
  294. when the runtime is unloaded, we can unload all of the transports.
  295. --*/
  296. {
  297. private:
  298. // accessed by all threads independently - put in separate cache line
  299. LONG ThreadsStarted ;
  300. RPC_CHAR DllName[MAX_DLLNAME_LENGTH + 1];
  301. // accessed by all threads independently - put in separate cache line
  302. // NumThreads is the number of threads actually doing a listen on the
  303. // completion port - this excludes the ones that are doing processing
  304. LONG NumThreads;
  305. DLL * LoadedDll;
  306. TRANS_INFO_DICT ProtseqDict ;
  307. // accessed by all threads independently - put in a separate cache line
  308. // ThreadsDoingLongWait is the number of threads that are waiting on
  309. // the completion port and their wait timeout is > MAX_SHORT_THREAD_TIMEOUT
  310. // In other words, those threads are not guaranteed to check for
  311. // garbage collection before gThreadTimeout
  312. INTERLOCKED_INTEGER ThreadsDoingLongWait;
  313. LONG Reserved0[7];
  314. // read-only often used section
  315. PROCESS_CALLS ProcessCallsFunc;
  316. long nOptimalNumberOfThreads;
  317. #ifndef NO_PLUG_AND_PLAY
  318. LISTEN_FOR_PNP_NOTIFICATIONS PnpListen;
  319. friend void ProcessNewAddressEvent(LOADABLE_TRANSPORT *pLoadableTransport,
  320. IN RPC_TRANSPORT_EVENT Event,
  321. IN RPC_STATUS EventStatus,
  322. IN PVOID pEventContext,
  323. IN UINT BufferLength,
  324. IN BUFFER Buffer,
  325. IN PVOID pSourceContext);
  326. #endif
  327. FuncGetHandleForThread GetHandleForThread;
  328. FuncReleaseHandleForThread ReleaseHandleForThread;
  329. LONG Reserved1[3];
  330. // accessed by all threads independently - put in separate cache line
  331. LONG Reserved2[7];
  332. // the total number of worker threads on the completion port - this
  333. // includes the ones that are listening, and the one that have picked
  334. // up work items and are working on them.
  335. INTERLOCKED_INTEGER nThreadsAtCompletionPort;
  336. // accessed by all threads independently - put in separate cache line
  337. LONG Reserved3[7];
  338. int nActivityValue;
  339. public:
  340. LOADABLE_TRANSPORT (
  341. IN RPC_TRANSPORT_INTERFACE pTransportInterface,
  342. IN RPC_CHAR * DllName,
  343. IN RPC_CHAR PAPI * ProtocolSequence,
  344. IN DLL *LoadableTransportDll,
  345. IN FuncGetHandleForThread GetHandleForThread,
  346. IN FuncReleaseHandleForThread ReleaseHandleForThread,
  347. OUT RPC_STATUS *Status,
  348. OUT TRANS_INFO * PAPI *TransInfo
  349. );
  350. TRANS_INFO *
  351. MapProtocol (
  352. IN RPC_CHAR * DllName,
  353. IN RPC_CHAR PAPI * ProtocolSequence
  354. );
  355. TRANS_INFO *
  356. MatchId (
  357. IN unsigned short Id
  358. );
  359. void
  360. ProcessIOEvents (
  361. );
  362. RPC_STATUS
  363. StartServerIfNecessary (
  364. );
  365. RPC_STATUS
  366. ProcessCalls (
  367. IN INT Timeout,
  368. OUT RPC_TRANSPORT_EVENT *pEvent,
  369. OUT RPC_STATUS *pEventStatus,
  370. OUT PVOID *ppEventContext,
  371. OUT UINT *pBufferLength,
  372. OUT BUFFER *pBuffer,
  373. OUT PVOID *ppSourceContext);
  374. RPC_STATUS CreateThread (void);
  375. // N.B. This can return negative numbers in rare race
  376. // conditions - make sure you handle it
  377. inline long GetThreadsDoingShortWait (
  378. void
  379. )
  380. {
  381. return (NumThreads - ThreadsDoingLongWait.GetInteger());
  382. }
  383. };
  384. inline
  385. RPC_STATUS
  386. TRANS_INFO::StartServerIfNecessary (
  387. )
  388. {
  389. return LoadableTrans->StartServerIfNecessary() ;
  390. }
  391. inline RPC_STATUS
  392. TRANS_INFO::CreateThread (
  393. )
  394. {
  395. return LoadableTrans->CreateThread();
  396. }
  397. NEW_SDICT(LOADABLE_TRANSPORT);
  398. extern LOADABLE_TRANSPORT_DICT * LoadedLoadableTransports;
  399. RPC_STATUS
  400. LoadableTransportInfo (
  401. IN RPC_CHAR * DllName,
  402. IN RPC_CHAR PAPI * RpcProtocolSequence,
  403. OUT TRANS_INFO * PAPI *pTransInfo
  404. );
  405. extern BOOL GetTransportEntryPoints(IN DLL *LoadableTransportDll,
  406. OUT TRANSPORT_LOAD *TransportLoad,
  407. OUT FuncGetHandleForThread *GetHandleForThread,
  408. OUT FuncReleaseHandleForThread *ReleaseHandleForThread
  409. );
  410. extern void
  411. UnjoinCompletionPort (
  412. void
  413. );
  414. extern RPC_STATUS
  415. IsRpcProtocolSequenceSupported (
  416. IN RPC_CHAR PAPI * RpcProtocolSequence
  417. );
  418. RPC_STATUS
  419. OsfMapRpcProtocolSequence (
  420. IN BOOL ServerSideFlag,
  421. IN RPC_CHAR PAPI * RpcProtocolSequence,
  422. OUT TRANS_INFO * PAPI *ClientTransInfo
  423. ) ;
  424. extern BINDING_HANDLE *
  425. OsfCreateBindingHandle (
  426. );
  427. extern BINDING_HANDLE *
  428. LrpcCreateBindingHandle (
  429. );
  430. extern BINDING_HANDLE *
  431. DgCreateBindingHandle (
  432. void
  433. );
  434. extern RPC_CHAR *
  435. AllocateEmptyString (
  436. void
  437. );
  438. extern RPC_CHAR *
  439. DuplicateString (
  440. IN RPC_CHAR PAPI * String
  441. );
  442. #define DuplicateStringPAPI DuplicateString
  443. #define AllocateEmptyStringPAPI AllocateEmptyString
  444. #define DG_EVENT_CALLBACK_COMPLETE 0x9991
  445. #define CO_EVENT_BIND_TO_SERVER 0x9992
  446. // don't use 9993 - it's already used
  447. #define IN_PROXY_IIS_DIRECT_RECV 0x9994
  448. #define HTTP2_DIRECT_RECEIVE 0x9995
  449. #define PLUG_CHANNEL_DIRECT_SEND 0x9996
  450. #define CHANNEL_DATA_ORIGINATOR_DIRECT_SEND 0x9997
  451. #define HTTP2_RESCHEDULE_TIMER 0x9998
  452. #define HTTP2_FLOW_CONTROL_DIRECT_SEND 0x9999
  453. #define HTTP2_WINHTTP_DIRECT_RECV 0x999A
  454. #define HTTP2_WINHTTP_DIRECT_SEND 0x999B
  455. #define HTTP2_ABORT_CONNECTION 0x999C
  456. #define HTTP2_RECYCLE_CHANNEL 0x999D
  457. extern UUID MgmtIf;
  458. extern UUID NullUuid;
  459. typedef void ProcessIOEventFunc(LOADABLE_TRANSPORT *pLoadableTransport,
  460. IN RPC_TRANSPORT_EVENT Event,
  461. IN RPC_STATUS EventStatus,
  462. IN PVOID pEventContext,
  463. IN UINT BufferLength,
  464. IN BUFFER Buffer,
  465. IN PVOID pSourceContext);
  466. BOOL
  467. ProcessIOEventsWrapper(
  468. IN LOADABLE_TRANSPORT *Transport
  469. ) ;
  470. void
  471. ProcessDgClientPacket(
  472. IN DWORD Status,
  473. IN DG_TRANSPORT_ENDPOINT LocalEndpoint,
  474. IN void * PacketHeader,
  475. IN unsigned long PacketLength,
  476. IN DatagramTransportPair *AddressPair
  477. );
  478. void
  479. ProcessDgServerPacket(
  480. IN DWORD Status,
  481. IN DG_TRANSPORT_ENDPOINT LocalEndpoint,
  482. IN void * PacketHeader,
  483. IN unsigned long PacketLength,
  484. IN DatagramTransportPair *AddressPair
  485. );
  486. #endif // __BINDING_HXX__