rpcrt4: Add tests for NdrStubForwardingFunction and write a commented out implementation.
[wine] / dlls / 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 "wine/rpcss_shared.h"
25 #include "security.h"
26 #include "wine/list.h"
27
28
29 typedef struct _RpcAuthInfo
30 {
31   LONG refs;
32
33   unsigned long AuthnLevel;
34   unsigned long AuthnSvc;
35   CredHandle cred;
36   TimeStamp exp;
37 } RpcAuthInfo;
38
39 struct protseq_ops;
40
41 typedef struct _RpcConnection
42 {
43   struct _RpcConnection* Next;
44   struct _RpcBinding* Used;
45   BOOL server;
46   LPSTR NetworkAddr;
47   LPSTR Endpoint;
48   const struct protseq_ops *ops;
49   USHORT MaxTransmissionSize;
50   /* The active interface bound to server. */
51   RPC_SYNTAX_IDENTIFIER ActiveInterface;
52   USHORT NextCallId;
53
54   /* authentication */
55   CtxtHandle ctx;
56   TimeStamp exp;
57   ULONG attr;
58   RpcAuthInfo *AuthInfo;
59
60   /* client-only */
61   struct list conn_pool_entry;
62 } RpcConnection;
63
64 struct protseq_ops {
65   const char *name;
66   unsigned char epm_protocols[2]; /* only floors 3 and 4. see http://www.opengroup.org/onlinepubs/9629399/apdxl.htm */
67   RpcConnection *(*alloc)(void);
68   RPC_STATUS (*open_connection)(RpcConnection *conn);
69   HANDLE (*get_connect_wait_handle)(RpcConnection *conn);
70   RPC_STATUS (*handoff)(RpcConnection *old_conn, RpcConnection *new_conn);
71   int (*read)(RpcConnection *conn, void *buffer, unsigned int len);
72   int (*write)(RpcConnection *conn, const void *buffer, unsigned int len);
73   int (*close)(RpcConnection *conn);
74   size_t (*get_top_of_tower)(unsigned char *tower_data, const char *networkaddr, const char *endpoint);
75   RPC_STATUS (*parse_top_of_tower)(const unsigned char *tower_data, size_t tower_size, char **networkaddr, char **endpoint);
76 };
77
78 /* don't know what MS's structure looks like */
79 typedef struct _RpcBinding
80 {
81   LONG refs;
82   struct _RpcBinding* Next;
83   BOOL server;
84   UUID ObjectUuid;
85   LPSTR Protseq;
86   LPSTR NetworkAddr;
87   LPSTR Endpoint;
88   RPC_BLOCKING_FN BlockingFn;
89   ULONG ServerTid;
90   RpcConnection* FromConn;
91
92   /* authentication */
93   RpcAuthInfo *AuthInfo;
94 } RpcBinding;
95
96 LPSTR RPCRT4_strndupA(LPCSTR src, INT len);
97 LPWSTR RPCRT4_strndupW(LPWSTR src, INT len);
98 LPSTR RPCRT4_strdupWtoA(LPWSTR src);
99 LPWSTR RPCRT4_strdupAtoW(LPSTR src);
100 void RPCRT4_strfree(LPSTR src);
101
102 #define RPCRT4_strdupA(x) RPCRT4_strndupA((x),-1)
103 #define RPCRT4_strdupW(x) RPCRT4_strndupW((x),-1)
104
105 ULONG RpcAuthInfo_AddRef(RpcAuthInfo *AuthInfo);
106 ULONG RpcAuthInfo_Release(RpcAuthInfo *AuthInfo);
107
108 RpcConnection *RPCRT4_GetIdleConnection(const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax, LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, RpcAuthInfo* AuthInfo);
109 void RPCRT4_ReleaseIdleConnection(RpcConnection *Connection);
110 RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server, LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCSTR NetworkOptions, RpcAuthInfo* AuthInfo, RpcBinding* Binding);
111 RPC_STATUS RPCRT4_DestroyConnection(RpcConnection* Connection);
112 RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection);
113 RPC_STATUS RPCRT4_CloseConnection(RpcConnection* Connection);
114 RPC_STATUS RPCRT4_SpawnConnection(RpcConnection** Connection, RpcConnection* OldConnection);
115
116 RPC_STATUS RPCRT4_CreateBindingA(RpcBinding** Binding, BOOL server, LPSTR Protseq);
117 RPC_STATUS RPCRT4_CreateBindingW(RpcBinding** Binding, BOOL server, LPWSTR Protseq);
118 RPC_STATUS RPCRT4_CompleteBindingA(RpcBinding* Binding, LPSTR NetworkAddr,  LPSTR Endpoint,  LPSTR NetworkOptions);
119 RPC_STATUS RPCRT4_CompleteBindingW(RpcBinding* Binding, LPWSTR NetworkAddr, LPWSTR Endpoint, LPWSTR NetworkOptions);
120 RPC_STATUS RPCRT4_ResolveBinding(RpcBinding* Binding, LPSTR Endpoint);
121 RPC_STATUS RPCRT4_SetBindingObject(RpcBinding* Binding, UUID* ObjectUuid);
122 RPC_STATUS RPCRT4_MakeBinding(RpcBinding** Binding, RpcConnection* Connection);
123 RPC_STATUS RPCRT4_ExportBinding(RpcBinding** Binding, RpcBinding* OldBinding);
124 RPC_STATUS RPCRT4_DestroyBinding(RpcBinding* Binding);
125 RPC_STATUS RPCRT4_OpenBinding(RpcBinding* Binding, RpcConnection** Connection, PRPC_SYNTAX_IDENTIFIER TransferSyntax, PRPC_SYNTAX_IDENTIFIER InterfaceId);
126 RPC_STATUS RPCRT4_CloseBinding(RpcBinding* Binding, RpcConnection* Connection);
127 BOOL RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg, char *vardata_payload, PRPCSS_NP_REPLY reply);
128 HANDLE RPCRT4_GetMasterMutex(void);
129 HANDLE RPCRT4_RpcssNPConnect(void);
130
131 static inline const char *rpcrt4_conn_get_name(RpcConnection *Connection)
132 {
133   return Connection->ops->name;
134 }
135
136 static inline int rpcrt4_conn_read(RpcConnection *Connection,
137                      void *buffer, unsigned int len)
138 {
139   return Connection->ops->read(Connection, buffer, len);
140 }
141
142 static inline int rpcrt4_conn_write(RpcConnection *Connection,
143                      const void *buffer, unsigned int len)
144 {
145   return Connection->ops->write(Connection, buffer, len);
146 }
147
148 static inline int rpcrt4_conn_close(RpcConnection *Connection)
149 {
150   return Connection->ops->close(Connection);
151 }
152
153 static inline HANDLE rpcrt4_conn_get_wait_object(RpcConnection *Connection)
154 {
155   return Connection->ops->get_connect_wait_handle(Connection);
156 }
157
158 static inline RPC_STATUS rpcrt4_conn_handoff(RpcConnection *old_conn, RpcConnection *new_conn)
159 {
160   return old_conn->ops->handoff(old_conn, new_conn);
161 }
162
163 /* floors 3 and up */
164 RPC_STATUS RpcTransport_GetTopOfTower(unsigned char *tower_data, size_t *tower_size, const char *protseq, const char *networkaddr, const char *endpoint);
165 RPC_STATUS RpcTransport_ParseTopOfTower(const unsigned char *tower_data, size_t tower_size, char **protseq, char **networkaddr, char **endpoint);
166
167 #endif