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
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
37 #include "dpnet_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dpnet
);
42 static inline void *heap_alloc(size_t len
)
44 return HeapAlloc(GetProcessHeap(), 0, len
);
47 static inline BOOL
heap_free(void *mem
)
49 return HeapFree(GetProcessHeap(), 0, mem
);
52 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
59 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
60 ret
= heap_alloc(size
);
62 memcpy(ret
, str
, size
);
68 static char *heap_strdupA( const char *str
)
72 if (!str
) return NULL
;
73 if ((ret
= HeapAlloc( GetProcessHeap(), 0, strlen(str
) + 1 ))) strcpy( ret
, str
);
77 static inline IDirectPlay8AddressImpl
*impl_from_IDirectPlay8Address(IDirectPlay8Address
*iface
)
79 return CONTAINING_RECORD(iface
, IDirectPlay8AddressImpl
, IDirectPlay8Address_iface
);
82 /* IDirectPlay8Address IUnknown parts follow: */
83 static HRESULT WINAPI
IDirectPlay8AddressImpl_QueryInterface(IDirectPlay8Address
*iface
,
84 REFIID riid
, void **ppv
)
86 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IDirectPlay8Address
)) {
87 IUnknown_AddRef(iface
);
92 WARN("(%p)->(%s,%p),not found\n", iface
, debugstr_guid(riid
), ppv
);
96 static ULONG WINAPI
IDirectPlay8AddressImpl_AddRef(IDirectPlay8Address
*iface
)
98 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
99 ULONG ref
= InterlockedIncrement(&This
->ref
);
101 TRACE("(%p) ref=%u\n", This
, ref
);
106 static ULONG WINAPI
IDirectPlay8AddressImpl_Release(IDirectPlay8Address
*iface
)
108 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
109 ULONG ref
= InterlockedDecrement(&This
->ref
);
111 TRACE("(%p) ref=%u\n", This
, ref
);
115 struct component
*entry
, *entry2
;
117 LIST_FOR_EACH_ENTRY_SAFE(entry
, entry2
, &This
->components
, struct component
, entry
)
121 case DPNA_DATATYPE_STRING
:
122 heap_free(entry
->data
.string
);
124 case DPNA_DATATYPE_STRING_ANSI
:
125 heap_free(entry
->data
.ansi
);
127 case DPNA_DATATYPE_BINARY
:
128 heap_free(entry
->data
.binary
);
132 HeapFree(GetProcessHeap(), 0, entry
);
135 HeapFree(GetProcessHeap(), 0, This
);
140 /* returns name of given GUID */
141 static const char *debugstr_SP(const GUID
*id
) {
142 static const guid_info guids
[] = {
145 GE(CLSID_DP8SP_TCPIP
),
146 GE(CLSID_DP8SP_SERIAL
),
147 GE(CLSID_DP8SP_MODEM
)
151 if (!id
) return "(null)";
153 for (i
= 0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++) {
154 if (IsEqualGUID(id
, guids
[i
].guid
))
155 return guids
[i
].name
;
157 /* if we didn't find it, act like standard debugstr_guid */
158 return debugstr_guid(id
);
161 /* IDirectPlay8Address Interface follow: */
163 static HRESULT WINAPI
IDirectPlay8AddressImpl_BuildFromURLW(IDirectPlay8Address
*iface
,
164 WCHAR
*pwszSourceURL
)
166 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
167 TRACE("(%p, %s): stub\n", This
, debugstr_w(pwszSourceURL
));
171 static HRESULT WINAPI
IDirectPlay8AddressImpl_BuildFromURLA(IDirectPlay8Address
*iface
,
174 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
175 TRACE("(%p, %s): stub\n", This
, pszSourceURL
);
179 static HRESULT WINAPI
IDirectPlay8AddressImpl_Duplicate(IDirectPlay8Address
*iface
,
180 IDirectPlay8Address
**ppdpaNewAddress
)
182 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
183 IDirectPlay8Address
*dup
;
186 TRACE("(%p, %p)\n", This
, ppdpaNewAddress
);
191 hr
= DPNET_CreateDirectPlay8Address(NULL
, NULL
, &IID_IDirectPlay8Address
, (LPVOID
*)&dup
);
194 IDirectPlay8AddressImpl
*DupThis
= impl_from_IDirectPlay8Address(dup
);
195 struct component
*entry
;
197 DupThis
->SP_guid
= This
->SP_guid
;
198 DupThis
->init
= This
->init
;
200 LIST_FOR_EACH_ENTRY(entry
, &This
->components
, struct component
, entry
)
202 hr
= IDirectPlay8Address_AddComponent(dup
, entry
->name
, &entry
->data
, entry
->size
, entry
->type
);
204 ERR("Failed to copy component: %s - 0x%08x\n", debugstr_w(entry
->name
), hr
);
207 *ppdpaNewAddress
= dup
;
213 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetEqual(IDirectPlay8Address
*iface
,
214 IDirectPlay8Address
*pdpaAddress
)
216 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
217 TRACE("(%p, %p): stub\n", This
, pdpaAddress
);
221 static HRESULT WINAPI
IDirectPlay8AddressImpl_IsEqual(IDirectPlay8Address
*iface
,
222 IDirectPlay8Address
*pdpaAddress
)
224 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
225 TRACE("(%p, %p): stub\n", This
, pdpaAddress
);
229 static HRESULT WINAPI
IDirectPlay8AddressImpl_Clear(IDirectPlay8Address
*iface
)
231 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
232 TRACE("(%p): stub\n", This
);
236 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetURLW(IDirectPlay8Address
*iface
, WCHAR
*pwszURL
,
239 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
240 TRACE("(%p): stub\n", This
);
244 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address
*iface
, CHAR
*pszURL
,
247 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
248 TRACE("(%p): stub\n", This
);
252 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address
*iface
, GUID
*pguidSP
)
254 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
256 TRACE("(%p, %p)\n", iface
, pguidSP
);
259 return DPNERR_INVALIDPOINTER
;
262 return DPNERR_DOESNOTEXIST
;
264 *pguidSP
= This
->SP_guid
;
268 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetUserData(IDirectPlay8Address
*iface
,
269 void *pvUserData
, DWORD
*pdwBufferSize
)
271 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
272 TRACE("(%p): stub\n", This
);
276 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetSP(IDirectPlay8Address
*iface
,
277 const GUID
*const pguidSP
)
279 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
281 TRACE("(%p, %s)\n", iface
, debugstr_SP(pguidSP
));
284 return DPNERR_INVALIDPOINTER
;
287 This
->SP_guid
= *pguidSP
;
289 IDirectPlay8Address_AddComponent(iface
, DPNA_KEY_PROVIDER
, &This
->SP_guid
, sizeof(GUID
), DPNA_DATATYPE_GUID
);
294 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetUserData(IDirectPlay8Address
*iface
,
295 const void *const pvUserData
, const DWORD dwDataSize
)
297 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
298 TRACE("(%p): stub\n", This
);
302 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetNumComponents(IDirectPlay8Address
*iface
,
303 DWORD
*pdwNumComponents
)
305 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
306 TRACE("(%p): stub\n", This
);
308 if(!pdwNumComponents
)
309 return DPNERR_INVALIDPOINTER
;
311 *pdwNumComponents
= list_count(&This
->components
);
316 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetComponentByName(IDirectPlay8Address
*iface
,
317 const WCHAR
*const pwszName
, void *pvBuffer
, DWORD
*pdwBufferSize
, DWORD
*pdwDataType
)
319 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
320 struct component
*entry
;
322 TRACE("(%p)->(%p %p %p %p)\n", This
, pwszName
, pvBuffer
, pdwBufferSize
, pdwDataType
);
324 if(!pwszName
|| !pdwBufferSize
|| !pdwDataType
|| (!pvBuffer
&& pdwBufferSize
))
327 LIST_FOR_EACH_ENTRY(entry
, &This
->components
, struct component
, entry
)
329 if (lstrcmpW(pwszName
, entry
->name
) == 0)
331 TRACE("Found %s\n", debugstr_w(pwszName
));
333 if(*pdwBufferSize
< entry
->size
)
335 *pdwBufferSize
= entry
->size
;
336 return DPNERR_BUFFERTOOSMALL
;
339 *pdwBufferSize
= entry
->size
;
340 *pdwDataType
= entry
->type
;
344 case DPNA_DATATYPE_DWORD
:
345 memcpy(pvBuffer
, &entry
->data
.value
, sizeof(DWORD
));
347 case DPNA_DATATYPE_GUID
:
348 memcpy(pvBuffer
, &entry
->data
.guid
, sizeof(GUID
));
350 case DPNA_DATATYPE_STRING
:
351 memcpy(pvBuffer
, &entry
->data
.string
, entry
->size
);
353 case DPNA_DATATYPE_STRING_ANSI
:
354 memcpy(pvBuffer
, &entry
->data
.ansi
, entry
->size
);
356 case DPNA_DATATYPE_BINARY
:
357 memcpy(pvBuffer
, &entry
->data
.binary
, entry
->size
);
365 return DPNERR_DOESNOTEXIST
;
368 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetComponentByIndex(IDirectPlay8Address
*iface
,
369 const DWORD dwComponentID
, WCHAR
*pwszName
, DWORD
*pdwNameLen
, void *pvBuffer
,
370 DWORD
*pdwBufferSize
, DWORD
*pdwDataType
)
372 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
373 TRACE("(%p): stub\n", This
);
377 static HRESULT WINAPI
IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address
*iface
,
378 const WCHAR
*const pwszName
, const void* const lpvData
, const DWORD dwDataSize
,
379 const DWORD dwDataType
)
381 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
382 struct component
*entry
;
385 TRACE("(%p, %s, %p, %u, %x): stub\n", This
, debugstr_w(pwszName
), lpvData
, dwDataSize
, dwDataType
);
388 return DPNERR_INVALIDPOINTER
;
390 LIST_FOR_EACH_ENTRY(entry
, &This
->components
, struct component
, entry
)
392 if (lstrcmpW(pwszName
, entry
->name
) == 0)
394 TRACE("Found %s\n", debugstr_w(pwszName
));
403 /* Create a new one */
404 entry
= heap_alloc(sizeof(struct component
));
405 entry
->name
= heap_strdupW(pwszName
);
406 entry
->type
= dwDataType
;
408 list_add_tail(&This
->components
, &entry
->entry
);
413 case DPNA_DATATYPE_DWORD
:
414 if (sizeof(DWORD
) != dwDataSize
)
415 return DPNERR_INVALIDPARAM
;
417 entry
->data
.value
= *(DWORD
*)lpvData
;
418 TRACE("(%p, %u): DWORD Type -> %u\n", lpvData
, dwDataSize
, *(const DWORD
*) lpvData
);
420 case DPNA_DATATYPE_GUID
:
421 if (sizeof(GUID
) != dwDataSize
)
422 return DPNERR_INVALIDPARAM
;
424 entry
->data
.guid
= *(GUID
*)lpvData
;
425 TRACE("(%p, %u): GUID Type -> %s\n", lpvData
, dwDataSize
, debugstr_guid(lpvData
));
427 case DPNA_DATATYPE_STRING
:
428 heap_free(entry
->data
.string
);
430 entry
->data
.string
= heap_strdupW((WCHAR
*)lpvData
);
431 TRACE("(%p, %u): STRING Type -> %s\n", lpvData
, dwDataSize
, debugstr_w((WCHAR
*)lpvData
));
433 case DPNA_DATATYPE_STRING_ANSI
:
434 heap_free(entry
->data
.ansi
);
436 entry
->data
.ansi
= heap_strdupA((CHAR
*)lpvData
);
437 TRACE("(%p, %u): ANSI STRING Type -> %s\n", lpvData
, dwDataSize
, (const CHAR
*) lpvData
);
439 case DPNA_DATATYPE_BINARY
:
440 heap_free(entry
->data
.binary
);
442 entry
->data
.binary
= heap_alloc(dwDataSize
);
443 memcpy(entry
->data
.binary
, lpvData
, dwDataSize
);
444 TRACE("(%p, %u): BINARY Type\n", lpvData
, dwDataSize
);
448 entry
->size
= dwDataSize
;
453 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address
*iface
, GUID
*pDevGuid
) {
454 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
455 TRACE("(%p): stub\n", This
);
459 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetDevice(IDirectPlay8Address
*iface
,
460 const GUID
*const devGuid
)
462 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
463 TRACE("(%p, %s): stub\n", This
, debugstr_guid(devGuid
));
467 static HRESULT WINAPI
IDirectPlay8AddressImpl_BuildFromDirectPlay4Address(IDirectPlay8Address
*iface
,
468 void *pvAddress
, DWORD dwDataSize
)
470 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
471 TRACE("(%p): stub\n", This
);
475 static const IDirectPlay8AddressVtbl DirectPlay8Address_Vtbl
=
477 IDirectPlay8AddressImpl_QueryInterface
,
478 IDirectPlay8AddressImpl_AddRef
,
479 IDirectPlay8AddressImpl_Release
,
480 IDirectPlay8AddressImpl_BuildFromURLW
,
481 IDirectPlay8AddressImpl_BuildFromURLA
,
482 IDirectPlay8AddressImpl_Duplicate
,
483 IDirectPlay8AddressImpl_SetEqual
,
484 IDirectPlay8AddressImpl_IsEqual
,
485 IDirectPlay8AddressImpl_Clear
,
486 IDirectPlay8AddressImpl_GetURLW
,
487 IDirectPlay8AddressImpl_GetURLA
,
488 IDirectPlay8AddressImpl_GetSP
,
489 IDirectPlay8AddressImpl_GetUserData
,
490 IDirectPlay8AddressImpl_SetSP
,
491 IDirectPlay8AddressImpl_SetUserData
,
492 IDirectPlay8AddressImpl_GetNumComponents
,
493 IDirectPlay8AddressImpl_GetComponentByName
,
494 IDirectPlay8AddressImpl_GetComponentByIndex
,
495 IDirectPlay8AddressImpl_AddComponent
,
496 IDirectPlay8AddressImpl_GetDevice
,
497 IDirectPlay8AddressImpl_SetDevice
,
498 IDirectPlay8AddressImpl_BuildFromDirectPlay4Address
501 HRESULT
DPNET_CreateDirectPlay8Address(IClassFactory
*iface
, IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppobj
)
503 IDirectPlay8AddressImpl
* client
;
506 TRACE("(%p, %s, %p)\n", pUnkOuter
, debugstr_guid(riid
), ppobj
);
510 client
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectPlay8AddressImpl
));
512 return E_OUTOFMEMORY
;
514 client
->IDirectPlay8Address_iface
.lpVtbl
= &DirectPlay8Address_Vtbl
;
517 list_init(&client
->components
);
519 ret
= IDirectPlay8AddressImpl_QueryInterface(&client
->IDirectPlay8Address_iface
, riid
, ppobj
);
520 IDirectPlay8AddressImpl_Release(&client
->IDirectPlay8Address_iface
);