wine.inf: Add some dll stub dll to the system directory.
[wine/multimedia.git] / dlls / rpcrt4 / rpc_epmap.c
blobf7d01a1a190045f61a453afb354d0263e0e81bd3
1 /*
2 * RPC endpoint mapper
4 * Copyright 2002 Greg Turner
5 * Copyright 2001 Ove Kåven, TransGaming Technologies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * TODO:
22 * - actually do things right
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "winreg.h"
34 #include "rpc.h"
36 #include "wine/debug.h"
38 #include "rpc_binding.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ole);
42 /* The "real" RPC portmapper endpoints that I know of are:
44 * ncadg_ip_udp: 135
45 * ncacn_ip_tcp: 135
46 * ncacn_np: \\pipe\epmapper (?)
47 * ncalrpc: epmapper
49 * If the user's machine ran a DCE RPC daemon, it would
50 * probably be possible to connect to it, but there are many
51 * reasons not to, like:
52 * - the user probably does *not* run one, and probably
53 * shouldn't be forced to run one just for local COM
54 * - very few Unix systems use DCE RPC... if they run a RPC
55 * daemon at all, it's usually Sun RPC
56 * - DCE RPC registrations are persistent and saved on disk,
57 * while MS-RPC registrations are documented as non-persistent
58 * and stored only in RAM, and auto-destroyed when the process
59 * dies (something DCE RPC can't do)
61 * Of course, if the user *did* want to run a DCE RPC daemon anyway,
62 * there would be interoperability advantages, like the possibility
63 * of running a fully functional DCOM server using Wine...
66 /***********************************************************************
67 * RpcEpRegisterA (RPCRT4.@)
69 RPC_STATUS WINAPI RpcEpRegisterA( RPC_IF_HANDLE IfSpec, RPC_BINDING_VECTOR *BindingVector,
70 UUID_VECTOR *UuidVector, unsigned char *Annotation )
72 RPCSS_NP_MESSAGE msg;
73 RPCSS_NP_REPLY reply;
74 char *vardata_payload, *vp;
75 PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
76 unsigned long c;
77 RPC_STATUS rslt = RPC_S_OK;
79 TRACE("(%p,%p,%p,%s)\n", IfSpec, BindingVector, UuidVector, debugstr_a((char*)Annotation));
80 TRACE(" ifid=%s\n", debugstr_guid(&If->InterfaceId.SyntaxGUID));
81 for (c=0; c<BindingVector->Count; c++) {
82 RpcBinding* bind = (RpcBinding*)(BindingVector->BindingH[c]);
83 TRACE(" protseq[%ld]=%s\n", c, debugstr_a(bind->Protseq));
84 TRACE(" endpoint[%ld]=%s\n", c, debugstr_a(bind->Endpoint));
86 if (UuidVector) {
87 for (c=0; c<UuidVector->Count; c++)
88 TRACE(" obj[%ld]=%s\n", c, debugstr_guid(UuidVector->Uuid[c]));
91 /* FIXME: Do something with annotation. */
93 /* construct the message to rpcss */
94 msg.message_type = RPCSS_NP_MESSAGE_TYPEID_REGISTEREPMSG;
95 msg.message.registerepmsg.iface = If->InterfaceId;
96 msg.message.registerepmsg.no_replace = 0;
98 msg.message.registerepmsg.object_count = (UuidVector) ? UuidVector->Count : 0;
99 msg.message.registerepmsg.binding_count = BindingVector->Count;
101 /* calculate vardata payload size */
102 msg.vardata_payload_size = msg.message.registerepmsg.object_count * sizeof(UUID);
103 for (c=0; c < msg.message.registerepmsg.binding_count; c++) {
104 RpcBinding *bind = (RpcBinding *)(BindingVector->BindingH[c]);
105 msg.vardata_payload_size += strlen(bind->Protseq) + 1;
106 msg.vardata_payload_size += strlen(bind->Endpoint) + 1;
109 /* allocate the payload buffer */
110 vp = vardata_payload = LocalAlloc(LPTR, msg.vardata_payload_size);
111 if (!vardata_payload)
112 return RPC_S_OUT_OF_MEMORY;
114 /* populate the payload data */
115 for (c=0; c < msg.message.registerepmsg.object_count; c++) {
116 CopyMemory(vp, UuidVector->Uuid[c], sizeof(UUID));
117 vp += sizeof(UUID);
120 for (c=0; c < msg.message.registerepmsg.binding_count; c++) {
121 RpcBinding *bind = (RpcBinding*)(BindingVector->BindingH[c]);
122 unsigned long pslen = strlen(bind->Protseq) + 1, eplen = strlen(bind->Endpoint) + 1;
123 CopyMemory(vp, bind->Protseq, pslen);
124 vp += pslen;
125 CopyMemory(vp, bind->Endpoint, eplen);
126 vp += eplen;
129 /* send our request */
130 if (!RPCRT4_RPCSSOnDemandCall(&msg, vardata_payload, &reply))
131 rslt = RPC_S_OUT_OF_MEMORY;
133 /* free the payload buffer */
134 LocalFree(vardata_payload);
136 return rslt;
139 /***********************************************************************
140 * RpcEpUnregister (RPCRT4.@)
142 RPC_STATUS WINAPI RpcEpUnregister( RPC_IF_HANDLE IfSpec, RPC_BINDING_VECTOR *BindingVector,
143 UUID_VECTOR *UuidVector )
145 RPCSS_NP_MESSAGE msg;
146 RPCSS_NP_REPLY reply;
147 char *vardata_payload, *vp;
148 PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
149 unsigned long c;
150 RPC_STATUS rslt = RPC_S_OK;
152 TRACE("(%p,%p,%p)\n", IfSpec, BindingVector, UuidVector);
153 TRACE(" ifid=%s\n", debugstr_guid(&If->InterfaceId.SyntaxGUID));
154 for (c=0; c<BindingVector->Count; c++) {
155 RpcBinding* bind = (RpcBinding*)(BindingVector->BindingH[c]);
156 TRACE(" protseq[%ld]=%s\n", c, debugstr_a(bind->Protseq));
157 TRACE(" endpoint[%ld]=%s\n", c, debugstr_a(bind->Endpoint));
159 if (UuidVector) {
160 for (c=0; c<UuidVector->Count; c++)
161 TRACE(" obj[%ld]=%s\n", c, debugstr_guid(UuidVector->Uuid[c]));
164 /* construct the message to rpcss */
165 msg.message_type = RPCSS_NP_MESSAGE_TYPEID_UNREGISTEREPMSG;
166 msg.message.unregisterepmsg.iface = If->InterfaceId;
168 msg.message.unregisterepmsg.object_count = (UuidVector) ? UuidVector->Count : 0;
169 msg.message.unregisterepmsg.binding_count = BindingVector->Count;
171 /* calculate vardata payload size */
172 msg.vardata_payload_size = msg.message.unregisterepmsg.object_count * sizeof(UUID);
173 for (c=0; c < msg.message.unregisterepmsg.binding_count; c++) {
174 RpcBinding *bind = (RpcBinding *)(BindingVector->BindingH[c]);
175 msg.vardata_payload_size += strlen(bind->Protseq) + 1;
176 msg.vardata_payload_size += strlen(bind->Endpoint) + 1;
179 /* allocate the payload buffer */
180 vp = vardata_payload = LocalAlloc(LPTR, msg.vardata_payload_size);
181 if (!vardata_payload)
182 return RPC_S_OUT_OF_MEMORY;
184 /* populate the payload data */
185 for (c=0; c < msg.message.unregisterepmsg.object_count; c++) {
186 CopyMemory(vp, UuidVector->Uuid[c], sizeof(UUID));
187 vp += sizeof(UUID);
190 for (c=0; c < msg.message.unregisterepmsg.binding_count; c++) {
191 RpcBinding *bind = (RpcBinding*)(BindingVector->BindingH[c]);
192 unsigned long pslen = strlen(bind->Protseq) + 1, eplen = strlen(bind->Endpoint) + 1;
193 CopyMemory(vp, bind->Protseq, pslen);
194 vp += pslen;
195 CopyMemory(vp, bind->Endpoint, eplen);
196 vp += eplen;
199 /* send our request */
200 if (!RPCRT4_RPCSSOnDemandCall(&msg, vardata_payload, &reply))
201 rslt = RPC_S_OUT_OF_MEMORY;
203 /* free the payload buffer */
204 LocalFree(vardata_payload);
206 return rslt;
209 /***********************************************************************
210 * RpcEpResolveBinding (RPCRT4.@)
212 RPC_STATUS WINAPI RpcEpResolveBinding( RPC_BINDING_HANDLE Binding, RPC_IF_HANDLE IfSpec )
214 RPCSS_NP_MESSAGE msg;
215 RPCSS_NP_REPLY reply;
216 PRPC_CLIENT_INTERFACE If = (PRPC_CLIENT_INTERFACE)IfSpec;
217 RpcBinding* bind = (RpcBinding*)Binding;
219 TRACE("(%p,%p)\n", Binding, IfSpec);
220 TRACE(" protseq=%s\n", debugstr_a(bind->Protseq));
221 TRACE(" obj=%s\n", debugstr_guid(&bind->ObjectUuid));
222 TRACE(" ifid=%s\n", debugstr_guid(&If->InterfaceId.SyntaxGUID));
224 /* FIXME: totally untested */
226 /* just return for fully bound handles */
227 if (bind->Endpoint && (bind->Endpoint[0] != '\0'))
228 return RPC_S_OK;
230 /* construct the message to rpcss */
231 msg.message_type = RPCSS_NP_MESSAGE_TYPEID_RESOLVEEPMSG;
232 msg.message.resolveepmsg.iface = If->InterfaceId;
233 msg.message.resolveepmsg.object = bind->ObjectUuid;
235 msg.vardata_payload_size = strlen(bind->Protseq) + 1;
237 /* send the message */
238 if (!RPCRT4_RPCSSOnDemandCall(&msg, bind->Protseq, &reply))
239 return RPC_S_OUT_OF_MEMORY;
241 /* empty-string result means not registered */
242 if (reply.as_string[0] == '\0')
243 return EPT_S_NOT_REGISTERED;
245 /* otherwise we fully bind the handle & return RPC_S_OK */
246 return RPCRT4_ResolveBinding(Binding, reply.as_string);