Sync to Wine-20050111:
authorGé van Geldorp <ge@gse.nl>
Wed, 12 Jan 2005 20:23:51 +0000 (20:23 +0000)
committerGé van Geldorp <ge@gse.nl>
Wed, 12 Jan 2005 20:23:51 +0000 (20:23 +0000)
Robert Shearman <rob@codeweavers.com>
- Remove unnecessary WNDPROC casts.
- Implement RPC_E_DISCONNECTED in proxies.
Mike McCormack <mike@codeweavers.com>
- Use CreateEventW in preference to CreateEventA for unnamed events.
Michael Stefaniuc <mstefani@redhat.de>
- Do not check for non NULL pointer before HeapFree'ing it. It's
  redundant.
Bill Medland <billmedland@mercuryspeed.com>
- Implemented DceErrorInqText.

svn path=/trunk/; revision=12991

reactos/lib/rpcrt4/ndr_midl.c
reactos/lib/rpcrt4/rpc_binding.c
reactos/lib/rpcrt4/rpc_message.c
reactos/lib/rpcrt4/rpc_server.c
reactos/lib/rpcrt4/rpcrt4.spec
reactos/lib/rpcrt4/rpcrt4_main.c

index 9804b7c..76f972b 100644 (file)
@@ -100,6 +100,13 @@ void WINAPI NdrProxySendReceive(void *This,
   HRESULT hr;\r
 \r
   TRACE("(%p,%p)\n", This, pStubMsg);\r
+\r
+  if (!pStubMsg->pRpcChannelBuffer)\r
+  {\r
+    WARN("Trying to use disconnected proxy %p\n", This);\r
+    RpcRaiseException(RPC_E_DISCONNECTED);\r
+  }\r
+\r
   pStubMsg->dwStubPhase = PROXY_SENDRECEIVE;\r
   hr = IRpcChannelBuffer_SendReceive(pStubMsg->pRpcChannelBuffer,\r
                                     (RPCOLEMESSAGE*)pStubMsg->RpcMsg,\r
index 32b7143..82e1690 100644 (file)
@@ -96,7 +96,7 @@ LPWSTR RPCRT4_strndupW(LPWSTR src, INT slen)
 \r
 void RPCRT4_strfree(LPSTR src)\r
 {\r
-  if (src) HeapFree(GetProcessHeap(), 0, src);\r
+  HeapFree(GetProcessHeap(), 0, src);\r
 }\r
 \r
 RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server, LPSTR Protseq, LPSTR NetworkAddr, LPSTR Endpoint, LPSTR NetworkOptions, RpcBinding* Binding)\r
@@ -147,7 +147,7 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection)
                                          RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);\r
         HeapFree(GetProcessHeap(), 0, pname);\r
         memset(&Connection->ovl, 0, sizeof(Connection->ovl));\r
-        Connection->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);\r
+        Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);\r
         if (!ConnectNamedPipe(Connection->conn, &Connection->ovl)) {\r
           WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError());\r
           if (GetLastError() == ERROR_PIPE_CONNECTED) {\r
@@ -171,7 +171,7 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection)
                                          RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);\r
         HeapFree(GetProcessHeap(), 0, pname);\r
         memset(&Connection->ovl, 0, sizeof(Connection->ovl));\r
-        Connection->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);\r
+        Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);\r
         if (!ConnectNamedPipe(Connection->conn, &Connection->ovl)) {\r
           WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError());\r
           if (GetLastError() == ERROR_PIPE_CONNECTED) {\r
@@ -223,7 +223,7 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection)
         /* pipe is connected; change to message-read mode. */\r
         dwMode = PIPE_READMODE_MESSAGE; \r
         SetNamedPipeHandleState(conn, &dwMode, NULL, NULL);\r
-        Connection->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);\r
+        Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);\r
         Connection->conn = conn;\r
       }\r
       /* protseq=ncacn_np: named pipes */\r
@@ -257,7 +257,7 @@ RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection)
         /* pipe is connected; change to message-read mode. */\r
         dwMode = PIPE_READMODE_MESSAGE;\r
         SetNamedPipeHandleState(conn, &dwMode, NULL, NULL);\r
-        Connection->ovl.hEvent = CreateEventA(NULL, TRUE, FALSE, NULL);\r
+        Connection->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);\r
         Connection->conn = conn;\r
       } else {\r
         ERR("protseq %s not supported\n", Connection->Protseq);\r
index 6a2b836..119af8c 100644 (file)
@@ -447,8 +447,7 @@ RPC_STATUS WINAPI I_RpcGetBuffer(PRPC_MESSAGE pMsg)
      * it, we'll leave deallocating the original buffer to the RPC server */\r
     pMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, pMsg->BufferLength);\r
   } else {\r
-    if (pMsg->Buffer)\r
-        HeapFree(GetProcessHeap(), 0, pMsg->Buffer);\r
+    HeapFree(GetProcessHeap(), 0, pMsg->Buffer);\r
     pMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, pMsg->BufferLength);\r
   }\r
   TRACE("Buffer=%p\n", pMsg->Buffer);\r
