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 TRACE("(%p): stub\n", This
);
324 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetComponentByIndex(IDirectPlay8Address
*iface
,
325 const DWORD dwComponentID
, WCHAR
*pwszName
, DWORD
*pdwNameLen
, void *pvBuffer
,
326 DWORD
*pdwBufferSize
, DWORD
*pdwDataType
)
328 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
329 TRACE("(%p): stub\n", This
);
333 static HRESULT WINAPI
IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address
*iface
,
334 const WCHAR
*const pwszName
, const void* const lpvData
, const DWORD dwDataSize
,
335 const DWORD dwDataType
)
337 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
338 struct component
*entry
;
341 TRACE("(%p, %s, %p, %u, %x): stub\n", This
, debugstr_w(pwszName
), lpvData
, dwDataSize
, dwDataType
);
344 return DPNERR_INVALIDPOINTER
;
346 LIST_FOR_EACH_ENTRY(entry
, &This
->components
, struct component
, entry
)
348 if (lstrcmpW(pwszName
, entry
->name
) == 0)
350 TRACE("Found %s\n", debugstr_w(pwszName
));
359 /* Create a new one */
360 entry
= heap_alloc(sizeof(struct component
));
361 entry
->name
= heap_strdupW(pwszName
);
362 entry
->type
= dwDataType
;
364 list_add_tail(&This
->components
, &entry
->entry
);
367 entry
->size
= dwDataSize
;
370 case DPNA_DATATYPE_DWORD
:
371 if (sizeof(DWORD
) != dwDataSize
)
372 return DPNERR_INVALIDPARAM
;
374 entry
->data
.value
= *(DWORD
*)lpvData
;
375 TRACE("(%p, %u): DWORD Type -> %u\n", lpvData
, dwDataSize
, *(const DWORD
*) lpvData
);
377 case DPNA_DATATYPE_GUID
:
378 if (sizeof(GUID
) != dwDataSize
)
379 return DPNERR_INVALIDPARAM
;
381 entry
->data
.guid
= *(GUID
*)lpvData
;
382 TRACE("(%p, %u): GUID Type -> %s\n", lpvData
, dwDataSize
, debugstr_guid(lpvData
));
384 case DPNA_DATATYPE_STRING
:
385 heap_free(entry
->data
.string
);
387 entry
->data
.string
= heap_strdupW((WCHAR
*)lpvData
);
388 TRACE("(%p, %u): STRING Type -> %s\n", lpvData
, dwDataSize
, debugstr_w((WCHAR
*)lpvData
));
390 case DPNA_DATATYPE_STRING_ANSI
:
391 heap_free(entry
->data
.ansi
);
393 entry
->data
.ansi
= heap_strdupA((CHAR
*)lpvData
);
394 TRACE("(%p, %u): ANSI STRING Type -> %s\n", lpvData
, dwDataSize
, (const CHAR
*) lpvData
);
396 case DPNA_DATATYPE_BINARY
:
397 heap_free(entry
->data
.binary
);
399 entry
->data
.binary
= heap_alloc(dwDataSize
);
400 memcpy(entry
->data
.binary
, lpvData
, dwDataSize
);
401 TRACE("(%p, %u): BINARY Type\n", lpvData
, dwDataSize
);
408 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address
*iface
, GUID
*pDevGuid
) {
409 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
410 TRACE("(%p): stub\n", This
);
414 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetDevice(IDirectPlay8Address
*iface
,
415 const GUID
*const devGuid
)
417 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
418 TRACE("(%p, %s): stub\n", This
, debugstr_guid(devGuid
));
422 static HRESULT WINAPI
IDirectPlay8AddressImpl_BuildFromDirectPlay4Address(IDirectPlay8Address
*iface
,
423 void *pvAddress
, DWORD dwDataSize
)
425 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
426 TRACE("(%p): stub\n", This
);
430 static const IDirectPlay8AddressVtbl DirectPlay8Address_Vtbl
=
432 IDirectPlay8AddressImpl_QueryInterface
,
433 IDirectPlay8AddressImpl_AddRef
,
434 IDirectPlay8AddressImpl_Release
,
435 IDirectPlay8AddressImpl_BuildFromURLW
,
436 IDirectPlay8AddressImpl_BuildFromURLA
,
437 IDirectPlay8AddressImpl_Duplicate
,
438 IDirectPlay8AddressImpl_SetEqual
,
439 IDirectPlay8AddressImpl_IsEqual
,
440 IDirectPlay8AddressImpl_Clear
,
441 IDirectPlay8AddressImpl_GetURLW
,
442 IDirectPlay8AddressImpl_GetURLA
,
443 IDirectPlay8AddressImpl_GetSP
,
444 IDirectPlay8AddressImpl_GetUserData
,
445 IDirectPlay8AddressImpl_SetSP
,
446 IDirectPlay8AddressImpl_SetUserData
,
447 IDirectPlay8AddressImpl_GetNumComponents
,
448 IDirectPlay8AddressImpl_GetComponentByName
,
449 IDirectPlay8AddressImpl_GetComponentByIndex
,
450 IDirectPlay8AddressImpl_AddComponent
,
451 IDirectPlay8AddressImpl_GetDevice
,
452 IDirectPlay8AddressImpl_SetDevice
,
453 IDirectPlay8AddressImpl_BuildFromDirectPlay4Address
456 HRESULT
DPNET_CreateDirectPlay8Address(IClassFactory
*iface
, IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppobj
)
458 IDirectPlay8AddressImpl
* client
;
461 TRACE("(%p, %s, %p)\n", pUnkOuter
, debugstr_guid(riid
), ppobj
);
465 client
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectPlay8AddressImpl
));
467 return E_OUTOFMEMORY
;
469 client
->IDirectPlay8Address_iface
.lpVtbl
= &DirectPlay8Address_Vtbl
;
472 list_init(&client
->components
);
474 ret
= IDirectPlay8AddressImpl_QueryInterface(&client
->IDirectPlay8Address_iface
, riid
, ppobj
);
475 IDirectPlay8AddressImpl_Release(&client
->IDirectPlay8Address_iface
);