ReactOS 0.4.15-dev-8417-gb6b82fe
rpc_assoc.h File Reference
#include "rpc_binding.h"
#include "wine/list.h"
Include dependency graph for rpc_assoc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _RpcAssoc
 

Typedefs

typedef struct _RpcAssoc RpcAssoc
 

Functions

RPC_STATUS RPCRT4_GetAssociation (LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAssoc **assoc) DECLSPEC_HIDDEN
 
RPC_STATUS RpcAssoc_GetClientConnection (RpcAssoc *assoc, const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax, RpcAuthInfo *AuthInfo, RpcQualityOfService *QOS, LPCWSTR CookieAuth, RpcConnection **Connection, BOOL *from_cache) DECLSPEC_HIDDEN
 
void RpcAssoc_ReleaseIdleConnection (RpcAssoc *assoc, RpcConnection *Connection) DECLSPEC_HIDDEN
 
ULONG RpcAssoc_Release (RpcAssoc *assoc) DECLSPEC_HIDDEN
 
RPC_STATUS RpcServerAssoc_GetAssociation (LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, ULONG assoc_gid, RpcAssoc **assoc_out) DECLSPEC_HIDDEN
 
RPC_STATUS RpcServerAssoc_AllocateContextHandle (RpcAssoc *assoc, void *CtxGuard, NDR_SCONTEXT *SContext) DECLSPEC_HIDDEN
 
RPC_STATUS RpcServerAssoc_FindContextHandle (RpcAssoc *assoc, const UUID *uuid, void *CtxGuard, ULONG Flags, NDR_SCONTEXT *SContext) DECLSPEC_HIDDEN
 
RPC_STATUS RpcServerAssoc_UpdateContextHandle (RpcAssoc *assoc, NDR_SCONTEXT SContext, void *CtxGuard, NDR_RUNDOWN rundown_routine) DECLSPEC_HIDDEN
 
unsigned int RpcServerAssoc_ReleaseContextHandle (RpcAssoc *assoc, NDR_SCONTEXT SContext, BOOL release_lock) DECLSPEC_HIDDEN
 
void RpcContextHandle_GetUuid (NDR_SCONTEXT SContext, UUID *uuid) DECLSPEC_HIDDEN
 
BOOL RpcContextHandle_IsGuardCorrect (NDR_SCONTEXT SContext, void *CtxGuard) DECLSPEC_HIDDEN
 
void RpcAssoc_ConnectionReleased (RpcAssoc *assoc) DECLSPEC_HIDDEN
 

Typedef Documentation

◆ RpcAssoc

Function Documentation

◆ RpcAssoc_ConnectionReleased()

void RpcAssoc_ConnectionReleased ( RpcAssoc assoc)

Definition at line 447 of file rpc_assoc.c.

448{
450 return;
451
452 TRACE("Last %p connection released\n", assoc);
453 assoc->assoc_group_id = 0;
454}
#define InterlockedDecrement
Definition: armddk.h:52
#define TRACE(s)
Definition: solgame.cpp:4
LONG connection_cnt
Definition: rpc_assoc.h:46
ULONG assoc_group_id
Definition: rpc_assoc.h:38

Referenced by RPCRT4_ReleaseConnection().

◆ RpcAssoc_GetClientConnection()

RPC_STATUS RpcAssoc_GetClientConnection ( RpcAssoc assoc,
const RPC_SYNTAX_IDENTIFIER InterfaceId,
const RPC_SYNTAX_IDENTIFIER TransferSyntax,
RpcAuthInfo AuthInfo,
RpcQualityOfService QOS,
LPCWSTR  CookieAuth,
RpcConnection **  Connection,
BOOL from_cache 
)

Definition at line 390 of file rpc_assoc.c.

