5aa83079d51e2505881b4642ae3d4ef3ff8eb944
[reactos.git] / reactos / dll / win32 / rpcrt4 / rpc_binding.h
1 /*
2 * RPC binding API
3 *
4 * Copyright 2001 Ove Kåven, TransGaming Technologies
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifndef __WINE_RPC_BINDING_H
22 #define __WINE_RPC_BINDING_H
23
24 #include "rpcndr.h"
25 #include "security.h"
26 #include "wine/list.h"
27
28
29 typedef struct _RpcAuthInfo
30 {
31 LONG refs;
32
33 ULONG AuthnLevel;
34 ULONG AuthnSvc;
35 CredHandle cred;
36 TimeStamp exp;
37 ULONG cbMaxToken;
38 /* the auth identity pointer that the application passed us (freed by application) */
39 RPC_AUTH_IDENTITY_HANDLE *identity;
40 /* our copy of NT auth identity structure, if the authentication service
41 * takes an NT auth identity */
42 SEC_WINNT_AUTH_IDENTITY_W *nt_identity;
43 LPWSTR server_principal_name;
44 } RpcAuthInfo;
45
46 typedef struct _RpcQualityOfService
47 {
48 LONG refs;
49
50 RPC_SECURITY_QOS_V2_W *qos;
51 } RpcQualityOfService;
52
53 struct connection_ops;
54
55 typedef struct _RpcConnection
56 {
57 BOOL server;
58 LPSTR NetworkAddr;
59 LPSTR Endpoint;
60 LPWSTR NetworkOptions;
61 const struct connection_ops *ops;
62 USHORT MaxTransmissionSize;
63
64 /* authentication */
65 CtxtHandle ctx;
66 TimeStamp exp;
67 ULONG attr;
68 RpcAuthInfo *AuthInfo;
69 ULONG encryption_auth_len;
70 ULONG signature_auth_len;
71 RpcQualityOfService *QOS;
72
73 /* client-only */
74 struct list conn_pool_entry;
75 ULONG assoc_group_id; /* association group returned during binding */
76 RPC_ASYNC_STATE *async_state;
77
78 /* server-only */
79 /* The active interface bound to server. */
80 RPC_SYNTAX_IDENTIFIER ActiveInterface;
81 USHORT NextCallId;
82 struct _RpcConnection* Next;
83 struct _RpcBinding *server_binding;
84 } RpcConnection;
85
86 struct connection_ops {
87 const char *name;
88 unsigned char epm_protocols[2]; /* only floors 3 and 4. see http://www.opengroup.org/onlinepubs/9629399/apdxl.htm */
89 RpcConnection *(*alloc)(void);
90 RPC_STATUS (*open_connection_client)(RpcConnection *conn);
91 RPC_STATUS (*handoff)(RpcConnection *old_conn, RpcConnection *new_conn);
92 int (*read)(RpcConnection *conn, void *buffer, unsigned int len);
93 int (*write)(RpcConnection *conn, const void *buffer, unsigned int len);
94 int (*close)(RpcConnection *conn);
95 void (*cancel_call)(RpcConnection *conn);
96 int (*wait_for_incoming_data)(RpcConnection *conn);
97 size_t (*get_top_of_tower)(unsigned char *tower_data, const char *networkaddr, const char *endpoint);
98 RPC_STATUS (*parse_top_of_tower)(const unsigned char *tower_data, size_t tower_size, char **networkaddr, char **endpoint);
99 };
100
101 /* don't know what MS's structure looks like */
102 typedef struct _RpcBinding
103 {
104 LONG refs;
105 struct _RpcBinding* Next;
106 BOOL server;
107 UUID ObjectUuid;
108 LPSTR Protseq;
109 LPSTR NetworkAddr;
110 LPSTR Endpoint;
111 LPWSTR NetworkOptions;
112 RPC_BLOCKING_FN BlockingFn;
113 ULONG ServerTid;
114 RpcConnection* FromConn;
115 struct _RpcAssoc *Assoc;
116
117 /* authentication */
118 RpcAuthInfo *AuthInfo;
119 RpcQualityOfService *QOS;
120 } RpcBinding;
121
122 LPSTR RPCRT4_strndupA(LPCSTR src, INT len);
123 LPWSTR RPCRT4_strndupW(LPCWSTR src, INT len);
124 LPSTR RPCRT4_strdupWtoA(LPCWSTR src);
125 LPWSTR RPCRT4_strdupAtoW(LPCSTR src);
126 void RPCRT4_strfree(LPSTR src);
127
128 #define RPCRT4_strdupA(x) RPCRT4_strndupA((x),-1)
129 #define RPCRT4_strdupW(x) RPCRT4_strndupW((x),-1)
130
131 ULONG RpcAuthInfo_AddRef(RpcAuthInfo *AuthInfo);
132 ULONG RpcAuthInfo_Release(RpcAuthInfo *AuthInfo);
133 BOOL RpcAuthInfo_IsEqual(const RpcAuthInfo *AuthInfo1, const RpcAuthInfo *AuthInfo2);
134 ULONG RpcQualityOfService_AddRef(RpcQualityOfService *qos);
135 ULONG RpcQualityOfService_Release(RpcQualityOfService *qos);
136 BOOL RpcQualityOfService_IsEqual(const RpcQualityOfService *qos1, const RpcQualityOfService *qos2);
137
138 RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server, LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAuthInfo* AuthInfo, RpcQualityOfService *QOS);
139 RPC_STATUS RPCRT4_DestroyConnection(RpcConnection* Connection);
140 RPC_STATUS RPCRT4_OpenClientConnection(RpcConnection* Connection);
141 RPC_STATUS RPCRT4_CloseConnection(RpcConnection* Connection);
142
143 RPC_STATUS RPCRT4_ResolveBinding(RpcBinding* Binding, LPCSTR Endpoint);
144 RPC_STATUS RPCRT4_SetBindingObject(RpcBinding* Binding, const UUID* ObjectUuid);
145 RPC_STATUS RPCRT4_MakeBinding(RpcBinding** Binding, RpcConnection* Connection);
146 void RPCRT4_AddRefBinding(RpcBinding* Binding);
147 RPC_STATUS RPCRT4_ReleaseBinding(RpcBinding* Binding);
148 RPC_STATUS RPCRT4_OpenBinding(RpcBinding* Binding, RpcConnection** Connection,
149 const RPC_SYNTAX_IDENTIFIER *TransferSyntax, const RPC_SYNTAX_IDENTIFIER *InterfaceId);
150 RPC_STATUS RPCRT4_CloseBinding(RpcBinding* Binding, RpcConnection* Connection);
151
152 static inline const char *rpcrt4_conn_get_name(const RpcConnection *Connection)
153 {
154 return Connection->ops->name;
155 }
156
157 static inline int rpcrt4_conn_read(RpcConnection *Connection,
158 void *buffer, unsigned int len)
159 {
160 return Connection->ops->read(Connection, buffer, len);
161 }
162
163 static inline int rpcrt4_conn_write(RpcConnection *Connection,
164 const void *buffer, unsigned int len)
165 {
166 return Connection->ops->write(Connection, buffer, len);
167 }
168
169 static inline int rpcrt4_conn_close(RpcConnection *Connection)
170 {
171 return Connection->ops->close(Connection);
172 }
173
174 static inline void rpcrt4_conn_cancel_call(RpcConnection *Connection)
175 {
176 Connection->ops->cancel_call(Connection);
177 }
178
179 static inline RPC_STATUS rpcrt4_conn_handoff(RpcConnection *old_conn, RpcConnection *new_conn)
180 {
181 return old_conn->ops->handoff(old_conn, new_conn);
182 }
183
184 /* floors 3 and up */
185 RPC_STATUS RpcTransport_GetTopOfTower(unsigned char *tower_data, size_t *tower_size, const char *protseq, const char *networkaddr, const char *endpoint);
186 RPC_STATUS RpcTransport_ParseTopOfTower(const unsigned char *tower_data, size_t tower_size, char **protseq, char **networkaddr, char **endpoint);
187
188 void RPCRT4_SetThreadCurrentConnection(RpcConnection *Connection);
189 void RPCRT4_SetThreadCurrentCallHandle(RpcBinding *Binding);
190 RpcBinding *RPCRT4_GetThreadCurrentCallHandle(void);
191 void RPCRT4_PushThreadContextHandle(NDR_SCONTEXT SContext);
192 void RPCRT4_RemoveThreadContextHandle(NDR_SCONTEXT SContext);
193 NDR_SCONTEXT RPCRT4_PopThreadContextHandle(void);
194
195 #endif