server: Store the clipboard windows as full handles.
[wine.git] / dlls / dpnet / address.c
blob7e10136e2ddda17a10e922388ac1e367d373bbe9
1 /*
2 * DirectPlay8 Address
3 *
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
22 #include "config.h"
24 #include <stdarg.h>
26 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "objbase.h"
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
36 #include "dplay8.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)
59 LPWSTR ret = NULL;
61 if(str) {
62 DWORD size;
64 size = (strlenW(str)+1)*sizeof(WCHAR);
65 ret = heap_alloc(size);
66 if(ret)
67 memcpy(ret, str, size);
70 return ret;
73 static char *heap_strdupA( const char *str )
75 char *ret;
77 if (!str) return NULL;
78 if ((ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 ))) strcpy( ret, str );
79 return ret;
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 );
89 if(!temp)
91 return FALSE;
94 This->comp_array_size *= 2;
95 This->components = temp;
98 This->components[This->comp_count] = item;
99 This->comp_count++;
101 return TRUE;
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);
115 *ppv = iface;
116 return DPN_OK;
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);
130 return 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);
140 if (!ref)
142 struct component *entry;
143 DWORD i;
145 for(i=0; i < This->comp_count; i++)
147 entry = This->components[i];
149 switch(entry->type)
151 case DPNA_DATATYPE_STRING:
152 heap_free(entry->data.string);
153 break;
154 case DPNA_DATATYPE_STRING_ANSI:
155 heap_free(entry->data.ansi);
156 break;
157 case DPNA_DATATYPE_BINARY:
158 heap_free(entry->data.binary);
159 break;
162 heap_free(entry);
165 heap_free(This->components);
166 heap_free(This);
168 return ref;
171 /* returns name of given GUID */
172 static const char *debugstr_SP(const GUID *id) {
173 static const guid_info guids[] = {
174 /* CLSIDs */
175 GE(CLSID_DP8SP_IPX),
176 GE(CLSID_DP8SP_TCPIP),
177 GE(CLSID_DP8SP_SERIAL),
178 GE(CLSID_DP8SP_MODEM)
180 unsigned int i;
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));
199 return DPN_OK;
202 static HRESULT WINAPI IDirectPlay8AddressImpl_BuildFromURLA(IDirectPlay8Address *iface,
203 CHAR *pszSourceURL)
205 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
206 TRACE("(%p, %s): stub\n", This, pszSourceURL);
207 return DPN_OK;
210 static HRESULT WINAPI IDirectPlay8AddressImpl_Duplicate(IDirectPlay8Address *iface,
211 IDirectPlay8Address **ppdpaNewAddress)
213 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
214 IDirectPlay8Address *dup;
215 HRESULT hr;
217 TRACE("(%p, %p)\n", This, ppdpaNewAddress);
219 if(!ppdpaNewAddress)
220 return E_POINTER;
222 hr = DPNET_CreateDirectPlay8Address(NULL, NULL, &IID_IDirectPlay8Address, (LPVOID*)&dup);
223 if(hr == S_OK)
225 IDirectPlay8AddressImpl *DupThis = impl_from_IDirectPlay8Address(dup);
226 DWORD i;
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);
236 if(hr != S_OK)
237 ERR("Failed to copy component: %s - 0x%08x\n", debugstr_w(entry->name), hr);
240 *ppdpaNewAddress = dup;
243 return hr;
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);
251 return DPN_OK;
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);
259 return DPN_OK;
262 static HRESULT WINAPI IDirectPlay8AddressImpl_Clear(IDirectPlay8Address *iface)
264 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
265 TRACE("(%p): stub\n", This);
266 return DPN_OK;
269 static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLW(IDirectPlay8Address *iface, WCHAR *pwszURL,
270 DWORD *pdwNumChars)
272 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
273 TRACE("(%p): stub\n", This);
274 return DPN_OK;
277 static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address *iface, CHAR *pszURL,
278 DWORD *pdwNumChars)
280 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
281 TRACE("(%p): stub\n", This);
282 return DPN_OK;
285 static HRESULT WINAPI IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address *iface, GUID *pguidSP)
287 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
289 TRACE("(%p, %p)\n", iface, pguidSP);
291 if(!pguidSP)
292 return DPNERR_INVALIDPOINTER;
294 if(!This->init)
295 return DPNERR_DOESNOTEXIST;
297 *pguidSP = This->SP_guid;
298 return DPN_OK;
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);
306 return DPN_OK;
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));
316 if(!pguidSP)
317 return DPNERR_INVALIDPOINTER;
319 This->init = TRUE;
320 This->SP_guid = *pguidSP;
322 IDirectPlay8Address_AddComponent(iface, DPNA_KEY_PROVIDER, &This->SP_guid, sizeof(GUID), DPNA_DATATYPE_GUID);
324 return DPN_OK;
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);
332 return DPN_OK;
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;
346 return DPN_OK;
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;
354 DWORD i;
356 TRACE("(%p)->(%p %p %p %p)\n", This, pwszName, pvBuffer, pdwBufferSize, pdwDataType);
358 if(!pwszName || !pdwBufferSize || !pdwDataType || (!pvBuffer && pdwBufferSize))
359 return E_POINTER;
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;
378 switch (entry->type)
380 case DPNA_DATATYPE_DWORD:
381 memcpy(pvBuffer, &entry->data.value, sizeof(DWORD));
382 break;
383 case DPNA_DATATYPE_GUID:
384 memcpy(pvBuffer, &entry->data.guid, sizeof(GUID));
385 break;
386 case DPNA_DATATYPE_STRING:
387 memcpy(pvBuffer, entry->data.string, entry->size);
388 break;
389 case DPNA_DATATYPE_STRING_ANSI:
390 memcpy(pvBuffer, entry->data.ansi, entry->size);
391 break;
392 case DPNA_DATATYPE_BINARY:
393 memcpy(pvBuffer, entry->data.binary, entry->size);
394 break;
397 return S_OK;
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);
410 return DPN_OK;
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;
419 BOOL found = FALSE;
420 DWORD i;
422 TRACE("(%p, %s, %p, %u, %x)\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
424 if (NULL == lpvData)
425 return DPNERR_INVALIDPOINTER;
427 switch (dwDataType)
429 case DPNA_DATATYPE_DWORD:
430 if (sizeof(DWORD) != dwDataSize)
432 WARN("Invalid DWORD size, returning DPNERR_INVALIDPARAM\n");
433 return DPNERR_INVALIDPARAM;
435 break;
436 case DPNA_DATATYPE_GUID:
437 if (sizeof(GUID) != dwDataSize)
439 WARN("Invalid GUID size, returning DPNERR_INVALIDPARAM\n");
440 return DPNERR_INVALIDPARAM;
442 break;
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;
449 break;
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;
456 break;
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));
466 found = TRUE;
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);
475 break;
479 if(!found)
481 /* Create a new one */
482 entry = heap_alloc(sizeof(struct component));
483 if(!entry)
484 return E_OUTOFMEMORY;
486 entry->name = heap_strdupW(pwszName);
487 if(!entry->name)
489 heap_free(entry);
490 return E_OUTOFMEMORY;
493 if(!add_component(This, entry))
495 heap_free(entry->name);
496 heap_free(entry);
497 return E_OUTOFMEMORY;
501 switch (dwDataType)
503 case DPNA_DATATYPE_DWORD:
504 entry->data.value = *(DWORD*)lpvData;
505 TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
506 break;
507 case DPNA_DATATYPE_GUID:
508 entry->data.guid = *(GUID*)lpvData;
509 TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid(lpvData));
510 break;
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));
514 break;
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);
518 break;
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);
523 break;
526 entry->type = dwDataType;
527 entry->size = dwDataSize;
529 return DPN_OK;
532 static HRESULT WINAPI IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address *iface, GUID *pDevGuid) {
533 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
534 TRACE("(%p): stub\n", This);
535 return DPN_OK;
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));
543 return DPN_OK;
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);
551 return DPN_OK;
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;
583 HRESULT ret;
585 TRACE("(%p, %s, %p)\n", pUnkOuter, debugstr_guid(riid), ppobj);
587 *ppobj = NULL;
589 client = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectPlay8AddressImpl));
590 if (!client)
591 return E_OUTOFMEMORY;
593 client->IDirectPlay8Address_iface.lpVtbl = &DirectPlay8Address_Vtbl;
594 client->ref = 1;
595 client->comp_array_size = 4;
596 client->components = heap_alloc( sizeof(*client->components) * client->comp_array_size );
597 if(!client->components)
599 heap_free(client);
600 return E_OUTOFMEMORY;
603 ret = IDirectPlay8AddressImpl_QueryInterface(&client->IDirectPlay8Address_iface, riid, ppobj);
604 IDirectPlay8AddressImpl_Release(&client->IDirectPlay8Address_iface);
606 return ret;