395{
396 RpcConnection *NewConnection;
398
399 *Connection = RpcAssoc_GetIdleConnection(assoc, InterfaceId, TransferSyntax, AuthInfo, QOS);
400 if (*Connection) {
401 TRACE("return idle connection %p for association %p\n", *Connection, assoc);
402 if (from_cache) *from_cache = TRUE;
403 return RPC_S_OK;
404 }
405
406 /* create a new connection */
407 status = RPCRT4_CreateConnection(&NewConnection, FALSE /* is this a server connection? */,
408 assoc->Protseq, assoc->NetworkAddr,
409 assoc->Endpoint, assoc->NetworkOptions,
410 AuthInfo, QOS, CookieAuth);
411 if (status != RPC_S_OK)
412 return status;
413
414 NewConnection->assoc = assoc;
415 status = RPCRT4_OpenClientConnection(NewConnection);
416 if (status != RPC_S_OK)
417 {
418 RPCRT4_ReleaseConnection(NewConnection);
419 return status;
420 }
421
422 status = RpcAssoc_BindConnection(assoc, NewConnection, InterfaceId, TransferSyntax);
423 if (status != RPC_S_OK)
424 {
425 RPCRT4_ReleaseConnection(NewConnection);
426 return status;
427 }
428
430
431 TRACE("return new connection %p for association %p\n", *Connection, assoc);
432 *Connection = NewConnection;
433 if (from_cache) *from_cache = FALSE;
434 return RPC_S_OK;
435}
#define InterlockedIncrement
Definition: armddk.h:53
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static RpcConnection * RpcAssoc_GetIdleConnection(RpcAssoc *assoc, const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax, const RpcAuthInfo *AuthInfo, const RpcQualityOfService *QOS)
Definition: rpc_assoc.c:364
static RPC_STATUS RpcAssoc_BindConnection(const RpcAssoc *assoc, RpcConnection *conn, const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax)
Definition: rpc_assoc.c:229
RPC_STATUS RPCRT4_OpenClientConnection(RpcConnection *Connection) DECLSPEC_HIDDEN
void RPCRT4_ReleaseConnection(RpcConnection *Connection) DECLSPEC_HIDDEN
RPC_STATUS RPCRT4_CreateConnection(RpcConnection **Connection, BOOL server, LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAuthInfo *AuthInfo, RpcQualityOfService *QOS, LPCWSTR CookieAuth) DECLSPEC_HIDDEN
#define RPC_S_OK
Definition: rpcnterr.h:22
long RPC_STATUS
Definition: rpc.h:52
LPSTR Protseq
Definition: rpc_assoc.h:32
LPWSTR NetworkOptions
Definition: rpc_assoc.h:35
LPSTR Endpoint
Definition: rpc_assoc.h:34
LPSTR NetworkAddr
Definition: rpc_assoc.h:33
struct _RpcAssoc * assoc
Definition: rpc_binding.h:88
Definition: ps.c:97

Referenced by RPCRT4_OpenBinding().

◆ RpcAssoc_Release()

ULONG RpcAssoc_Release ( RpcAssoc assoc)

Definition at line 187 of file rpc_assoc.c.

