4 * Copyright 2001 Ove Kåven, TransGaming Technologies
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 #include "rpc_binding.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ole);
42 LPSTR RPCRT4_strndupA(LPSTR src, INT slen)
46 if (!src) return NULL;
47 if (slen == -1) slen = strlen(src);
49 s = HeapAlloc(GetProcessHeap(), 0, len+1);
55 LPSTR RPCRT4_strdupWtoA(LPWSTR src)
59 if (!src) return NULL;
60 len = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL);
61 s = HeapAlloc(GetProcessHeap(), 0, len);
62 WideCharToMultiByte(CP_ACP, 0, src, -1, s, len, NULL, NULL);
66 LPWSTR RPCRT4_strdupAtoW(LPSTR src)
70 if (!src) return NULL;
71 len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
72 s = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
73 MultiByteToWideChar(CP_ACP, 0, src, -1, s, len);
77 LPWSTR RPCRT4_strndupW(LPWSTR src, INT slen)
81 if (!src) return NULL;
82 if (slen == -1) slen = strlenW(src);
84 s = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
85 memcpy(s, src, len*sizeof(WCHAR));
90 void RPCRT4_strfree(LPSTR src)
92 if (src) HeapFree(GetProcessHeap(), 0, src);
95 RPC_STATUS RPCRT4_CreateBindingA(RpcBinding** Binding, BOOL server, LPSTR Protseq)
97 RpcBinding* NewBinding;
99 NewBinding = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcBinding));
100 NewBinding->refs = 1;
101 NewBinding->server = server;
102 NewBinding->Protseq = RPCRT4_strdupA(Protseq);
104 TRACE("binding: %p\n", NewBinding);
105 *Binding = NewBinding;
110 RPC_STATUS RPCRT4_CreateBindingW(RpcBinding** Binding, BOOL server, LPWSTR Protseq)
112 RpcBinding* NewBinding;
114 TRACE(" (*Binding == ^%p, server == %s, Protseq == \"%s\")\n", *Binding, server ? "Yes" : "No", debugstr_w(Protseq));
116 ERR("!RpcBinding?\n");
117 *((char *)0) = 0; /* we will crash below anyhow... */
120 NewBinding = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcBinding));
121 NewBinding->refs = 1;
122 NewBinding->server = server;
123 NewBinding->Protseq = RPCRT4_strdupWtoA(Protseq);
125 TRACE("binding: %p\n", NewBinding);
126 *Binding = NewBinding;
131 RPC_STATUS RPCRT4_CompleteBindingA(RpcBinding* Binding, LPSTR NetworkAddr, LPSTR Endpoint, LPSTR NetworkOptions)
134 TRACE(" (RpcBinding == ^%p, NetworkAddr == \"%s\", EndPoint == \"%s\", NetworkOptions == \"%s\")\n", Binding, NetworkAddr, Endpoint, NetworkOptions);
136 RPCRT4_strfree(Binding->NetworkAddr);
137 Binding->NetworkAddr = RPCRT4_strdupA(NetworkAddr);
138 RPCRT4_strfree(Binding->Endpoint);
139 if (Binding->Endpoint) {
140 Binding->Endpoint = RPCRT4_strdupA(Endpoint);
142 Binding->Endpoint = RPCRT4_strdupA("");
148 RPC_STATUS RPCRT4_CompleteBindingW(RpcBinding* Binding, LPWSTR NetworkAddr, LPWSTR Endpoint, LPWSTR NetworkOptions)
151 TRACE(" (RpcBinding == ^%p, NetworkAddr == \"%s\", EndPoint == \"%s\", NetworkOptions == \"%s\")\n", Binding,
152 debugstr_w(NetworkAddr), debugstr_w(Endpoint), debugstr_w(NetworkOptions));
154 RPCRT4_strfree(Binding->NetworkAddr);
155 Binding->NetworkAddr = RPCRT4_strdupWtoA(NetworkAddr);
156 RPCRT4_strfree(Binding->Endpoint);
157 if (Binding->Endpoint) {
158 Binding->Endpoint = RPCRT4_strdupWtoA(Endpoint);
160 Binding->Endpoint = RPCRT4_strdupA("");
166 RPC_STATUS RPCRT4_ResolveBinding(RpcBinding* Binding, LPSTR Endpoint)
168 RPCRT4_strfree(Binding->Endpoint);
169 Binding->Endpoint = RPCRT4_strdupA(Endpoint);
174 RPC_STATUS RPCRT4_SetBindingObject(RpcBinding* Binding, UUID* ObjectUuid)
176 TRACE(" (*RpcBinding == ^%p, UUID == %s)\n", Binding, debugstr_guid(ObjectUuid));
177 if (ObjectUuid) memcpy(&Binding->ObjectUuid, ObjectUuid, sizeof(UUID));
178 else UuidCreateNil(&Binding->ObjectUuid);
182 RPC_STATUS RPCRT4_SpawnBinding(RpcBinding** Binding, RpcBinding* OldBinding)
184 RpcBinding* NewBinding;
186 TRACE(" (*RpcBinding == ^%p, OldBinding == ^%p)\n", *Binding, OldBinding);
189 /* we will crash below anyhow... */
193 NewBinding = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcBinding));
194 NewBinding->refs = 1;
195 NewBinding->server = OldBinding->server;
196 NewBinding->Protseq = RPCRT4_strdupA(OldBinding->Protseq);
197 NewBinding->NetworkAddr = RPCRT4_strdupA(OldBinding->NetworkAddr);
198 NewBinding->Endpoint = RPCRT4_strdupA(OldBinding->Endpoint);
199 /* because of the way named pipes work, we'll transfer the connected pipe
200 * to the child, then reopen the server binding to continue listening */
201 NewBinding->conn = OldBinding->conn;
202 NewBinding->ovl = OldBinding->ovl;
203 OldBinding->conn = 0;
204 memset(&OldBinding->ovl, 0, sizeof(OldBinding->ovl));
205 *Binding = NewBinding;
206 RPCRT4_OpenBinding(OldBinding);
211 RPC_STATUS RPCRT4_ExportBinding(RpcBinding** Binding, RpcBinding* OldBinding)
213 InterlockedIncrement(&OldBinding->refs);
214 *Binding = OldBinding;
218 RPC_STATUS RPCRT4_DestroyBinding(RpcBinding* Binding)
220 if (InterlockedDecrement(&Binding->refs))
223 TRACE("binding: %p\n", Binding);
224 RPCRT4_CloseBinding(Binding);
225 RPCRT4_strfree(Binding->Endpoint);
226 RPCRT4_strfree(Binding->NetworkAddr);
227 RPCRT4_strfree(Binding->Protseq);
228 HeapFree(GetProcessHeap(), 0, Binding);
232 RPC_STATUS RPCRT4_OpenBinding(RpcBinding* Binding)
234 TRACE(" (Binding == ^%p)\n", Binding);
235 if (!Binding->conn) {
236 if (Binding->server) { /* server */
237 /* protseq=ncalrpc: supposed to use NT LPC ports,
238 * but we'll implement it with named pipes for now */
239 if (strcmp(Binding->Protseq, "ncalrpc") == 0) {
240 static LPSTR prefix = "\\\\.\\pipe\\lrpc\\";
242 pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Binding->Endpoint) + 1);
243 strcat(strcpy(pname, prefix), Binding->Endpoint);
244 TRACE("listening on %s\n", pname);
245 Binding->conn = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
246 0, PIPE_UNLIMITED_INSTANCES, 0, 0, 5000, NULL);
247 HeapFree(GetProcessHeap(), 0, pname);
248 memset(&Binding->ovl, 0, sizeof(Binding->ovl));
249 Binding->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
250 if (!ConnectNamedPipe(Binding->conn, &Binding->ovl)) {
251 DWORD err = GetLastError();
252 if (err == ERROR_PIPE_CONNECTED) {
253 SetEvent(Binding->ovl.hEvent);
259 /* protseq=ncacn_np: named pipes */
260 else if (strcmp(Binding->Protseq, "ncacn_np") == 0) {
261 static LPSTR prefix = "\\\\.";
263 pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Binding->Endpoint) + 1);
264 strcat(strcpy(pname, prefix), Binding->Endpoint);
265 TRACE("listening on %s\n", pname);
266 Binding->conn = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
267 0, PIPE_UNLIMITED_INSTANCES, 0, 0, 5000, NULL);
268 HeapFree(GetProcessHeap(), 0, pname);
269 memset(&Binding->ovl, 0, sizeof(Binding->ovl));
270 Binding->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
271 if (!ConnectNamedPipe(Binding->conn, &Binding->ovl)) {
272 DWORD err = GetLastError();
273 if (err == ERROR_PIPE_CONNECTED) {
274 SetEvent(Binding->ovl.hEvent);
281 ERR("protseq %s not supported\n", Binding->Protseq);
282 return RPC_S_PROTSEQ_NOT_SUPPORTED;
286 /* protseq=ncalrpc: supposed to use NT LPC ports,
287 * but we'll implement it with named pipes for now */
288 if (strcmp(Binding->Protseq, "ncalrpc") == 0) {
289 static LPSTR prefix = "\\\\.\\pipe\\lrpc\\";
294 pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Binding->Endpoint) + 1);
295 strcat(strcpy(pname, prefix), Binding->Endpoint);
296 TRACE("connecting to %s\n", pname);
298 if (WaitNamedPipeA(pname, NMPWAIT_WAIT_FOREVER)) {
299 conn = CreateFileA(pname, GENERIC_READ|GENERIC_WRITE, 0, NULL,
300 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
301 if (conn != INVALID_HANDLE_VALUE) break;
302 err = GetLastError();
303 if (err == ERROR_PIPE_BUSY) continue;
304 TRACE("connection failed, error=%lx\n", err);
305 HeapFree(GetProcessHeap(), 0, pname);
309 err = GetLastError();
310 TRACE("connection failed, error=%lx\n", err);
311 HeapFree(GetProcessHeap(), 0, pname);
317 HeapFree(GetProcessHeap(), 0, pname);
318 memset(&Binding->ovl, 0, sizeof(Binding->ovl));
319 Binding->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
320 Binding->conn = conn;
322 /* protseq=ncacn_np: named pipes */
323 else if (strcmp(Binding->Protseq, "ncacn_np") == 0) {
324 static LPSTR prefix = "\\\\.";
329 pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Binding->Endpoint) + 1);
330 strcat(strcpy(pname, prefix), Binding->Endpoint);
331 TRACE("connecting to %s\n", pname);
332 conn = CreateFileA(pname, GENERIC_READ|GENERIC_WRITE, 0, NULL,
333 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
334 if (conn == INVALID_HANDLE_VALUE) {
335 err = GetLastError();
336 /* we don't need to handle ERROR_PIPE_BUSY here,
337 * the doc says that it is returned to the app */
338 TRACE("connection failed, error=%lx\n", err);
339 HeapFree(GetProcessHeap(), 0, pname);
344 HeapFree(GetProcessHeap(), 0, pname);
345 memset(&Binding->ovl, 0, sizeof(Binding->ovl));
346 Binding->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
347 Binding->conn = conn;
350 ERR("protseq %s not supported\n", Binding->Protseq);
351 return RPC_S_PROTSEQ_NOT_SUPPORTED;
358 RPC_STATUS RPCRT4_CloseBinding(RpcBinding* Binding)
360 TRACE(" (Binding == ^%p)\n", Binding);
362 CancelIo(Binding->conn);
363 CloseHandle(Binding->conn);
366 if (Binding->ovl.hEvent) {
367 CloseHandle(Binding->ovl.hEvent);
368 Binding->ovl.hEvent = 0;
373 /* utility functions for string composing and parsing */
374 static unsigned RPCRT4_strcopyA(LPSTR data, LPCSTR src)
376 unsigned len = strlen(src);
377 memcpy(data, src, len*sizeof(CHAR));
381 static unsigned RPCRT4_strcopyW(LPWSTR data, LPCWSTR src)
383 unsigned len = strlenW(src);
384 memcpy(data, src, len*sizeof(WCHAR));
388 static LPSTR RPCRT4_strconcatA(LPSTR dst, LPCSTR src)
390 DWORD len = strlen(dst), slen = strlen(src);
391 LPSTR ndst = HeapReAlloc(GetProcessHeap(), 0, dst, (len+slen+2)*sizeof(CHAR));
392 if (!ndst) HeapFree(GetProcessHeap(), 0, dst);
394 memcpy(ndst+len+1, src, slen*sizeof(CHAR));
395 ndst[len+slen+1] = 0;
399 static LPWSTR RPCRT4_strconcatW(LPWSTR dst, LPCWSTR src)
401 DWORD len = strlenW(dst), slen = strlenW(src);
402 LPWSTR ndst = HeapReAlloc(GetProcessHeap(), 0, dst, (len+slen+2)*sizeof(WCHAR));
403 if (!ndst) HeapFree(GetProcessHeap(), 0, dst);
405 memcpy(ndst+len+1, src, slen*sizeof(WCHAR));
406 ndst[len+slen+1] = 0;
411 /***********************************************************************
412 * RpcStringBindingComposeA (RPCRT4.@)
414 RPC_STATUS WINAPI RpcStringBindingComposeA( LPSTR ObjUuid, LPSTR Protseq,
415 LPSTR NetworkAddr, LPSTR Endpoint,
416 LPSTR Options, LPSTR* StringBinding )
421 TRACE( "(%s,%s,%s,%s,%s,%p)\n",
422 debugstr_a( ObjUuid ), debugstr_a( Protseq ),
423 debugstr_a( NetworkAddr ), debugstr_a( Endpoint ),
424 debugstr_a( Options ), StringBinding );
426 if (ObjUuid && *ObjUuid) len += strlen(ObjUuid) + 1;
427 if (Protseq && *Protseq) len += strlen(Protseq) + 1;
428 if (NetworkAddr && *NetworkAddr) len += strlen(NetworkAddr);
429 if (Endpoint && *Endpoint) len += strlen(Endpoint) + 2;
430 if (Options && *Options) len += strlen(Options) + 2;
432 data = HeapAlloc(GetProcessHeap(), 0, len);
433 *StringBinding = data;
435 if (ObjUuid && *ObjUuid) {
436 data += RPCRT4_strcopyA(data, ObjUuid);
439 if (Protseq && *Protseq) {
440 data += RPCRT4_strcopyA(data, Protseq);
443 if (NetworkAddr && *NetworkAddr) {
444 data += RPCRT4_strcopyA(data, NetworkAddr);
446 if ((Endpoint && *Endpoint) ||
447 (Options && *Options)) {
449 if (Endpoint && *Endpoint) {
450 data += RPCRT4_strcopyA(data, Endpoint);
451 if (Options && *Options) *data++ = ',';
453 if (Options && *Options) {
454 data += RPCRT4_strcopyA(data, Options);
463 /***********************************************************************
464 * RpcStringBindingComposeW (RPCRT4.@)
466 RPC_STATUS WINAPI RpcStringBindingComposeW( LPWSTR ObjUuid, LPWSTR Protseq,
467 LPWSTR NetworkAddr, LPWSTR Endpoint,
468 LPWSTR Options, LPWSTR* StringBinding )
473 TRACE("(%s,%s,%s,%s,%s,%p)\n",
474 debugstr_w( ObjUuid ), debugstr_w( Protseq ),
475 debugstr_w( NetworkAddr ), debugstr_w( Endpoint ),
476 debugstr_w( Options ), StringBinding);
478 if (ObjUuid && *ObjUuid) len += strlenW(ObjUuid) + 1;
479 if (Protseq && *Protseq) len += strlenW(Protseq) + 1;
480 if (NetworkAddr && *NetworkAddr) len += strlenW(NetworkAddr);
481 if (Endpoint && *Endpoint) len += strlenW(Endpoint) + 2;
482 if (Options && *Options) len += strlenW(Options) + 2;
484 data = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
485 *StringBinding = data;
487 if (ObjUuid && *ObjUuid) {
488 data += RPCRT4_strcopyW(data, ObjUuid);
491 if (Protseq && *Protseq) {
492 data += RPCRT4_strcopyW(data, Protseq);
495 if (NetworkAddr && *NetworkAddr) {
496 data += RPCRT4_strcopyW(data, NetworkAddr);
498 if ((Endpoint && *Endpoint) ||
499 (Options && *Options)) {
501 if (Endpoint && *Endpoint) {
502 data += RPCRT4_strcopyW(data, Endpoint);
503 if (Options && *Options) *data++ = ',';
505 if (Options && *Options) {
506 data += RPCRT4_strcopyW(data, Options);
516 /***********************************************************************
517 * RpcStringBindingParseA (RPCRT4.@)
519 RPC_STATUS WINAPI RpcStringBindingParseA( LPSTR StringBinding, LPSTR *ObjUuid,
520 LPSTR *Protseq, LPSTR *NetworkAddr,
521 LPSTR *Endpoint, LPSTR *Options)
524 static const char ep_opt[] = "endpoint=";
526 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_a(StringBinding),
527 ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
529 if (ObjUuid) *ObjUuid = NULL;
530 if (Protseq) *Protseq = NULL;
531 if (NetworkAddr) *NetworkAddr = NULL;
532 if (Endpoint) *Endpoint = NULL;
533 if (Options) *Options = NULL;
535 data = StringBinding;
537 next = strchr(data, '@');
539 if (ObjUuid) *ObjUuid = RPCRT4_strndupA(data, next - data);
543 next = strchr(data, ':');
545 if (Protseq) *Protseq = RPCRT4_strndupA(data, next - data);
549 next = strchr(data, '[');
553 if (NetworkAddr) *NetworkAddr = RPCRT4_strndupA(data, next - data);
555 close = strchr(data, ']');
556 if (!close) goto fail;
558 /* tokenize options */
559 while (data < close) {
560 next = strchr(data, ',');
561 if (!next || next > close) next = close;
562 /* FIXME: this is kind of inefficient */
563 opt = RPCRT4_strndupA(data, next - data);
567 next = strchr(opt, '=');
569 /* not an option, must be an endpoint */
570 if (*Endpoint) goto fail;
574 if (strncmp(opt, ep_opt, strlen(ep_opt)) == 0) {
575 /* endpoint option */
576 if (*Endpoint) goto fail;
577 *Endpoint = RPCRT4_strdupA(next+1);
578 HeapFree(GetProcessHeap(), 0, opt);
583 /* FIXME: this is kind of inefficient */
584 *Options = RPCRT4_strconcatA(*Options, opt);
585 HeapFree(GetProcessHeap(), 0, opt);
593 if (*data) goto fail;
595 else if (NetworkAddr) *NetworkAddr = RPCRT4_strdupA(data);
599 if (ObjUuid) RpcStringFreeA(ObjUuid);
600 if (Protseq) RpcStringFreeA(Protseq);
601 if (NetworkAddr) RpcStringFreeA(NetworkAddr);
602 if (Endpoint) RpcStringFreeA(Endpoint);
603 if (Options) RpcStringFreeA(Options);
604 return RPC_S_INVALID_STRING_BINDING;
607 /***********************************************************************
608 * RpcStringBindingParseW (RPCRT4.@)
610 RPC_STATUS WINAPI RpcStringBindingParseW( LPWSTR StringBinding, LPWSTR *ObjUuid,
611 LPWSTR *Protseq, LPWSTR *NetworkAddr,
612 LPWSTR *Endpoint, LPWSTR *Options)
615 static const WCHAR ep_opt[] = {'e','n','d','p','o','i','n','t','=',0};
617 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_w(StringBinding),
618 ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
620 if (ObjUuid) *ObjUuid = NULL;
621 if (Protseq) *Protseq = NULL;
622 if (NetworkAddr) *NetworkAddr = NULL;
623 if (Endpoint) *Endpoint = NULL;
624 if (Options) *Options = NULL;
626 data = StringBinding;
628 next = strchrW(data, '@');
630 if (ObjUuid) *ObjUuid = RPCRT4_strndupW(data, next - data);
634 next = strchrW(data, ':');
636 if (Protseq) *Protseq = RPCRT4_strndupW(data, next - data);
640 next = strchrW(data, '[');
644 if (NetworkAddr) *NetworkAddr = RPCRT4_strndupW(data, next - data);
646 close = strchrW(data, ']');
647 if (!close) goto fail;
649 /* tokenize options */
650 while (data < close) {
651 next = strchrW(data, ',');
652 if (!next || next > close) next = close;
653 /* FIXME: this is kind of inefficient */
654 opt = RPCRT4_strndupW(data, next - data);
658 next = strchrW(opt, '=');
660 /* not an option, must be an endpoint */
661 if (*Endpoint) goto fail;
665 if (strncmpW(opt, ep_opt, strlenW(ep_opt)) == 0) {
666 /* endpoint option */
667 if (*Endpoint) goto fail;
668 *Endpoint = RPCRT4_strdupW(next+1);
669 HeapFree(GetProcessHeap(), 0, opt);
674 /* FIXME: this is kind of inefficient */
675 *Options = RPCRT4_strconcatW(*Options, opt);
676 HeapFree(GetProcessHeap(), 0, opt);
684 if (*data) goto fail;
686 else if (NetworkAddr) *NetworkAddr = RPCRT4_strdupW(data);
690 if (ObjUuid) RpcStringFreeW(ObjUuid);
691 if (Protseq) RpcStringFreeW(Protseq);
692 if (NetworkAddr) RpcStringFreeW(NetworkAddr);
693 if (Endpoint) RpcStringFreeW(Endpoint);
694 if (Options) RpcStringFreeW(Options);
695 return RPC_S_INVALID_STRING_BINDING;
698 /***********************************************************************
699 * RpcBindingFree (RPCRT4.@)
701 RPC_STATUS WINAPI RpcBindingFree( RPC_BINDING_HANDLE* Binding )
704 TRACE("(%p) = %p\n", Binding, *Binding);
705 status = RPCRT4_DestroyBinding(*Binding);
706 if (status == RPC_S_OK) *Binding = 0;
710 /***********************************************************************
711 * RpcBindingVectorFree (RPCRT4.@)
713 RPC_STATUS WINAPI RpcBindingVectorFree( RPC_BINDING_VECTOR** BindingVector )
718 TRACE("(%p)\n", BindingVector);
719 for (c=0; c<(*BindingVector)->Count; c++) {
720 status = RpcBindingFree(&(*BindingVector)->BindingH[c]);
722 HeapFree(GetProcessHeap(), 0, *BindingVector);
723 *BindingVector = NULL;
727 /***********************************************************************
728 * RpcBindingInqObject (RPCRT4.@)
730 RPC_STATUS WINAPI RpcBindingInqObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
732 RpcBinding* bind = (RpcBinding*)Binding;
734 TRACE("(%p,%p) = %s\n", Binding, ObjectUuid, debugstr_guid(&bind->ObjectUuid));
735 memcpy(ObjectUuid, &bind->ObjectUuid, sizeof(UUID));
739 /***********************************************************************
740 * RpcBindingSetObject (RPCRT4.@)
742 RPC_STATUS WINAPI RpcBindingSetObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
744 RpcBinding* bind = (RpcBinding*)Binding;
746 TRACE("(%p,%s)\n", Binding, debugstr_guid(ObjectUuid));
747 if (bind->server) return RPC_S_WRONG_KIND_OF_BINDING;
748 return RPCRT4_SetBindingObject(Binding, ObjectUuid);
751 /***********************************************************************
752 * RpcBindingFromStringBindingA (RPCRT4.@)
754 RPC_STATUS WINAPI RpcBindingFromStringBindingA( LPSTR StringBinding, RPC_BINDING_HANDLE* Binding )
757 RpcBinding* bind = NULL;
758 LPSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
761 TRACE("(%s,%p)\n", debugstr_a(StringBinding), Binding);
763 ret = RpcStringBindingParseA(StringBinding, &ObjectUuid, &Protseq,
764 &NetworkAddr, &Endpoint, &Options);
765 if (ret != RPC_S_OK) return ret;
767 ret = UuidFromStringA(ObjectUuid, &Uuid);
770 ret = RPCRT4_CreateBindingA(&bind, FALSE, Protseq);
772 ret = RPCRT4_SetBindingObject(bind, &Uuid);
774 ret = RPCRT4_CompleteBindingA(bind, NetworkAddr, Endpoint, Options);
776 RpcStringFreeA(&Options);
777 RpcStringFreeA(&Endpoint);
778 RpcStringFreeA(&NetworkAddr);
779 RpcStringFreeA(&Protseq);
780 RpcStringFreeA(&ObjectUuid);
782 if (ret == RPC_S_OK) *Binding = (RPC_BINDING_HANDLE)bind;
783 else RPCRT4_DestroyBinding(bind);
788 /***********************************************************************
789 * RpcBindingFromStringBindingW (RPCRT4.@)
791 RPC_STATUS WINAPI RpcBindingFromStringBindingW( LPWSTR StringBinding, RPC_BINDING_HANDLE* Binding )
794 RpcBinding* bind = NULL;
795 LPWSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
798 TRACE("(%s,%p)\n", debugstr_w(StringBinding), Binding);
800 ret = RpcStringBindingParseW(StringBinding, &ObjectUuid, &Protseq,
801 &NetworkAddr, &Endpoint, &Options);
802 if (ret != RPC_S_OK) return ret;
804 ret = UuidFromStringW(ObjectUuid, &Uuid);
807 ret = RPCRT4_CreateBindingW(&bind, FALSE, Protseq);
809 ret = RPCRT4_SetBindingObject(bind, &Uuid);
811 ret = RPCRT4_CompleteBindingW(bind, NetworkAddr, Endpoint, Options);
813 RpcStringFreeW(&Options);
814 RpcStringFreeW(&Endpoint);
815 RpcStringFreeW(&NetworkAddr);
816 RpcStringFreeW(&Protseq);
817 RpcStringFreeW(&ObjectUuid);
819 if (ret == RPC_S_OK) *Binding = (RPC_BINDING_HANDLE)bind;
820 else RPCRT4_DestroyBinding(bind);
825 /***********************************************************************
826 * RpcBindingToStringBindingA (RPCRT4.@)
828 RPC_STATUS WINAPI RpcBindingToStringBindingA( RPC_BINDING_HANDLE Binding, LPSTR* StringBinding )
831 RpcBinding* bind = (RpcBinding*)Binding;
834 TRACE("(%p,%p)\n", Binding, StringBinding);
836 ret = UuidToStringA(&bind->ObjectUuid, &ObjectUuid);
837 if (ret != RPC_S_OK) return ret;
839 ret = RpcStringBindingComposeA(ObjectUuid, bind->Protseq, bind->NetworkAddr,
840 bind->Endpoint, NULL, StringBinding);
842 RpcStringFreeA(&ObjectUuid);
847 /***********************************************************************
848 * RpcBindingToStringBindingW (RPCRT4.@)
850 RPC_STATUS WINAPI RpcBindingToStringBindingW( RPC_BINDING_HANDLE Binding, LPWSTR* StringBinding )
854 TRACE("(%p,%p)\n", Binding, StringBinding);
855 ret = RpcBindingToStringBindingA(Binding, &str);
856 *StringBinding = RPCRT4_strdupAtoW(str);
857 RpcStringFreeA(&str);
861 /***********************************************************************
862 * I_RpcBindingSetAsync (RPCRT4.@)
864 * Exists in win9x and winNT, but with different number of arguments
865 * (9x version has 3 arguments, NT has 2).
867 RPC_STATUS WINAPI I_RpcBindingSetAsync( RPC_BINDING_HANDLE Binding, RPC_BLOCKING_FN BlockingFn, unsigned long ServerTid )
869 RpcBinding* bind = (RpcBinding*)Binding;
871 TRACE( "(%p,%p,%ld): stub\n", Binding, BlockingFn, ServerTid );
873 bind->BlockingFn = BlockingFn;
874 bind->ServerTid = ServerTid;