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 NewBinding = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcBinding));
115 NewBinding->refs = 1;
116 NewBinding->server = server;
117 NewBinding->Protseq = RPCRT4_strdupWtoA(Protseq);
119 TRACE("binding: %p\n", NewBinding);
120 *Binding = NewBinding;
125 RPC_STATUS RPCRT4_CompleteBindingA(RpcBinding* Binding, LPSTR NetworkAddr, LPSTR Endpoint, LPSTR NetworkOptions)
127 RPCRT4_strfree(Binding->NetworkAddr);
128 Binding->NetworkAddr = RPCRT4_strdupA(NetworkAddr);
129 RPCRT4_strfree(Binding->Endpoint);
130 Binding->Endpoint = RPCRT4_strdupA(Endpoint);
135 RPC_STATUS RPCRT4_CompleteBindingW(RpcBinding* Binding, LPWSTR NetworkAddr, LPWSTR Endpoint, LPWSTR NetworkOptions)
137 RPCRT4_strfree(Binding->NetworkAddr);
138 Binding->NetworkAddr = RPCRT4_strdupWtoA(NetworkAddr);
139 RPCRT4_strfree(Binding->Endpoint);
140 Binding->Endpoint = RPCRT4_strdupWtoA(Endpoint);
145 RPC_STATUS RPCRT4_ResolveBinding(RpcBinding* Binding, LPSTR Endpoint)
147 RPCRT4_strfree(Binding->Endpoint);
148 Binding->Endpoint = RPCRT4_strdupA(Endpoint);
153 RPC_STATUS RPCRT4_SetBindingObject(RpcBinding* Binding, UUID* ObjectUuid)
155 if (ObjectUuid) memcpy(&Binding->ObjectUuid, ObjectUuid, sizeof(UUID));
156 else UuidCreateNil(&Binding->ObjectUuid);
160 RPC_STATUS RPCRT4_SpawnBinding(RpcBinding** Binding, RpcBinding* OldBinding)
162 RpcBinding* NewBinding;
164 NewBinding = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcBinding));
165 NewBinding->refs = 1;
166 NewBinding->server = OldBinding->server;
167 NewBinding->Protseq = RPCRT4_strdupA(OldBinding->Protseq);
168 NewBinding->NetworkAddr = RPCRT4_strdupA(OldBinding->NetworkAddr);
169 NewBinding->Endpoint = RPCRT4_strdupA(OldBinding->Endpoint);
170 /* because of the way named pipes work, we'll transfer the connected pipe
171 * to the child, then reopen the server binding to continue listening */
172 NewBinding->conn = OldBinding->conn;
173 NewBinding->ovl = OldBinding->ovl;
174 OldBinding->conn = 0;
175 memset(&OldBinding->ovl, 0, sizeof(OldBinding->ovl));
176 *Binding = NewBinding;
177 RPCRT4_OpenBinding(OldBinding);
182 RPC_STATUS RPCRT4_ExportBinding(RpcBinding** Binding, RpcBinding* OldBinding)
184 InterlockedIncrement(&OldBinding->refs);
185 *Binding = OldBinding;
189 RPC_STATUS RPCRT4_DestroyBinding(RpcBinding* Binding)
191 if (InterlockedDecrement(&Binding->refs))
194 TRACE("binding: %p\n", Binding);
195 RPCRT4_CloseBinding(Binding);
196 RPCRT4_strfree(Binding->Endpoint);
197 RPCRT4_strfree(Binding->NetworkAddr);
198 RPCRT4_strfree(Binding->Protseq);
199 HeapFree(GetProcessHeap(), 0, Binding);
203 RPC_STATUS RPCRT4_OpenBinding(RpcBinding* Binding)
205 if (!Binding->conn) {
206 if (Binding->server) { /* server */
207 /* protseq=ncalrpc: supposed to use NT LPC ports,
208 * but we'll implement it with named pipes for now */
209 if (strcmp(Binding->Protseq, "ncalrpc") == 0) {
210 static LPSTR prefix = "\\\\.\\pipe\\lrpc\\";
212 pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Binding->Endpoint) + 1);
213 strcat(strcpy(pname, prefix), Binding->Endpoint);
214 TRACE("listening on %s\n", pname);
215 Binding->conn = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
216 0, PIPE_UNLIMITED_INSTANCES, 0, 0, 5000, NULL);
217 HeapFree(GetProcessHeap(), 0, pname);
218 memset(&Binding->ovl, 0, sizeof(Binding->ovl));
219 Binding->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
220 if (!ConnectNamedPipe(Binding->conn, &Binding->ovl)) {
221 DWORD err = GetLastError();
222 if (err == ERROR_PIPE_CONNECTED) {
223 SetEvent(Binding->ovl.hEvent);
229 /* protseq=ncacn_np: named pipes */
230 else if (strcmp(Binding->Protseq, "ncacn_np") == 0) {
231 static LPSTR prefix = "\\\\.";
233 pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Binding->Endpoint) + 1);
234 strcat(strcpy(pname, prefix), Binding->Endpoint);
235 TRACE("listening on %s\n", pname);
236 Binding->conn = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
237 0, PIPE_UNLIMITED_INSTANCES, 0, 0, 5000, NULL);
238 HeapFree(GetProcessHeap(), 0, pname);
239 memset(&Binding->ovl, 0, sizeof(Binding->ovl));
240 Binding->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
241 if (!ConnectNamedPipe(Binding->conn, &Binding->ovl)) {
242 DWORD err = GetLastError();
243 if (err == ERROR_PIPE_CONNECTED) {
244 SetEvent(Binding->ovl.hEvent);
251 ERR("protseq %s not supported\n", Binding->Protseq);
252 return RPC_S_PROTSEQ_NOT_SUPPORTED;
256 /* protseq=ncalrpc: supposed to use NT LPC ports,
257 * but we'll implement it with named pipes for now */
258 if (strcmp(Binding->Protseq, "ncalrpc") == 0) {
259 static LPSTR prefix = "\\\\.\\pipe\\lrpc\\";
264 pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Binding->Endpoint) + 1);
265 strcat(strcpy(pname, prefix), Binding->Endpoint);
266 TRACE("connecting to %s\n", pname);
268 if (WaitNamedPipeA(pname, NMPWAIT_WAIT_FOREVER)) {
269 conn = CreateFileA(pname, GENERIC_READ|GENERIC_WRITE, 0, NULL,
270 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
271 if (conn != INVALID_HANDLE_VALUE) break;
272 err = GetLastError();
273 if (err == ERROR_PIPE_BUSY) continue;
274 TRACE("connection failed, error=%lx\n", err);
275 HeapFree(GetProcessHeap(), 0, pname);
279 err = GetLastError();
280 TRACE("connection failed, error=%lx\n", err);
281 HeapFree(GetProcessHeap(), 0, pname);
287 HeapFree(GetProcessHeap(), 0, pname);
288 memset(&Binding->ovl, 0, sizeof(Binding->ovl));
289 Binding->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
290 Binding->conn = conn;
292 /* protseq=ncacn_np: named pipes */
293 else if (strcmp(Binding->Protseq, "ncacn_np") == 0) {
294 static LPSTR prefix = "\\\\.";
299 pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Binding->Endpoint) + 1);
300 strcat(strcpy(pname, prefix), Binding->Endpoint);
301 TRACE("connecting to %s\n", pname);
302 conn = CreateFileA(pname, GENERIC_READ|GENERIC_WRITE, 0, NULL,
303 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
304 if (conn == INVALID_HANDLE_VALUE) {
305 err = GetLastError();
306 /* we don't need to handle ERROR_PIPE_BUSY here,
307 * the doc says that it is returned to the app */
308 TRACE("connection failed, error=%lx\n", err);
309 HeapFree(GetProcessHeap(), 0, pname);
314 HeapFree(GetProcessHeap(), 0, pname);
315 memset(&Binding->ovl, 0, sizeof(Binding->ovl));
316 Binding->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
317 Binding->conn = conn;
320 ERR("protseq %s not supported\n", Binding->Protseq);
321 return RPC_S_PROTSEQ_NOT_SUPPORTED;
328 RPC_STATUS RPCRT4_CloseBinding(RpcBinding* Binding)
331 CancelIo(Binding->conn);
332 CloseHandle(Binding->conn);
335 if (Binding->ovl.hEvent) {
336 CloseHandle(Binding->ovl.hEvent);
337 Binding->ovl.hEvent = 0;
342 /* utility functions for string composing and parsing */
343 static unsigned RPCRT4_strcopyA(LPSTR data, LPCSTR src)
345 unsigned len = strlen(src);
346 memcpy(data, src, len*sizeof(CHAR));
350 static unsigned RPCRT4_strcopyW(LPWSTR data, LPCWSTR src)
352 unsigned len = strlenW(src);
353 memcpy(data, src, len*sizeof(WCHAR));
357 static LPSTR RPCRT4_strconcatA(LPSTR dst, LPCSTR src)
359 DWORD len = strlen(dst), slen = strlen(src);
360 LPSTR ndst = HeapReAlloc(GetProcessHeap(), 0, dst, (len+slen+2)*sizeof(CHAR));
361 if (!ndst) HeapFree(GetProcessHeap(), 0, dst);
363 memcpy(ndst+len+1, src, slen*sizeof(CHAR));
364 ndst[len+slen+1] = 0;
368 static LPWSTR RPCRT4_strconcatW(LPWSTR dst, LPCWSTR src)
370 DWORD len = strlenW(dst), slen = strlenW(src);
371 LPWSTR ndst = HeapReAlloc(GetProcessHeap(), 0, dst, (len+slen+2)*sizeof(WCHAR));
372 if (!ndst) HeapFree(GetProcessHeap(), 0, dst);
374 memcpy(ndst+len+1, src, slen*sizeof(WCHAR));
375 ndst[len+slen+1] = 0;
380 /***********************************************************************
381 * RpcStringBindingComposeA (RPCRT4.@)
383 RPC_STATUS WINAPI RpcStringBindingComposeA( LPSTR ObjUuid, LPSTR Protseq,
384 LPSTR NetworkAddr, LPSTR Endpoint,
385 LPSTR Options, LPSTR* StringBinding )
390 TRACE( "(%s,%s,%s,%s,%s,%p)\n",
391 debugstr_a( ObjUuid ), debugstr_a( Protseq ),
392 debugstr_a( NetworkAddr ), debugstr_a( Endpoint ),
393 debugstr_a( Options ), StringBinding );
395 if (ObjUuid && *ObjUuid) len += strlen(ObjUuid) + 1;
396 if (Protseq && *Protseq) len += strlen(Protseq) + 1;
397 if (NetworkAddr && *NetworkAddr) len += strlen(NetworkAddr);
398 if (Endpoint && *Endpoint) len += strlen(Endpoint) + 2;
399 if (Options && *Options) len += strlen(Options) + 2;
401 data = HeapAlloc(GetProcessHeap(), 0, len);
402 *StringBinding = data;
404 if (ObjUuid && *ObjUuid) {
405 data += RPCRT4_strcopyA(data, ObjUuid);
408 if (Protseq && *Protseq) {
409 data += RPCRT4_strcopyA(data, Protseq);
412 if (NetworkAddr && *NetworkAddr) {
413 data += RPCRT4_strcopyA(data, NetworkAddr);
415 if ((Endpoint && *Endpoint) ||
416 (Options && *Options)) {
418 if (Endpoint && *Endpoint) {
419 data += RPCRT4_strcopyA(data, Endpoint);
420 if (Options && *Options) *data++ = ',';
422 if (Options && *Options) {
423 data += RPCRT4_strcopyA(data, Options);
432 /***********************************************************************
433 * RpcStringBindingComposeW (RPCRT4.@)
435 RPC_STATUS WINAPI RpcStringBindingComposeW( LPWSTR ObjUuid, LPWSTR Protseq,
436 LPWSTR NetworkAddr, LPWSTR Endpoint,
437 LPWSTR Options, LPWSTR* StringBinding )
442 TRACE("(%s,%s,%s,%s,%s,%p)\n",
443 debugstr_w( ObjUuid ), debugstr_w( Protseq ),
444 debugstr_w( NetworkAddr ), debugstr_w( Endpoint ),
445 debugstr_w( Options ), StringBinding);
447 if (ObjUuid && *ObjUuid) len += strlenW(ObjUuid) + 1;
448 if (Protseq && *Protseq) len += strlenW(Protseq) + 1;
449 if (NetworkAddr && *NetworkAddr) len += strlenW(NetworkAddr);
450 if (Endpoint && *Endpoint) len += strlenW(Endpoint) + 2;
451 if (Options && *Options) len += strlenW(Options) + 2;
453 data = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
454 *StringBinding = data;
456 if (ObjUuid && *ObjUuid) {
457 data += RPCRT4_strcopyW(data, ObjUuid);
460 if (Protseq && *Protseq) {
461 data += RPCRT4_strcopyW(data, Protseq);
464 if (NetworkAddr && *NetworkAddr) {
465 data += RPCRT4_strcopyW(data, NetworkAddr);
467 if ((Endpoint && *Endpoint) ||
468 (Options && *Options)) {
470 if (Endpoint && *Endpoint) {
471 data += RPCRT4_strcopyW(data, Endpoint);
472 if (Options && *Options) *data++ = ',';
474 if (Options && *Options) {
475 data += RPCRT4_strcopyW(data, Options);
485 /***********************************************************************
486 * RpcStringBindingParseA (RPCRT4.@)
488 RPC_STATUS WINAPI RpcStringBindingParseA( LPSTR StringBinding, LPSTR *ObjUuid,
489 LPSTR *Protseq, LPSTR *NetworkAddr,
490 LPSTR *Endpoint, LPSTR *Options)
493 static const char ep_opt[] = "endpoint=";
495 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_a(StringBinding),
496 ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
498 if (ObjUuid) *ObjUuid = NULL;
499 if (Protseq) *Protseq = NULL;
500 if (NetworkAddr) *NetworkAddr = NULL;
501 if (Endpoint) *Endpoint = NULL;
502 if (Options) *Options = NULL;
504 data = StringBinding;
506 next = strchr(data, '@');
508 if (ObjUuid) *ObjUuid = RPCRT4_strndupA(data, next - data);
512 next = strchr(data, ':');
514 if (Protseq) *Protseq = RPCRT4_strndupA(data, next - data);
518 next = strchr(data, '[');
522 if (NetworkAddr) *NetworkAddr = RPCRT4_strndupA(data, next - data);
524 close = strchr(data, ']');
525 if (!close) goto fail;
527 /* tokenize options */
528 while (data < close) {
529 next = strchr(data, ',');
530 if (!next || next > close) next = close;
531 /* FIXME: this is kind of inefficient */
532 opt = RPCRT4_strndupA(data, next - data);
536 next = strchr(opt, '=');
538 /* not an option, must be an endpoint */
539 if (*Endpoint) goto fail;
543 if (strncmp(opt, ep_opt, strlen(ep_opt)) == 0) {
544 /* endpoint option */
545 if (*Endpoint) goto fail;
546 *Endpoint = RPCRT4_strdupA(next+1);
547 HeapFree(GetProcessHeap(), 0, opt);
552 /* FIXME: this is kind of inefficient */
553 *Options = RPCRT4_strconcatA(*Options, opt);
554 HeapFree(GetProcessHeap(), 0, opt);
562 if (*data) goto fail;
564 else if (NetworkAddr) *NetworkAddr = RPCRT4_strdupA(data);
568 if (ObjUuid) RpcStringFreeA(ObjUuid);
569 if (Protseq) RpcStringFreeA(Protseq);
570 if (NetworkAddr) RpcStringFreeA(NetworkAddr);
571 if (Endpoint) RpcStringFreeA(Endpoint);
572 if (Options) RpcStringFreeA(Options);
573 return RPC_S_INVALID_STRING_BINDING;
576 /***********************************************************************
577 * RpcStringBindingParseW (RPCRT4.@)
579 RPC_STATUS WINAPI RpcStringBindingParseW( LPWSTR StringBinding, LPWSTR *ObjUuid,
580 LPWSTR *Protseq, LPWSTR *NetworkAddr,
581 LPWSTR *Endpoint, LPWSTR *Options)
584 static const WCHAR ep_opt[] = {'e','n','d','p','o','i','n','t','=',0};
586 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_w(StringBinding),
587 ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
589 if (ObjUuid) *ObjUuid = NULL;
590 if (Protseq) *Protseq = NULL;
591 if (NetworkAddr) *NetworkAddr = NULL;
592 if (Endpoint) *Endpoint = NULL;
593 if (Options) *Options = NULL;
595 data = StringBinding;
597 next = strchrW(data, '@');
599 if (ObjUuid) *ObjUuid = RPCRT4_strndupW(data, next - data);
603 next = strchrW(data, ':');
605 if (Protseq) *Protseq = RPCRT4_strndupW(data, next - data);
609 next = strchrW(data, '[');
613 if (NetworkAddr) *NetworkAddr = RPCRT4_strndupW(data, next - data);
615 close = strchrW(data, ']');
616 if (!close) goto fail;
618 /* tokenize options */
619 while (data < close) {
620 next = strchrW(data, ',');
621 if (!next || next > close) next = close;
622 /* FIXME: this is kind of inefficient */
623 opt = RPCRT4_strndupW(data, next - data);
627 next = strchrW(opt, '=');
629 /* not an option, must be an endpoint */
630 if (*Endpoint) goto fail;
634 if (strncmpW(opt, ep_opt, strlenW(ep_opt)) == 0) {
635 /* endpoint option */
636 if (*Endpoint) goto fail;
637 *Endpoint = RPCRT4_strdupW(next+1);
638 HeapFree(GetProcessHeap(), 0, opt);
643 /* FIXME: this is kind of inefficient */
644 *Options = RPCRT4_strconcatW(*Options, opt);
645 HeapFree(GetProcessHeap(), 0, opt);
653 if (*data) goto fail;
655 else if (NetworkAddr) *NetworkAddr = RPCRT4_strdupW(data);
659 if (ObjUuid) RpcStringFreeW(ObjUuid);
660 if (Protseq) RpcStringFreeW(Protseq);
661 if (NetworkAddr) RpcStringFreeW(NetworkAddr);
662 if (Endpoint) RpcStringFreeW(Endpoint);
663 if (Options) RpcStringFreeW(Options);
664 return RPC_S_INVALID_STRING_BINDING;
667 /***********************************************************************
668 * RpcBindingFree (RPCRT4.@)
670 RPC_STATUS WINAPI RpcBindingFree( RPC_BINDING_HANDLE* Binding )
673 TRACE("(%p) = %p\n", Binding, *Binding);
674 status = RPCRT4_DestroyBinding(*Binding);
675 if (status == RPC_S_OK) *Binding = 0;
679 /***********************************************************************
680 * RpcBindingVectorFree (RPCRT4.@)
682 RPC_STATUS WINAPI RpcBindingVectorFree( RPC_BINDING_VECTOR** BindingVector )
687 TRACE("(%p)\n", BindingVector);
688 for (c=0; c<(*BindingVector)->Count; c++) {
689 status = RpcBindingFree(&(*BindingVector)->BindingH[c]);
691 HeapFree(GetProcessHeap(), 0, *BindingVector);
692 *BindingVector = NULL;
696 /***********************************************************************
697 * RpcBindingInqObject (RPCRT4.@)
699 RPC_STATUS WINAPI RpcBindingInqObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
701 RpcBinding* bind = (RpcBinding*)Binding;
703 TRACE("(%p,%p) = %s\n", Binding, ObjectUuid, debugstr_guid(&bind->ObjectUuid));
704 memcpy(ObjectUuid, &bind->ObjectUuid, sizeof(UUID));
708 /***********************************************************************
709 * RpcBindingSetObject (RPCRT4.@)
711 RPC_STATUS WINAPI RpcBindingSetObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
713 RpcBinding* bind = (RpcBinding*)Binding;
715 TRACE("(%p,%s)\n", Binding, debugstr_guid(ObjectUuid));
716 if (bind->server) return RPC_S_WRONG_KIND_OF_BINDING;
717 return RPCRT4_SetBindingObject(Binding, ObjectUuid);
720 /***********************************************************************
721 * RpcBindingFromStringBindingA (RPCRT4.@)
723 RPC_STATUS WINAPI RpcBindingFromStringBindingA( LPSTR StringBinding, RPC_BINDING_HANDLE* Binding )
726 RpcBinding* bind = NULL;
727 LPSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
730 TRACE("(%s,%p)\n", debugstr_a(StringBinding), Binding);
732 ret = RpcStringBindingParseA(StringBinding, &ObjectUuid, &Protseq,
733 &NetworkAddr, &Endpoint, &Options);
734 if (ret != RPC_S_OK) return ret;
736 ret = UuidFromStringA(ObjectUuid, &Uuid);
739 ret = RPCRT4_CreateBindingA(&bind, FALSE, Protseq);
741 ret = RPCRT4_SetBindingObject(bind, &Uuid);
743 ret = RPCRT4_CompleteBindingA(bind, NetworkAddr, Endpoint, Options);
745 RpcStringFreeA(&Options);
746 RpcStringFreeA(&Endpoint);
747 RpcStringFreeA(&NetworkAddr);
748 RpcStringFreeA(&Protseq);
749 RpcStringFreeA(&ObjectUuid);
751 if (ret == RPC_S_OK) *Binding = (RPC_BINDING_HANDLE)bind;
752 else RPCRT4_DestroyBinding(bind);
757 /***********************************************************************
758 * RpcBindingFromStringBindingW (RPCRT4.@)
760 RPC_STATUS WINAPI RpcBindingFromStringBindingW( LPWSTR StringBinding, RPC_BINDING_HANDLE* Binding )
763 RpcBinding* bind = NULL;
764 LPWSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
767 TRACE("(%s,%p)\n", debugstr_w(StringBinding), Binding);
769 ret = RpcStringBindingParseW(StringBinding, &ObjectUuid, &Protseq,
770 &NetworkAddr, &Endpoint, &Options);
771 if (ret != RPC_S_OK) return ret;
773 ret = UuidFromStringW(ObjectUuid, &Uuid);
776 ret = RPCRT4_CreateBindingW(&bind, FALSE, Protseq);
778 ret = RPCRT4_SetBindingObject(bind, &Uuid);
780 ret = RPCRT4_CompleteBindingW(bind, NetworkAddr, Endpoint, Options);
782 RpcStringFreeW(&Options);
783 RpcStringFreeW(&Endpoint);
784 RpcStringFreeW(&NetworkAddr);
785 RpcStringFreeW(&Protseq);
786 RpcStringFreeW(&ObjectUuid);
788 if (ret == RPC_S_OK) *Binding = (RPC_BINDING_HANDLE)bind;
789 else RPCRT4_DestroyBinding(bind);
794 /***********************************************************************
795 * RpcBindingToStringBindingA (RPCRT4.@)
797 RPC_STATUS WINAPI RpcBindingToStringBindingA( RPC_BINDING_HANDLE Binding, LPSTR* StringBinding )
800 RpcBinding* bind = (RpcBinding*)Binding;
803 TRACE("(%p,%p)\n", Binding, StringBinding);
805 ret = UuidToStringA(&bind->ObjectUuid, &ObjectUuid);
806 if (ret != RPC_S_OK) return ret;
808 ret = RpcStringBindingComposeA(ObjectUuid, bind->Protseq, bind->NetworkAddr,
809 bind->Endpoint, NULL, StringBinding);
811 RpcStringFreeA(&ObjectUuid);
816 /***********************************************************************
817 * RpcBindingToStringBindingW (RPCRT4.@)
819 RPC_STATUS WINAPI RpcBindingToStringBindingW( RPC_BINDING_HANDLE Binding, LPWSTR* StringBinding )
823 TRACE("(%p,%p)\n", Binding, StringBinding);
824 ret = RpcBindingToStringBindingA(Binding, &str);
825 *StringBinding = RPCRT4_strdupAtoW(str);
826 RpcStringFreeA(&str);
830 /***********************************************************************
831 * I_RpcBindingSetAsync (RPCRT4.@)
833 * Exists in win9x and winNT, but with different number of arguments
834 * (9x version has 3 arguments, NT has 2).
836 RPC_STATUS WINAPI I_RpcBindingSetAsync( RPC_BINDING_HANDLE Binding, RPC_BLOCKING_FN BlockingFn, unsigned long ServerTid )
838 RpcBinding* bind = (RpcBinding*)Binding;
840 TRACE( "(%p,%p,%ld): stub\n", Binding, BlockingFn, ServerTid );
842 bind->BlockingFn = BlockingFn;
843 bind->ServerTid = ServerTid;