188{
189 ULONG refs;
190
192 refs = --assoc->refs;
193 if (!refs)
194 list_remove(&assoc->entry);
196
197 if (!refs)
198 {
199 RpcConnection *Connection, *cursor2;
200 RpcContextHandle *context_handle, *context_handle_cursor;
201
202 TRACE("destroying assoc %p\n", assoc);
203
204 LIST_FOR_EACH_ENTRY_SAFE(Connection, cursor2, &assoc->free_connection_pool, RpcConnection, conn_pool_entry)
205 {
206 list_remove(&Connection->conn_pool_entry);
207 RPCRT4_ReleaseConnection(Connection);
208 }
209
210 LIST_FOR_EACH_ENTRY_SAFE(context_handle, context_handle_cursor, &assoc->context_handle_list, RpcContextHandle, entry)
211 RpcContextHandle_Destroy(context_handle);
212
214 HeapFree(GetProcessHeap(), 0, assoc->Endpoint);
215 HeapFree(GetProcessHeap(), 0, assoc->NetworkAddr);
216 HeapFree(GetProcessHeap(), 0, assoc->Protseq);
217
218 assoc->cs.DebugInfo->Spare[0] = 0;
219 DeleteCriticalSection(&assoc->cs);
220
221 HeapFree(GetProcessHeap(), 0, assoc);
222 }
223
224 return refs;
225}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
uint32_t entry
Definition: isohybrid.c:63
static void RpcContextHandle_Destroy(RpcContextHandle *context_handle)
Definition: rpc_assoc.c:547
static CRITICAL_SECTION assoc_list_cs
Definition: rpc_assoc.c:37
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
DWORD_PTR Spare[8/sizeof(DWORD_PTR)]
Definition: winbase.h:887
PCRITICAL_SECTION_DEBUG DebugInfo
Definition: winbase.h:894
struct list free_connection_pool
Definition: rpc_assoc.h:45
LONG refs
Definition: rpc_assoc.h:30
struct list context_handle_list
Definition: rpc_assoc.h:49
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
struct list entry
Definition: rpc_assoc.h:29
struct list conn_pool_entry
Definition: rpc_binding.h:85
uint32_t ULONG
Definition: typedefs.h:59
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by RpcBindingReset(), RPCRT4_ReleaseBinding(), and RPCRT4_ResolveBinding().

◆ RpcAssoc_ReleaseIdleConnection()

void RpcAssoc_ReleaseIdleConnection ( RpcAssoc assoc,
RpcConnection Connection 
)

Definition at line 437 of file rpc_assoc.c.

438{
439 assert(!Connection->server);
440 Connection->async_state = NULL;
441 EnterCriticalSection(&assoc->cs);
442 if (!assoc->assoc_group_id) assoc->assoc_group_id = Connection->assoc_group_id;
444 LeaveCriticalSection(&assoc->cs);
445}
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
#define NULL
Definition: types.h:112
#define assert(x)
Definition: debug.h:53
ULONG assoc_group_id
Definition: rpc_binding.h:86
RPC_ASYNC_STATE * async_state
Definition: rpc_binding.h:87

Referenced by RPCRT4_CloseBinding().

◆ RpcContextHandle_GetUuid()

void RpcContextHandle_GetUuid ( NDR_SCONTEXT  SContext,
UUID uuid 
)

Definition at line 541 of file rpc_assoc.c.

542{
543 RpcContextHandle *context_handle = (RpcContextHandle *)SContext;
544 *uuid = context_handle->uuid;
545}
Definition: msctf.idl:550

Referenced by NDRSContextMarshall2().

◆ RpcContextHandle_IsGuardCorrect()

BOOL RpcContextHandle_IsGuardCorrect ( NDR_SCONTEXT  SContext,
void CtxGuard 
)

Definition at line 481 of file rpc_assoc.c.

482{
483 RpcContextHandle *context_handle = (RpcContextHandle *)SContext;
484 return context_handle->ctx_guard == CtxGuard;
485}
void * ctx_guard
Definition: rpc_assoc.c:56

Referenced by NDRSContextMarshall2(), RpcServerAssoc_FindContextHandle(), and RpcServerAssoc_UpdateContextHandle().

◆ RPCRT4_GetAssociation()

RPC_STATUS RPCRT4_GetAssociation ( LPCSTR  Protseq,
LPCSTR  NetworkAddr,
LPCSTR  Endpoint,
LPCWSTR  NetworkOptions,
RpcAssoc **  assoc 
)

Definition at line 98 of file rpc_assoc.c.

101{
102 RpcAssoc *assoc;
104
107 {
108 if (!strcmp(Protseq, assoc->Protseq) &&
109 !strcmp(NetworkAddr, assoc->NetworkAddr) &&
110 !strcmp(Endpoint, assoc->Endpoint) &&
111 compare_networkoptions(NetworkOptions, assoc->NetworkOptions))
112 {
113 assoc->refs++;
114 *assoc_out = assoc;
116 TRACE("using existing assoc %p\n", assoc);
117 return RPC_S_OK;
118 }
119 }
120
121 status = RpcAssoc_Alloc(Protseq, NetworkAddr, Endpoint, NetworkOptions, &assoc);
122 if (status != RPC_S_OK)
123 {
125 return status;
126 }
128 *assoc_out = assoc;
129
131
132 TRACE("new assoc %p\n", assoc);
133
134 return RPC_S_OK;
135}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static BOOL compare_networkoptions(LPCWSTR opts1, LPCWSTR opts2)
Definition: rpc_assoc.c:89
static RPC_STATUS RpcAssoc_Alloc(LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAssoc **assoc_out)
Definition: rpc_assoc.c:64
static struct list client_assoc_list
Definition: rpc_assoc.c:46
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198

