From 6aa3e62e96640726c19a34e660b2008e8ad173c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Wed, 12 Jan 2005 20:23:51 +0000 Subject: [PATCH] Sync to Wine-20050111: Robert Shearman - Remove unnecessary WNDPROC casts. - Implement RPC_E_DISCONNECTED in proxies. Mike McCormack - Use CreateEventW in preference to CreateEventA for unnamed events. Michael Stefaniuc - Do not check for non NULL pointer before HeapFree'ing it. It's redundant. Bill Medland - Implemented DceErrorInqText. svn path=/trunk/; revision=12991 --- reactos/lib/rpcrt4/ndr_midl.c | 7 +++++ reactos/lib/rpcrt4/rpc_binding.c | 10 +++---- reactos/lib/rpcrt4/rpc_message.c | 7 ++--- reactos/lib/rpcrt4/rpc_server.c | 6 ++-- reactos/lib/rpcrt4/rpcrt4.spec | 4 +-- reactos/lib/rpcrt4/rpcrt4_main.c | 50 ++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 15 deletions(-) diff --git a/reactos/lib/rpcrt4/ndr_midl.c b/reactos/lib/rpcrt4/ndr_midl.c index 9804b7c8963..76f972b69f4 100644 --- a/reactos/lib/rpcrt4/ndr_midl.c +++ b/reactos/lib/rpcrt4/ndr_midl.c @@ -100,6 +100,13 @@ void WINAPI NdrProxySendReceive(void *This, HRESULT hr; TRACE("(%p,%p)\n", This, pStubMsg); + + if (!pStubMsg->pRpcChannelBuffer) + { + WARN("Trying to use disconnected proxy %p\n", This); + RpcRaiseException(RPC_E_DISCONNECTED); + } + pStubMsg->dwStubPhase = PROXY_SENDRECEIVE; hr = IRpcChannelBuffer_SendReceive(pStubMsg->pRpcChannelBuffer, (RPCOLEMESSAGE*)pStubMsg->RpcMsg, diff --git a/reactos/lib/rpcrt4/rpc_binding.c b/reactos/lib/rpcrt4/rpc_binding.c index 32b71433e86..82e1690ea5f 100644 --- a/reactos/lib/rpcrt4/rpc_binding.c +++ b/reactos/lib/rpcrt4/rpc_binding.c @@ -96,7 +96,7 @@ LPWSTR RPCRT4_strndupW(LPWSTR src, INT slen) void RPCRT4_strfree(LPSTR src) { - if (src) HeapFree(GetProcessHeap(), 0, src); + HeapFree(GetProcessHeap(), 0, src); } RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server, LPSTR Protseq, LPSTR NetworkAddr, LPSTR Endpoint, LPSTR NetworkOptions, RpcBinding* Binding) @@ -147,7 +147,7 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection) RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL); HeapFree(GetProcessHeap(), 0, pname); memset(&Connection->ovl, 0, sizeof(Connection->ovl)); - Connection->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL); + Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); if (!ConnectNamedPipe(Connection->conn, &Connection->ovl)) { WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError()); if (GetLastError() == ERROR_PIPE_CONNECTED) { @@ -171,7 +171,7 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection) RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL); HeapFree(GetProcessHeap(), 0, pname); memset(&Connection->ovl, 0, sizeof(Connection->ovl)); - Connection->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL); + Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); if (!ConnectNamedPipe(Connection->conn, &Connection->ovl)) { WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError()); if (GetLastError() == ERROR_PIPE_CONNECTED) { @@ -223,7 +223,7 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection) /* pipe is connected; change to message-read mode. */ dwMode = PIPE_READMODE_MESSAGE; SetNamedPipeHandleState(conn, &dwMode, NULL, NULL); - Connection->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL); + Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); Connection->conn = conn; } /* protseq=ncacn_np: named pipes */ @@ -257,7 +257,7 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection) /* pipe is connected; change to message-read mode. */ dwMode = PIPE_READMODE_MESSAGE; SetNamedPipeHandleState(conn, &dwMode, NULL, NULL); - Connection->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL); + Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); Connection->conn = conn; } else { ERR("protseq %s not supported\n", Connection->Protseq); diff --git a/reactos/lib/rpcrt4/rpc_message.c b/reactos/lib/rpcrt4/rpc_message.c index 6a2b8365138..119af8cfab3 100644 --- a/reactos/lib/rpcrt4/rpc_message.c +++ b/reactos/lib/rpcrt4/rpc_message.c @@ -447,8 +447,7 @@ RPC_STATUS WINAPI I_RpcGetBuffer(PRPC_MESSAGE pMsg) * it, we'll leave deallocating the original buffer to the RPC server */ pMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, pMsg->BufferLength); } else { - if (pMsg->Buffer) - HeapFree(GetProcessHeap(), 0, pMsg->Buffer); + HeapFree(GetProcessHeap(), 0, pMsg->Buffer); pMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, pMsg->BufferLength); } TRACE("Buffer=%p\n", pMsg->Buffer); @@ -463,9 +462,7 @@ RPC_STATUS WINAPI I_RpcFreeBuffer(PRPC_MESSAGE pMsg) { TRACE("(%p) Buffer=%p\n", pMsg, pMsg->Buffer); /* FIXME: pfnFree? */ - if (pMsg->Buffer != NULL) { - HeapFree(GetProcessHeap(), 0, pMsg->Buffer); - } + HeapFree(GetProcessHeap(), 0, pMsg->Buffer); pMsg->Buffer = NULL; return S_OK; } diff --git a/reactos/lib/rpcrt4/rpc_server.c b/reactos/lib/rpcrt4/rpc_server.c index 57eb4abbd30..bb3cb95da82 100644 --- a/reactos/lib/rpcrt4/rpc_server.c +++ b/reactos/lib/rpcrt4/rpc_server.c @@ -434,7 +434,7 @@ static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg) #endif msg = NULL; } - if (msg) HeapFree(GetProcessHeap(), 0, msg); + HeapFree(GetProcessHeap(), 0, msg); RPCRT4_DestroyConnection(conn); return 0; } @@ -554,8 +554,8 @@ static void RPCRT4_start_listen(void) EnterCriticalSection(&listen_cs); if (! ++listen_count) { - if (!mgr_event) mgr_event = CreateEventA(NULL, TRUE, FALSE, NULL); - if (!server_sem) server_sem = CreateSemaphoreA(NULL, 0, MAX_THREADS, NULL); + if (!mgr_event) mgr_event = CreateEventW(NULL, TRUE, FALSE, NULL); + if (!server_sem) server_sem = CreateSemaphoreW(NULL, 0, MAX_THREADS, NULL); if (!worker_tls) worker_tls = TlsAlloc(); std_listen = TRUE; server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, NULL, 0, NULL); diff --git a/reactos/lib/rpcrt4/rpcrt4.spec b/reactos/lib/rpcrt4/rpcrt4.spec index 72efb417851..c2250a8e1e4 100644 --- a/reactos/lib/rpcrt4/rpcrt4.spec +++ b/reactos/lib/rpcrt4/rpcrt4.spec @@ -1,5 +1,5 @@ -@ stub DceErrorInqTextA -@ stub DceErrorInqTextW +@ stdcall DceErrorInqTextA (long ptr) +@ stdcall DceErrorInqTextW (long ptr) @ stdcall -private DllRegisterServer() RPCRT4_DllRegisterServer @ stub MesBufferHandleReset diff --git a/reactos/lib/rpcrt4/rpcrt4_main.c b/reactos/lib/rpcrt4/rpcrt4_main.c index baf7914e2b6..cdf54512aec 100644 --- a/reactos/lib/rpcrt4/rpcrt4_main.c +++ b/reactos/lib/rpcrt4/rpcrt4_main.c @@ -748,3 +748,53 @@ BOOL RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg, char *vardata_payload, PRPC return TRUE; } + +/* DceErrorInqText + * + * Notes + * 1. On passing a NULL pointer the code does bomb out. + * 2. The size of the required buffer is not defined in the documentation. + * It appears to be 256. + * 3. The function is defined to return RPC_S_INVALID_ARG but I don't know + * of any value for which it does. + * 4. The MSDN documentation currently declares that the second argument is + * unsigned char *, even for the W version. I don't believe it. + */ + +#define MAX_RPC_ERROR_TEXT 256 + +RPC_STATUS RPC_ENTRY DceErrorInqTextW (RPC_STATUS e, unsigned short *buffer) +{ + DWORD count; + count = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, e, 0, buffer, MAX_RPC_ERROR_TEXT, NULL); + if (!count) + { + count = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, RPC_S_NOT_RPC_ERROR, 0, buffer, MAX_RPC_ERROR_TEXT, NULL); + if (!count) + { + ERR ("Failed to translate error"); + return RPC_S_INVALID_ARG; + } + } + return RPC_S_OK; +} + +RPC_STATUS RPC_ENTRY DceErrorInqTextA (RPC_STATUS e, unsigned char *buffer) +{ + RPC_STATUS status; + WCHAR bufferW [MAX_RPC_ERROR_TEXT]; + if ((status = DceErrorInqTextW (e, bufferW)) == RPC_S_OK) + { + if (!WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_RPC_ERROR_TEXT, + NULL, NULL)) + { + ERR ("Failed to translate error"); + status = RPC_S_INVALID_ARG; + } + } + return status; +}