[2/2] dpnet: Partial Implement IDirectPlay8Peer SetPeerInfo (try 3)

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Sat Jan 11 02:24:18 CST 2014


Hi,
Remove pointer checks.
Add Heap Helper functions.

Changelog:
       dpnet: Partial Implement IDirectPlay8Peer SetPeerInfo


Best Regards
    Alistair Leslie-Hughes


-------------- next part --------------
>From 0e011fb29ba02fa8bbe454c75e607bfad7f02ebd Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date: Fri, 10 Jan 2014 11:10:40 +1100
Subject: [PATCH] Partial Implement IDirectPlay8Peer SetPeerInfo
To: wine-patches <wine-patches at winehq.org>

---
 dlls/dpnet/dpnet_private.h | 22 ++++++++++++++++++++++
 dlls/dpnet/peer.c          | 36 +++++++++++++++++++++++++++++++++---
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/dlls/dpnet/dpnet_private.h b/dlls/dpnet/dpnet_private.h
index 4a42eae..e4ff219 100644
--- a/dlls/dpnet/dpnet_private.h
+++ b/dlls/dpnet/dpnet_private.h
@@ -27,6 +27,9 @@
 
 #include "dplay8.h"
 #include "dplobby8.h"
+
+#include "wine/unicode.h"
+
 /*
  *#include "dplay8sp.h"
  */
@@ -95,6 +98,25 @@ extern HRESULT DPNET_CreateDirectPlay8Address(LPCLASSFACTORY iface, LPUNKNOWN pu
 extern HRESULT DPNET_CreateDirectPlay8LobbiedApp(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN;
 extern HRESULT DPNET_CreateDirectPlay8ThreadPool(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN;
 
+static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
+static inline void *heap_alloc( size_t len )
+{
+    return HeapAlloc( GetProcessHeap(), 0, len );
+}
+
+static inline BOOL heap_free( void *mem )
+{
+    return HeapFree( GetProcessHeap(), 0, mem );
+}
+
+static inline WCHAR *heap_strdupW( const WCHAR *src )
+{
+    WCHAR *dst;
+    if (!src) return NULL;
+    if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
+    return dst;
+}
+
 /* used for generic dumping (copied from ddraw) */
 typedef struct {
     DWORD val;
diff --git a/dlls/dpnet/peer.c b/dlls/dpnet/peer.c
index 1b287dd..280708b 100644
--- a/dlls/dpnet/peer.c
+++ b/dlls/dpnet/peer.c
@@ -43,6 +43,10 @@ typedef struct IDirectPlay8PeerImpl
 {
     IDirectPlay8Peer IDirectPlay8Peer_iface;
     LONG ref;
+
+    PWSTR peername;
+    void* data;
+    int datasize;
 } IDirectPlay8PeerImpl;
 
 static inline IDirectPlay8PeerImpl *impl_from_IDirectPlay8Peer(IDirectPlay8Peer *iface)
@@ -86,7 +90,12 @@ static ULONG WINAPI IDirectPlay8PeerImpl_Release(IDirectPlay8Peer *iface)
     TRACE("(%p) ref=%d\n", This, RefCount);
 
     if(!RefCount)
-        HeapFree(GetProcessHeap(), 0, This);
+    {
+        heap_free(This->peername);
+        heap_free(This->data);
+
+        heap_free(This);
+    }
 
     return RefCount;
 }
@@ -292,9 +301,27 @@ static HRESULT WINAPI IDirectPlay8PeerImpl_SetPeerInfo(IDirectPlay8Peer *iface,
         const DPN_PLAYER_INFO * const pdpnPlayerInfo, void * const pvAsyncContext,
         DPNHANDLE * const phAsyncHandle, const DWORD dwFlags)
 {
-    FIXME("(%p)->(%p,%p,%p,%x): stub\n", iface, pdpnPlayerInfo, pvAsyncContext, phAsyncHandle, dwFlags);
+    IDirectPlay8PeerImpl* This = impl_from_IDirectPlay8Peer(iface);
 
-    return DPNERR_GENERIC;
+    TRACE("(%p)->(%p,%p,%p,%x)\n", This, pdpnPlayerInfo, pvAsyncContext, phAsyncHandle, dwFlags);
+
+    if(pdpnPlayerInfo->dwInfoFlags & DPNINFO_NAME)
+    {
+        heap_free(This->peername);
+
+        This->peername = heap_strdupW(pdpnPlayerInfo->pwszName);
+    }
+
+    if(pdpnPlayerInfo->dwInfoFlags & DPNINFO_DATA)
+    {
+        heap_free(This->data);
+
+        This->datasize = pdpnPlayerInfo->dwDataSize;
+        This->data = heap_alloc(pdpnPlayerInfo->dwDataSize);
+        memcpy(This->data, pdpnPlayerInfo->pvData, pdpnPlayerInfo->dwDataSize);
+    }
+
+    return S_OK;
 }
 
 static HRESULT WINAPI IDirectPlay8PeerImpl_GetPeerInfo(IDirectPlay8Peer *iface, const DPNID dpnid,
@@ -502,6 +529,9 @@ HRESULT DPNET_CreateDirectPlay8Peer(IClassFactory *iface, IUnknown *pUnkOuter, R
 
     Client->IDirectPlay8Peer_iface.lpVtbl = &DirectPlay8Peer_Vtbl;
     Client->ref = 1;
+    Client->peername = NULL;
+    Client->data = NULL;
+    Client->datasize = 0;
 
     ret = IDirectPlay8Peer_QueryInterface(&Client->IDirectPlay8Peer_iface, riid, ppobj);
     IDirectPlay8Peer_Release(&Client->IDirectPlay8Peer_iface);
-- 
1.8.3.2



More information about the wine-patches mailing list