Referenced by RPCRT4_CompleteBindingA(), RPCRT4_CompleteBindingW(), and RPCRT4_ResolveBinding().

◆ RpcServerAssoc_AllocateContextHandle()

RPC_STATUS RpcServerAssoc_AllocateContextHandle ( RpcAssoc assoc,
void CtxGuard,
NDR_SCONTEXT SContext 
)

Definition at line 456 of file rpc_assoc.c.

458{
459 RpcContextHandle *context_handle;
460
461 context_handle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*context_handle));
462 if (!context_handle)
463 return RPC_S_OUT_OF_MEMORY;
464
465 context_handle->ctx_guard = CtxGuard;
466 RtlInitializeResource(&context_handle->rw_lock);
467 context_handle->refs = 1;
468
469 /* lock here to mirror unmarshall, so we don't need to special-case the
470 * freeing of a non-marshalled context handle */
471 RtlAcquireResourceExclusive(&context_handle->rw_lock, TRUE);
472
473 EnterCriticalSection(&assoc->cs);
474 list_add_tail(&assoc->context_handle_list, &context_handle->entry);
475 LeaveCriticalSection(&assoc->cs);
476
477 *SContext = (NDR_SCONTEXT)context_handle;
478 return RPC_S_OK;
479}
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
struct _NDR_SCONTEXT * NDR_SCONTEXT
#define RPC_S_OUT_OF_MEMORY
Definition: rpcnterr.h:24
struct list entry
Definition: rpc_assoc.c:53
RTL_RWLOCK rw_lock
Definition: rpc_assoc.c:58
unsigned int refs
Definition: rpc_assoc.c:59

Referenced by NDRSContextUnmarshall2().

◆ RpcServerAssoc_FindContextHandle()

RPC_STATUS RpcServerAssoc_FindContextHandle ( RpcAssoc assoc,
const UUID uuid,
void CtxGuard,
ULONG  Flags,
NDR_SCONTEXT SContext 
)

Definition at line 487 of file rpc_assoc.c.

489{
490 RpcContextHandle *context_handle;
491
492 EnterCriticalSection(&assoc->cs);
494 {
495 if (RpcContextHandle_IsGuardCorrect((NDR_SCONTEXT)context_handle, CtxGuard) &&
496 !memcmp(&context_handle->uuid, uuid, sizeof(*uuid)))
497 {
498 *SContext = (NDR_SCONTEXT)context_handle;
499 if (context_handle->refs++)
500 {
501 LeaveCriticalSection(&assoc->cs);
502 TRACE("found %p\n", context_handle);
503 RtlAcquireResourceExclusive(&context_handle->rw_lock, TRUE);
504 return RPC_S_OK;
505 }
506 }
507 }
508 LeaveCriticalSection(&assoc->cs);
509
510 ERR("no context handle found for uuid %s, guard %p\n",
511 debugstr_guid(uuid), CtxGuard);
513}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ERR(fmt,...)
Definition: precomp.h:57
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define debugstr_guid
Definition: kernel32.h:35
BOOL RpcContextHandle_IsGuardCorrect(NDR_SCONTEXT SContext, void *CtxGuard)
Definition: rpc_assoc.c:481

Referenced by NDRSContextUnmarshall2().

◆ RpcServerAssoc_GetAssociation()