@@ -463,9 +462,7 @@ RPC_STATUS WINAPI I_RpcFreeBuffer(PRPC_MESSAGE pMsg)
 {\r
   TRACE("(%p) Buffer=%p\n", pMsg, pMsg->Buffer);\r
   /* FIXME: pfnFree? */\r
-  if (pMsg->Buffer != NULL) {\r
-    HeapFree(GetProcessHeap(), 0, pMsg->Buffer);\r
-  }\r
+  HeapFree(GetProcessHeap(), 0, pMsg->Buffer);\r
   pMsg->Buffer = NULL;\r
   return S_OK;\r
 }\r
index 57eb4ab..bb3cb95 100644 (file)
@@ -434,7 +434,7 @@ static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg)
 #endif\r
     msg = NULL;\r
   }\r
-  if (msg) HeapFree(GetProcessHeap(), 0, msg);\r
+  HeapFree(GetProcessHeap(), 0, msg);\r
   RPCRT4_DestroyConnection(conn);\r
   return 0;\r
 }\r
@@ -554,8 +554,8 @@ static void RPCRT4_start_listen(void)
 \r
   EnterCriticalSection(&listen_cs);\r
   if (! ++listen_count) {\r
-    if (!mgr_event) mgr_event = CreateEventA(NULL, TRUE, FALSE, NULL);\r
-    if (!server_sem) server_sem = CreateSemaphoreA(NULL, 0, MAX_THREADS, NULL);\r
+    if (!mgr_event) mgr_event = CreateEventW(NULL, TRUE, FALSE, NULL);\r
+    if (!server_sem) server_sem = CreateSemaphoreW(NULL, 0, MAX_THREADS, NULL);\r
     if (!worker_tls) worker_tls = TlsAlloc();\r
     std_listen = TRUE;\r
     server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, NULL, 0, NULL);\r
index 72efb41..c2250a8 100644 (file)
@@ -1,5 +1,5 @@
-@ stub DceErrorInqTextA\r
-@ stub DceErrorInqTextW\r
+@ stdcall DceErrorInqTextA (long ptr)\r
+@ stdcall DceErrorInqTextW (long ptr)\r
 @ stdcall -private DllRegisterServer() RPCRT4_DllRegisterServer\r
 \r
 @ stub MesBufferHandleReset\r
index baf7914..cdf5451 100644 (file)
@@ -748,3 +748,53 @@ BOOL RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg, char *vardata_payload, PRPC
 \r
     return TRUE;\r
 }\r
+\r
+/* DceErrorInqText\r
+ *\r
+ * Notes\r
+ * 1. On passing a NULL pointer the code does bomb out.\r
+ * 2. The size of the required buffer is not defined in the documentation.\r
+ *    It appears to be 256.\r
+ * 3. The function is defined to return RPC_S_INVALID_ARG but I don't know\r
+ *    of any value for which it does.\r
+ * 4. The MSDN documentation currently declares that the second argument is\r
+ *    unsigned char *, even for the W version.  I don't believe it.\r
+ */\r
+\r
+#define MAX_RPC_ERROR_TEXT 256\r
+\r
+RPC_STATUS RPC_ENTRY DceErrorInqTextW (RPC_STATUS e, unsigned short *buffer)\r
+{\r
+    DWORD count;\r
+    count = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |\r
+                FORMAT_MESSAGE_IGNORE_INSERTS,\r
+                NULL, e, 0, buffer, MAX_RPC_ERROR_TEXT, NULL);\r
+    if (!count)\r
+    {\r
+        count = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |\r
+                FORMAT_MESSAGE_IGNORE_INSERTS,\r
+                NULL, RPC_S_NOT_RPC_ERROR, 0, buffer, MAX_RPC_ERROR_TEXT, NULL);\r
+        if (!count)\r
+        {\r
+            ERR ("Failed to translate error");\r
+            return RPC_S_INVALID_ARG;\r
+        }\r
+    }\r
+    return RPC_S_OK;\r
+}\r
+\r
+RPC_STATUS RPC_ENTRY DceErrorInqTextA (RPC_STATUS e, unsigned char *buffer)\r
+{\r
+    RPC_STATUS status;\r
+    WCHAR bufferW [MAX_RPC_ERROR_TEXT];\r
+    if ((status = DceErrorInqTextW (e, bufferW)) == RPC_S_OK)\r
+    {\r
+        if (!WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_RPC_ERROR_TEXT,\r
+                NULL, NULL))\r
+        {\r
+            ERR ("Failed to translate error");\r
+            status = RPC_S_INVALID_ARG;\r
+        }\r
+    }\r
+    return status;\r
+}\r