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 void *heap_realloc(void *mem
, size_t len
)
49 return HeapReAlloc( GetProcessHeap(), 0, mem
, len
);
52 static inline BOOL
heap_free(void *mem
)
54 return HeapFree(GetProcessHeap(), 0, mem
);
57 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
64 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
65 ret
= heap_alloc(size
);
67 memcpy(ret
, str
, size
);
73 static char *heap_strdupA( const char *str
)
77 if (!str
) return NULL
;
78 if ((ret
= HeapAlloc( GetProcessHeap(), 0, strlen(str
) + 1 ))) strcpy( ret
, str
);
82 static BOOL
add_component(IDirectPlay8AddressImpl
*This
, struct component
*item
)
84 if(This
->comp_count
== This
->comp_array_size
)
86 struct component
**temp
;
88 temp
= heap_realloc(This
->components
, sizeof(*temp
) * This
->comp_array_size
* 2 );
94 This
->comp_array_size
*= 2;
95 This
->components
= temp
;
98 This
->components
[This
->comp_count
] = item
;
104 static inline IDirectPlay8AddressImpl
*impl_from_IDirectPlay8Address(IDirectPlay8Address
*iface
)
106 return CONTAINING_RECORD(iface
, IDirectPlay8AddressImpl
, IDirectPlay8Address_iface
);
109 /* IDirectPlay8Address IUnknown parts follow: */
110 static HRESULT WINAPI
IDirectPlay8AddressImpl_QueryInterface(IDirectPlay8Address
*iface
,
111 REFIID riid
, void **ppv
)
113 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IDirectPlay8Address
)) {
114 IUnknown_AddRef(iface
);
119 WARN("(%p)->(%s,%p),not found\n", iface
, debugstr_guid(riid
), ppv
);
120 return E_NOINTERFACE
;
123 static ULONG WINAPI
IDirectPlay8AddressImpl_AddRef(IDirectPlay8Address
*iface
)
125 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
126 ULONG ref
= InterlockedIncrement(&This
->ref
);
128 TRACE("(%p) ref=%u\n", This
, ref
);
133 static ULONG WINAPI
IDirectPlay8AddressImpl_Release(IDirectPlay8Address
*iface
)
135 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
136 ULONG ref
= InterlockedDecrement(&This
->ref
);
138 TRACE("(%p) ref=%u\n", This
, ref
);
142 struct component
*entry
;
145 for(i
=0; i
< This
->comp_count
; i
++)
147 entry
= This
->components
[i
];
151 case DPNA_DATATYPE_STRING
:
152 heap_free(entry
->data
.string
);
154 case DPNA_DATATYPE_STRING_ANSI
:
155 heap_free(entry
->data
.ansi
);
157 case DPNA_DATATYPE_BINARY
:
158 heap_free(entry
->data
.binary
);
165 heap_free(This
->components
);
171 /* returns name of given GUID */
172 static const char *debugstr_SP(const GUID
*id
) {
173 static const guid_info guids
[] = {
176 GE(CLSID_DP8SP_TCPIP
),
177 GE(CLSID_DP8SP_SERIAL
),
178 GE(CLSID_DP8SP_MODEM
)
182 if (!id
) return "(null)";
184 for (i
= 0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++) {
185 if (IsEqualGUID(id
, guids
[i
].guid
))
186 return guids
[i
].name
;
188 /* if we didn't find it, act like standard debugstr_guid */
189 return debugstr_guid(id
);
192 /* IDirectPlay8Address Interface follow: */
194 static HRESULT WINAPI
IDirectPlay8AddressImpl_BuildFromURLW(IDirectPlay8Address
*iface
,
195 WCHAR
*pwszSourceURL
)
197 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
198 TRACE("(%p, %s): stub\n", This
, debugstr_w(pwszSourceURL
));
202 static HRESULT WINAPI
IDirectPlay8AddressImpl_BuildFromURLA(IDirectPlay8Address
*iface
,
205 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
206 TRACE("(%p, %s): stub\n", This
, pszSourceURL
);
210 static HRESULT WINAPI
IDirectPlay8AddressImpl_Duplicate(IDirectPlay8Address
*iface
,
211 IDirectPlay8Address
**ppdpaNewAddress
)
213 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
214 IDirectPlay8Address
*dup
;
217 TRACE("(%p, %p)\n", This
, ppdpaNewAddress
);
222 hr
= DPNET_CreateDirectPlay8Address(NULL
, NULL
, &IID_IDirectPlay8Address
, (LPVOID
*)&dup
);
225 IDirectPlay8AddressImpl
*DupThis
= impl_from_IDirectPlay8Address(dup
);
228 DupThis
->SP_guid
= This
->SP_guid
;
229 DupThis
->init
= This
->init
;
231 for(i
=0; i
< This
->comp_count
; i
++)
233 struct component
*entry
= This
->components
[i
];
235 hr
= IDirectPlay8Address_AddComponent(dup
, entry
->name
, &entry
->data
, entry
->size
, entry
->type
);
237 ERR("Failed to copy component: %s - 0x%08x\n", debugstr_w(entry
->name
), hr
);
240 *ppdpaNewAddress
= dup
;
246 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetEqual(IDirectPlay8Address
*iface
,
247 IDirectPlay8Address
*pdpaAddress
)
249 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
250 TRACE("(%p, %p): stub\n", This
, pdpaAddress
);
254 static HRESULT WINAPI
IDirectPlay8AddressImpl_IsEqual(IDirectPlay8Address
*iface
,
255 IDirectPlay8Address
*pdpaAddress
)
257 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
258 TRACE("(%p, %p): stub\n", This
, pdpaAddress
);
262 static HRESULT WINAPI
IDirectPlay8AddressImpl_Clear(IDirectPlay8Address
*iface
)
264 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
265 TRACE("(%p): stub\n", This
);
269 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetURLW(IDirectPlay8Address
*iface
, WCHAR
*pwszURL
,
272 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
273 TRACE("(%p): stub\n", This
);
277 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address
*iface
, CHAR
*pszURL
,
280 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
281 TRACE("(%p): stub\n", This
);
285 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address
*iface
, GUID
*pguidSP
)
287 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
289 TRACE("(%p, %p)\n", iface
, pguidSP
);
292 return DPNERR_INVALIDPOINTER
;
295 return DPNERR_DOESNOTEXIST
;
297 *pguidSP
= This
->SP_guid
;
301 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetUserData(IDirectPlay8Address
*iface
,
302 void *pvUserData
, DWORD
*pdwBufferSize
)
304 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
305 TRACE("(%p): stub\n", This
);
309 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetSP(IDirectPlay8Address
*iface
,
310 const GUID
*const pguidSP
)
312 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
314 TRACE("(%p, %s)\n", iface
, debugstr_SP(pguidSP
));
317 return DPNERR_INVALIDPOINTER
;
320 This
->SP_guid
= *pguidSP
;
322 IDirectPlay8Address_AddComponent(iface
, DPNA_KEY_PROVIDER
, &This
->SP_guid
, sizeof(GUID
), DPNA_DATATYPE_GUID
);
327 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetUserData(IDirectPlay8Address
*iface
,
328 const void *const pvUserData
, const DWORD dwDataSize
)
330 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
331 TRACE("(%p): stub\n", This
);
335 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetNumComponents(IDirectPlay8Address
*iface
,
336 DWORD
*pdwNumComponents
)
338 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
339 TRACE("(%p): stub\n", This
);
341 if(!pdwNumComponents
)
342 return DPNERR_INVALIDPOINTER
;
344 *pdwNumComponents
= This
->comp_count
;
349 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetComponentByName(IDirectPlay8Address
*iface
,
350 const WCHAR
*const pwszName
, void *pvBuffer
, DWORD
*pdwBufferSize
, DWORD
*pdwDataType
)
352 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
353 struct component
*entry
;
356 TRACE("(%p)->(%p %p %p %p)\n", This
, pwszName
, pvBuffer
, pdwBufferSize
, pdwDataType
);
358 if(!pwszName
|| !pdwBufferSize
|| !pdwDataType
|| (!pvBuffer
&& pdwBufferSize
))
361 for(i
=0; i
< This
->comp_count
; i
++)
363 entry
= This
->components
[i
];
365 if (lstrcmpW(pwszName
, entry
->name
) == 0)
367 TRACE("Found %s\n", debugstr_w(pwszName
));
369 if(*pdwBufferSize
< entry
->size
)
371 *pdwBufferSize
= entry
->size
;
372 return DPNERR_BUFFERTOOSMALL
;
375 *pdwBufferSize
= entry
->size
;
376 *pdwDataType
= entry
->type
;
380 case DPNA_DATATYPE_DWORD
:
381 memcpy(pvBuffer
, &entry
->data
.value
, sizeof(DWORD
));
383 case DPNA_DATATYPE_GUID
:
384 memcpy(pvBuffer
, &entry
->data
.guid
, sizeof(GUID
));
386 case DPNA_DATATYPE_STRING
:
387 memcpy(pvBuffer
, entry
->data
.string
, entry
->size
);
389 case DPNA_DATATYPE_STRING_ANSI
:
390 memcpy(pvBuffer
, entry
->data
.ansi
, entry
->size
);
392 case DPNA_DATATYPE_BINARY
:
393 memcpy(pvBuffer
, entry
->data
.binary
, entry
->size
);
401 return DPNERR_DOESNOTEXIST
;
404 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetComponentByIndex(IDirectPlay8Address
*iface
,
405 const DWORD dwComponentID
, WCHAR
*pwszName
, DWORD
*pdwNameLen
, void *pvBuffer
,
406 DWORD
*pdwBufferSize
, DWORD
*pdwDataType
)
408 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
409 TRACE("(%p): stub\n", This
);
413 static HRESULT WINAPI
IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address
*iface
,
414 const WCHAR
*const pwszName
, const void* const lpvData
, const DWORD dwDataSize
,
415 const DWORD dwDataType
)
417 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
418 struct component
*entry
;
422 TRACE("(%p, %s, %p, %u, %x)\n", This
, debugstr_w(pwszName
), lpvData
, dwDataSize
, dwDataType
);
425 return DPNERR_INVALIDPOINTER
;
429 case DPNA_DATATYPE_DWORD
:
430 if (sizeof(DWORD
) != dwDataSize
)
432 WARN("Invalid DWORD size, returning DPNERR_INVALIDPARAM\n");
433 return DPNERR_INVALIDPARAM
;
436 case DPNA_DATATYPE_GUID
:
437 if (sizeof(GUID
) != dwDataSize
)
439 WARN("Invalid GUID size, returning DPNERR_INVALIDPARAM\n");
440 return DPNERR_INVALIDPARAM
;
443 case DPNA_DATATYPE_STRING
:
444 if (((strlenW((WCHAR
*)lpvData
)+1)*sizeof(WCHAR
)) != dwDataSize
)
446 WARN("Invalid STRING size, returning DPNERR_INVALIDPARAM\n");
447 return DPNERR_INVALIDPARAM
;
450 case DPNA_DATATYPE_STRING_ANSI
:
451 if ((strlen((const CHAR
*)lpvData
)+1) != dwDataSize
)
453 WARN("Invalid ASCII size, returning DPNERR_INVALIDPARAM\n");
454 return DPNERR_INVALIDPARAM
;
459 for(i
=0; i
< This
->comp_count
; i
++)
461 entry
= This
->components
[i
];
463 if (lstrcmpW(pwszName
, entry
->name
) == 0)
465 TRACE("Found %s\n", debugstr_w(pwszName
));
468 if(entry
->type
== DPNA_DATATYPE_STRING_ANSI
)
469 heap_free(entry
->data
.ansi
);
470 else if(entry
->type
== DPNA_DATATYPE_STRING
)
471 heap_free(entry
->data
.string
);
472 else if(entry
->type
== DPNA_DATATYPE_BINARY
)
473 heap_free(entry
->data
.binary
);
481 /* Create a new one */
482 entry
= heap_alloc(sizeof(struct component
));
484 return E_OUTOFMEMORY
;
486 entry
->name
= heap_strdupW(pwszName
);
490 return E_OUTOFMEMORY
;
493 if(!add_component(This
, entry
))
495 heap_free(entry
->name
);
497 return E_OUTOFMEMORY
;
503 case DPNA_DATATYPE_DWORD
:
504 entry
->data
.value
= *(DWORD
*)lpvData
;
505 TRACE("(%p, %u): DWORD Type -> %u\n", lpvData
, dwDataSize
, *(const DWORD
*) lpvData
);
507 case DPNA_DATATYPE_GUID
:
508 entry
->data
.guid
= *(GUID
*)lpvData
;
509 TRACE("(%p, %u): GUID Type -> %s\n", lpvData
, dwDataSize
, debugstr_guid(lpvData
));
511 case DPNA_DATATYPE_STRING
:
512 entry
->data
.string
= heap_strdupW((WCHAR
*)lpvData
);
513 TRACE("(%p, %u): STRING Type -> %s\n", lpvData
, dwDataSize
, debugstr_w((WCHAR
*)lpvData
));
515 case DPNA_DATATYPE_STRING_ANSI
:
516 entry
->data
.ansi
= heap_strdupA((CHAR
*)lpvData
);
517 TRACE("(%p, %u): ANSI STRING Type -> %s\n", lpvData
, dwDataSize
, (const CHAR
*) lpvData
);
519 case DPNA_DATATYPE_BINARY
:
520 entry
->data
.binary
= heap_alloc(dwDataSize
);
521 memcpy(entry
->data
.binary
, lpvData
, dwDataSize
);
522 TRACE("(%p, %u): BINARY Type\n", lpvData
, dwDataSize
);
526 entry
->type
= dwDataType
;
527 entry
->size
= dwDataSize
;
532 static HRESULT WINAPI
IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address
*iface
, GUID
*pDevGuid
) {
533 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
534 TRACE("(%p): stub\n", This
);
538 static HRESULT WINAPI
IDirectPlay8AddressImpl_SetDevice(IDirectPlay8Address
*iface
,
539 const GUID
*const devGuid
)
541 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
542 TRACE("(%p, %s): stub\n", This
, debugstr_guid(devGuid
));
546 static HRESULT WINAPI
IDirectPlay8AddressImpl_BuildFromDirectPlay4Address(IDirectPlay8Address
*iface
,
547 void *pvAddress
, DWORD dwDataSize
)
549 IDirectPlay8AddressImpl
*This
= impl_from_IDirectPlay8Address(iface
);
550 TRACE("(%p): stub\n", This
);
554 static const IDirectPlay8AddressVtbl DirectPlay8Address_Vtbl
=
556 IDirectPlay8AddressImpl_QueryInterface
,
557 IDirectPlay8AddressImpl_AddRef
,
558 IDirectPlay8AddressImpl_Release
,
559 IDirectPlay8AddressImpl_BuildFromURLW
,
560 IDirectPlay8AddressImpl_BuildFromURLA
,
561 IDirectPlay8AddressImpl_Duplicate
,
562 IDirectPlay8AddressImpl_SetEqual
,
563 IDirectPlay8AddressImpl_IsEqual
,
564 IDirectPlay8AddressImpl_Clear
,
565 IDirectPlay8AddressImpl_GetURLW
,
566 IDirectPlay8AddressImpl_GetURLA
,
567 IDirectPlay8AddressImpl_GetSP
,
568 IDirectPlay8AddressImpl_GetUserData
,
569 IDirectPlay8AddressImpl_SetSP
,
570 IDirectPlay8AddressImpl_SetUserData
,
571 IDirectPlay8AddressImpl_GetNumComponents
,
572 IDirectPlay8AddressImpl_GetComponentByName
,
573 IDirectPlay8AddressImpl_GetComponentByIndex
,
574 IDirectPlay8AddressImpl_AddComponent
,
575 IDirectPlay8AddressImpl_GetDevice
,
576 IDirectPlay8AddressImpl_SetDevice
,
577 IDirectPlay8AddressImpl_BuildFromDirectPlay4Address
580 HRESULT
DPNET_CreateDirectPlay8Address(IClassFactory
*iface
, IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppobj
)
582 IDirectPlay8AddressImpl
* client
;
585 TRACE("(%p, %s, %p)\n", pUnkOuter
, debugstr_guid(riid
), ppobj
);
589 client
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectPlay8AddressImpl
));
591 return E_OUTOFMEMORY
;
593 client
->IDirectPlay8Address_iface
.lpVtbl
= &DirectPlay8Address_Vtbl
;
595 client
->comp_array_size
= 4;
596 client
->components
= heap_alloc( sizeof(*client
->components
) * client
->comp_array_size
);
597 if(!client
->components
)
600 return E_OUTOFMEMORY
;
603 ret
= IDirectPlay8AddressImpl_QueryInterface(&client
->IDirectPlay8Address_iface
, riid
, ppobj
);
604 IDirectPlay8AddressImpl_Release(&client
->IDirectPlay8Address_iface
);