4 * Copyright 2004 Raphael Junqueira
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/debug.h"
34 #include "dpnet_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dpnet
);
38 typedef struct IDirectPlay8LobbyClientImpl
40 IDirectPlay8LobbyClient IDirectPlay8LobbyClient_iface
;
43 PFNDPNMESSAGEHANDLER msghandler
;
46 } IDirectPlay8LobbyClientImpl
;
48 static inline IDirectPlay8LobbyClientImpl
*impl_from_IDirectPlay8LobbyClient(IDirectPlay8LobbyClient
*iface
)
50 return CONTAINING_RECORD(iface
, IDirectPlay8LobbyClientImpl
, IDirectPlay8LobbyClient_iface
);
53 static inline IDirectPlay8ClientImpl
*impl_from_IDirectPlay8Client(IDirectPlay8Client
*iface
)
55 return CONTAINING_RECORD(iface
, IDirectPlay8ClientImpl
, IDirectPlay8Client_iface
);
58 /* IDirectPlay8Client IUnknown parts follow: */
59 static HRESULT WINAPI
IDirectPlay8ClientImpl_QueryInterface(IDirectPlay8Client
*iface
, REFIID riid
,
62 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
64 if (IsEqualGUID(riid
, &IID_IUnknown
)
65 || IsEqualGUID(riid
, &IID_IDirectPlay8Client
)) {
66 IUnknown_AddRef(iface
);
71 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
75 static ULONG WINAPI
IDirectPlay8ClientImpl_AddRef(IDirectPlay8Client
*iface
)
77 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
78 ULONG ref
= InterlockedIncrement(&This
->ref
);
80 TRACE("(%p) ref=%u\n", This
, ref
);
85 static ULONG WINAPI
IDirectPlay8ClientImpl_Release(IDirectPlay8Client
*iface
)
87 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
88 ULONG ref
= InterlockedDecrement(&This
->ref
);
90 TRACE("(%p) ref=%u\n", This
, ref
);
94 heap_free(This
->username
);
95 heap_free(This
->data
);
101 /* IDirectPlay8Client Interface follow: */
103 static HRESULT WINAPI
IDirectPlay8ClientImpl_Initialize(IDirectPlay8Client
*iface
,
104 void * const pvUserContext
, const PFNDPNMESSAGEHANDLER pfn
, const DWORD dwFlags
)
106 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
108 TRACE("(%p):(%p,%p,%x)\n", This
, pvUserContext
, pfn
, dwFlags
);
111 return DPNERR_INVALIDPARAM
;
113 This
->usercontext
= pvUserContext
;
114 This
->msghandler
= pfn
;
115 This
->flags
= dwFlags
;
122 static HRESULT WINAPI
IDirectPlay8ClientImpl_EnumServiceProviders(IDirectPlay8Client
*iface
,
123 const GUID
* const pguidServiceProvider
, const GUID
* const pguidApplication
,
124 DPN_SERVICE_PROVIDER_INFO
* const pSPInfoBuffer
, PDWORD
const pcbEnumData
,
125 PDWORD
const pcReturned
, const DWORD dwFlags
)
127 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
128 TRACE("(%p)->(%s,%s,%p,%p,%p,%x)\n", This
, debugstr_guid(pguidServiceProvider
), debugstr_guid(pguidApplication
),
129 pSPInfoBuffer
, pcbEnumData
, pcReturned
, dwFlags
);
132 FIXME("Unhandled flags %x\n", dwFlags
);
135 FIXME("Application guid %s is currently being ignored\n", debugstr_guid(pguidApplication
));
137 return enum_services_providers(pguidServiceProvider
, pSPInfoBuffer
, pcbEnumData
, pcReturned
);
140 static HRESULT WINAPI
IDirectPlay8ClientImpl_EnumHosts(IDirectPlay8Client
*iface
,
141 PDPN_APPLICATION_DESC
const pApplicationDesc
, IDirectPlay8Address
* const pAddrHost
,
142 IDirectPlay8Address
* const pDeviceInfo
, void * const pUserEnumData
,
143 const DWORD dwUserEnumDataSize
, const DWORD dwEnumCount
, const DWORD dwRetryInterval
,
144 const DWORD dwTimeOut
, void * const pvUserContext
, DPNHANDLE
* const pAsyncHandle
,
147 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
149 FIXME("(%p):(%p,%p,%p,%p,%u,%u,%u,%u,%p,%p,%x)\n", This
, pApplicationDesc
, pAddrHost
, pDeviceInfo
, pUserEnumData
,
150 dwUserEnumDataSize
, dwEnumCount
, dwRetryInterval
, dwTimeOut
, pvUserContext
, pAsyncHandle
, dwFlags
);
152 if(!This
->msghandler
)
153 return DPNERR_UNINITIALIZED
;
155 if((dwFlags
& DPNENUMHOSTS_SYNC
) && pAsyncHandle
)
156 return DPNERR_INVALIDPARAM
;
158 if(dwUserEnumDataSize
> This
->spcaps
.dwMaxEnumPayloadSize
)
159 return DPNERR_ENUMQUERYTOOLARGE
;
161 return (dwFlags
& DPNENUMHOSTS_SYNC
) ? DPN_OK
: DPNSUCCESS_PENDING
;
164 static HRESULT WINAPI
IDirectPlay8ClientImpl_CancelAsyncOperation(IDirectPlay8Client
*iface
,
165 const DPNHANDLE hAsyncHandle
, const DWORD dwFlags
)
167 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
168 FIXME("(%p):(%u,%x): Stub\n", This
, hAsyncHandle
, dwFlags
);
172 static HRESULT WINAPI
IDirectPlay8ClientImpl_Connect(IDirectPlay8Client
*iface
,
173 const DPN_APPLICATION_DESC
* const pdnAppDesc
, IDirectPlay8Address
* const pHostAddr
,
174 IDirectPlay8Address
* const pDeviceInfo
, const DPN_SECURITY_DESC
* const pdnSecurity
,
175 const DPN_SECURITY_CREDENTIALS
* const pdnCredentials
, const void * const pvUserConnectData
,
176 const DWORD dwUserConnectDataSize
, void * const pvAsyncContext
,
177 DPNHANDLE
* const phAsyncHandle
, const DWORD dwFlags
)
179 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
180 FIXME("(%p):(%p,%p,%x): Stub\n", This
, pvAsyncContext
, phAsyncHandle
, dwFlags
);
184 static HRESULT WINAPI
IDirectPlay8ClientImpl_Send(IDirectPlay8Client
*iface
,
185 const DPN_BUFFER_DESC
* const prgBufferDesc
, const DWORD cBufferDesc
, const DWORD dwTimeOut
,
186 void * const pvAsyncContext
, DPNHANDLE
* const phAsyncHandle
, const DWORD dwFlags
)
188 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
189 FIXME("(%p):(%p,%p,%x): Stub\n", This
, pvAsyncContext
, phAsyncHandle
, dwFlags
);
193 static HRESULT WINAPI
IDirectPlay8ClientImpl_GetSendQueueInfo(IDirectPlay8Client
*iface
,
194 DWORD
* const pdwNumMsgs
, DWORD
* const pdwNumBytes
, const DWORD dwFlags
)
196 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
197 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
201 static HRESULT WINAPI
IDirectPlay8ClientImpl_GetApplicationDesc(IDirectPlay8Client
*iface
,
202 DPN_APPLICATION_DESC
* const pAppDescBuffer
, DWORD
* const pcbDataSize
, const DWORD dwFlags
)
204 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
205 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
209 static HRESULT WINAPI
IDirectPlay8ClientImpl_SetClientInfo(IDirectPlay8Client
*iface
,
210 const DPN_PLAYER_INFO
* const pdpnPlayerInfo
, void * const pvAsyncContext
,
211 DPNHANDLE
* const phAsyncHandle
, const DWORD dwFlags
)
213 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
214 FIXME("(%p):(%p,%p,%x): Semi-stub.\n", This
, pvAsyncContext
, phAsyncHandle
, dwFlags
);
220 FIXME("Async handle currently not supported.\n");
222 if (pdpnPlayerInfo
->dwInfoFlags
& DPNINFO_NAME
)
224 heap_free(This
->username
);
225 This
->username
= NULL
;
227 if(pdpnPlayerInfo
->pwszName
)
229 This
->username
= heap_strdupW(pdpnPlayerInfo
->pwszName
);
231 return E_OUTOFMEMORY
;
235 if (pdpnPlayerInfo
->dwInfoFlags
& DPNINFO_DATA
)
237 heap_free(This
->data
);
241 if(!pdpnPlayerInfo
->pvData
&& pdpnPlayerInfo
->dwDataSize
)
244 if(pdpnPlayerInfo
->dwDataSize
&& pdpnPlayerInfo
->pvData
)
246 This
->data
= heap_alloc(pdpnPlayerInfo
->dwDataSize
);
248 return E_OUTOFMEMORY
;
250 This
->datasize
= pdpnPlayerInfo
->dwDataSize
;
252 memcpy(This
->data
, pdpnPlayerInfo
->pvData
, pdpnPlayerInfo
->dwDataSize
);
259 static HRESULT WINAPI
IDirectPlay8ClientImpl_GetServerInfo(IDirectPlay8Client
*iface
,
260 DPN_PLAYER_INFO
* const pdpnPlayerInfo
, DWORD
* const pdwSize
, const DWORD dwFlags
)
262 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
263 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
267 static HRESULT WINAPI
IDirectPlay8ClientImpl_GetServerAddress(IDirectPlay8Client
*iface
,
268 IDirectPlay8Address
** const pAddress
, const DWORD dwFlags
)
270 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
271 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
275 static HRESULT WINAPI
IDirectPlay8ClientImpl_Close(IDirectPlay8Client
*iface
, const DWORD dwFlags
)
277 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
278 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
280 This
->msghandler
= NULL
;
285 static HRESULT WINAPI
IDirectPlay8ClientImpl_ReturnBuffer(IDirectPlay8Client
*iface
,
286 const DPNHANDLE hBufferHandle
, const DWORD dwFlags
)
288 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
289 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
293 static HRESULT WINAPI
IDirectPlay8ClientImpl_GetCaps(IDirectPlay8Client
*iface
,
294 DPN_CAPS
* const pdpCaps
, const DWORD dwFlags
)
296 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
297 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
301 static HRESULT WINAPI
IDirectPlay8ClientImpl_SetCaps(IDirectPlay8Client
*iface
,
302 const DPN_CAPS
* const pdpCaps
, const DWORD dwFlags
)
304 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
305 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
309 static HRESULT WINAPI
IDirectPlay8ClientImpl_SetSPCaps(IDirectPlay8Client
*iface
,
310 const GUID
* const pguidSP
, const DPN_SP_CAPS
* const pdpspCaps
, const DWORD dwFlags
)
312 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
313 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
317 static HRESULT WINAPI
IDirectPlay8ClientImpl_GetSPCaps(IDirectPlay8Client
*iface
,
318 const GUID
* const pguidSP
, DPN_SP_CAPS
* const pdpspCaps
, const DWORD dwFlags
)
320 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
322 TRACE("(%p)->(%p,%p,%x)\n", This
, pguidSP
, pdpspCaps
, dwFlags
);
324 if(!This
->msghandler
)
325 return DPNERR_UNINITIALIZED
;
327 if(pdpspCaps
->dwSize
!= sizeof(DPN_SP_CAPS
))
329 return DPNERR_INVALIDPARAM
;
332 *pdpspCaps
= This
->spcaps
;
337 static HRESULT WINAPI
IDirectPlay8ClientImpl_GetConnectionInfo(IDirectPlay8Client
*iface
,
338 DPN_CONNECTION_INFO
* const pdpConnectionInfo
, const DWORD dwFlags
)
340 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
341 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
345 static HRESULT WINAPI
IDirectPlay8ClientImpl_RegisterLobby(IDirectPlay8Client
*iface
,
346 const DPNHANDLE dpnHandle
,
347 struct IDirectPlay8LobbiedApplication
* const pIDP8LobbiedApplication
, const DWORD dwFlags
)
349 IDirectPlay8ClientImpl
*This
= impl_from_IDirectPlay8Client(iface
);
350 FIXME("(%p):(%x): Stub\n", This
, dwFlags
);
354 static const IDirectPlay8ClientVtbl DirectPlay8Client_Vtbl
=
356 IDirectPlay8ClientImpl_QueryInterface
,
357 IDirectPlay8ClientImpl_AddRef
,
358 IDirectPlay8ClientImpl_Release
,
359 IDirectPlay8ClientImpl_Initialize
,
360 IDirectPlay8ClientImpl_EnumServiceProviders
,
361 IDirectPlay8ClientImpl_EnumHosts
,
362 IDirectPlay8ClientImpl_CancelAsyncOperation
,
363 IDirectPlay8ClientImpl_Connect
,
364 IDirectPlay8ClientImpl_Send
,
365 IDirectPlay8ClientImpl_GetSendQueueInfo
,
366 IDirectPlay8ClientImpl_GetApplicationDesc
,
367 IDirectPlay8ClientImpl_SetClientInfo
,
368 IDirectPlay8ClientImpl_GetServerInfo
,
369 IDirectPlay8ClientImpl_GetServerAddress
,
370 IDirectPlay8ClientImpl_Close
,
371 IDirectPlay8ClientImpl_ReturnBuffer
,
372 IDirectPlay8ClientImpl_GetCaps
,
373 IDirectPlay8ClientImpl_SetCaps
,
374 IDirectPlay8ClientImpl_SetSPCaps
,
375 IDirectPlay8ClientImpl_GetSPCaps
,
376 IDirectPlay8ClientImpl_GetConnectionInfo
,
377 IDirectPlay8ClientImpl_RegisterLobby
380 HRESULT
DPNET_CreateDirectPlay8Client(IClassFactory
*iface
, IUnknown
*pUnkOuter
, REFIID riid
, void **ppv
)
382 IDirectPlay8ClientImpl
* client
;
385 TRACE("(%p, %s, %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
390 return CLASS_E_NOAGGREGATION
;
392 client
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectPlay8ClientImpl
));
394 return E_OUTOFMEMORY
;
396 client
->IDirectPlay8Client_iface
.lpVtbl
= &DirectPlay8Client_Vtbl
;
399 init_dpn_sp_caps(&client
->spcaps
);
401 hr
= IDirectPlay8ClientImpl_QueryInterface(&client
->IDirectPlay8Client_iface
, riid
, ppv
);
402 IDirectPlay8ClientImpl_Release(&client
->IDirectPlay8Client_iface
);
407 static HRESULT WINAPI
lobbyclient_QueryInterface(IDirectPlay8LobbyClient
*iface
, REFIID riid
, void **obj
)
409 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
411 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
415 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
416 IsEqualGUID(riid
, &IID_IDirectPlay8LobbyClient
))
418 *obj
= &This
->IDirectPlay8LobbyClient_iface
;
419 IUnknown_AddRef( (IUnknown
*)*obj
);
424 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),obj
);
425 return E_NOINTERFACE
;
428 static ULONG WINAPI
lobbyclient_AddRef(IDirectPlay8LobbyClient
*iface
)
430 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
431 ULONG ref
= InterlockedIncrement(&This
->ref
);
433 TRACE("(%p) ref=%u\n", This
, ref
);
438 static ULONG WINAPI
lobbyclient_Release(IDirectPlay8LobbyClient
*iface
)
440 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
441 ULONG ref
= InterlockedDecrement(&This
->ref
);
443 TRACE("(%p) ref=%u\n", This
, ref
);
447 HeapFree(GetProcessHeap(), 0, This
);
453 static HRESULT WINAPI
lobbyclient_Initialize(IDirectPlay8LobbyClient
*iface
, void *context
,
454 PFNDPNMESSAGEHANDLER msghandler
, DWORD flags
)
456 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
458 TRACE("(%p):(%p,%p,%x)\n", This
, context
, msghandler
, flags
);
463 This
->usercontext
= context
;
464 This
->msghandler
= msghandler
;
472 static HRESULT WINAPI
lobbyclient_EnumLocalPrograms(IDirectPlay8LobbyClient
*iface
, GUID
* guidapplication
,
473 BYTE
*enumdata
, DWORD
*enumDataSize
, DWORD
*items
, DWORD flags
)
475 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
477 FIXME("(%p)->(%p %p %p %p 0x%08x)\n", This
, guidapplication
, enumdata
, enumDataSize
, items
, flags
);
482 static HRESULT WINAPI
lobbyclient_ConnectApplication(IDirectPlay8LobbyClient
*iface
, DPL_CONNECT_INFO
*connectioninfo
,
483 void *connectioncontext
, DPNHANDLE
*application
, DWORD timeout
,
486 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
488 FIXME("(%p)->(%p %p %p %u 0x%08x)\n", This
, connectioninfo
, connectioncontext
, application
, timeout
, flags
);
493 static HRESULT WINAPI
lobbyclient_Send(IDirectPlay8LobbyClient
*iface
, DPNHANDLE connection
, BYTE
*buffer
, DWORD buffersize
, DWORD flags
)
495 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
497 FIXME("(%p)->(%u %p %u 0x%08x)\n", This
, connection
, buffer
, buffersize
, flags
);
502 static HRESULT WINAPI
lobbyclient_ReleaseApplication(IDirectPlay8LobbyClient
*iface
, DPNHANDLE connection
, DWORD flags
)
504 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
506 FIXME("(%p)->(%u 0x%08x)\n", This
, connection
, flags
);
511 static HRESULT WINAPI
lobbyclient_Close(IDirectPlay8LobbyClient
*iface
, DWORD flags
)
513 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
515 FIXME("(%p)->(0x%08x)\n", This
, flags
);
520 static HRESULT WINAPI
lobbyclient_GetConnectionSettings(IDirectPlay8LobbyClient
*iface
, DPNHANDLE connection
, DPL_CONNECTION_SETTINGS
*sessioninfo
, DWORD
*infosize
, DWORD flags
)
522 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
524 FIXME("(%p)->(%u %p %p 0x%08x)\n", This
, connection
, sessioninfo
, infosize
, flags
);
529 static HRESULT WINAPI
lobbyclient_SetConnectionSettings(IDirectPlay8LobbyClient
*iface
, DPNHANDLE connection
, const DPL_CONNECTION_SETTINGS
*sessioninfo
, DWORD flags
)
531 IDirectPlay8LobbyClientImpl
*This
= impl_from_IDirectPlay8LobbyClient(iface
);
533 FIXME("(%p)->(%u %p 0x%08x)\n", This
, connection
, sessioninfo
, flags
);
538 static const IDirectPlay8LobbyClientVtbl DirectPlay8LobbiedClient_Vtbl
=
540 lobbyclient_QueryInterface
,
543 lobbyclient_Initialize
,
544 lobbyclient_EnumLocalPrograms
,
545 lobbyclient_ConnectApplication
,
547 lobbyclient_ReleaseApplication
,
549 lobbyclient_GetConnectionSettings
,
550 lobbyclient_SetConnectionSettings
553 HRESULT
DPNET_CreateDirectPlay8LobbyClient(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **obj
)
555 IDirectPlay8LobbyClientImpl
*client
;
558 TRACE("%p (%p, %s, %p)\n", iface
, outer
, debugstr_guid(riid
), obj
);
560 client
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*client
));
564 return E_OUTOFMEMORY
;
567 client
->IDirectPlay8LobbyClient_iface
.lpVtbl
= &DirectPlay8LobbiedClient_Vtbl
;
570 ret
= lobbyclient_QueryInterface(&client
->IDirectPlay8LobbyClient_iface
, riid
, obj
);
571 lobbyclient_Release(&client
->IDirectPlay8LobbyClient_iface
);