RPC_STATUS RpcServerAssoc_GetAssociation ( LPCSTR  Protseq,
LPCSTR  NetworkAddr,
LPCSTR  Endpoint,
LPCWSTR  NetworkOptions,
ULONG  assoc_gid,
RpcAssoc **  assoc_out 
)

Definition at line 137 of file rpc_assoc.c.

141{
142 RpcAssoc *assoc;
144
146 if (assoc_gid)
147 {
149 {
150 /* FIXME: NetworkAddr shouldn't be NULL */
151 if (assoc->assoc_group_id == assoc_gid &&
152 !strcmp(Protseq, assoc->Protseq) &&
153 (!NetworkAddr || !assoc->NetworkAddr || !strcmp(NetworkAddr, assoc->NetworkAddr)) &&
154 !strcmp(Endpoint, assoc->Endpoint) &&
155 ((!assoc->NetworkOptions == !NetworkOptions) &&
156 (!NetworkOptions || !wcscmp(NetworkOptions, assoc->NetworkOptions))))
157 {
158 assoc->refs++;
159 *assoc_out = assoc;
161 TRACE("using existing assoc %p\n", assoc);
162 return RPC_S_OK;
163 }
164 }
165 *assoc_out = NULL;
168 }
169
170 status = RpcAssoc_Alloc(Protseq, NetworkAddr, Endpoint, NetworkOptions, &assoc);
171 if (status != RPC_S_OK)
172 {
174 return status;
175 }
178 *assoc_out = assoc;
179
181
182 TRACE("new assoc %p\n", assoc);
183
184 return RPC_S_OK;
185}
static LONG last_assoc_group_id
Definition: rpc_assoc.c:49
static struct list server_assoc_list
Definition: rpc_assoc.c:47
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define RPC_S_NO_CONTEXT_AVAILABLE
Definition: winerror.h:1073

Referenced by process_bind_packet_no_send().

◆ RpcServerAssoc_ReleaseContextHandle()

unsigned int RpcServerAssoc_ReleaseContextHandle ( RpcAssoc assoc,
NDR_SCONTEXT  SContext,
BOOL  release_lock 
)

Definition at line 563 of file rpc_assoc.c.

564{
565 RpcContextHandle *context_handle = (RpcContextHandle *)SContext;
566 unsigned int refs;
567
568 if (release_lock)
569 RtlReleaseResource(&context_handle->rw_lock);
570
571 EnterCriticalSection(&assoc->cs);
572 refs = --context_handle->refs;
573 if (!refs)
574 list_remove(&context_handle->entry);
575 LeaveCriticalSection(&assoc->cs);
576
577 if (!refs)
578 RpcContextHandle_Destroy(context_handle);
579
580 return refs;
581}
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)

Referenced by NDRSContextMarshall2(), and process_request_packet().

◆ RpcServerAssoc_UpdateContextHandle()

RPC_STATUS RpcServerAssoc_UpdateContextHandle ( RpcAssoc assoc,
NDR_SCONTEXT  SContext,
void CtxGuard,
NDR_RUNDOWN  rundown_routine 
)

Definition at line 515 of file rpc_assoc.c.

519{
520 RpcContextHandle *context_handle = (RpcContextHandle *)SContext;
522
523 if (!RpcContextHandle_IsGuardCorrect((NDR_SCONTEXT)context_handle, CtxGuard))
525
526 EnterCriticalSection(&assoc->cs);
527 if (UuidIsNil(&context_handle->uuid, &status))
528 {
529 /* add a ref for the data being valid */
530 context_handle->refs++;
531 UuidCreate(&context_handle->uuid);
532 context_handle->rundown_routine = rundown_routine;
533 TRACE("allocated uuid %s for context handle %p\n",
534 debugstr_guid(&context_handle->uuid), context_handle);
535 }
536 LeaveCriticalSection(&assoc->cs);
537
538 return RPC_S_OK;
539}
int WINAPI UuidIsNil(UUID *Uuid, RPC_STATUS *Status)
Definition: rpcrt4_main.c:268
RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
Definition: rpcrt4_main.c:305

Referenced by NDRSContextMarshall2().