msxml3: Update pure_parser directive to avoid a deprecation warning.
[wine.git] / dlls / dpnet / address.c
blob2062bc465373903e8d247e0d9431dc6473ee412e
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 BOOL heap_free(void *mem)
49 return HeapFree(GetProcessHeap(), 0, mem);
52 static inline LPWSTR heap_strdupW(LPCWSTR str)
54 LPWSTR ret = NULL;
56 if(str) {
57 DWORD size;
59 size = (strlenW(str)+1)*sizeof(WCHAR);
60 ret = heap_alloc(size);
61 if(ret)
62 memcpy(ret, str, size);
65 return ret;
68 static char *heap_strdupA( const char *str )
70 char *ret;
72 if (!str) return NULL;
73 if ((ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 ))) strcpy( ret, str );
74 return ret;
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);
88 *ppv = iface;
89 return DPN_OK;
92 WARN("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ppv);
93 return E_NOINTERFACE;
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);
103 return 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);
113 if (!ref)
115 struct component *entry, *entry2;
117 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->components, struct component, entry)
119 switch(entry->type)
121 case DPNA_DATATYPE_STRING:
122 heap_free(entry->data.string);
123 break;
124 case DPNA_DATATYPE_STRING_ANSI:
125 heap_free(entry->data.ansi);
126 break;
127 case DPNA_DATATYPE_BINARY:
128 heap_free(entry->data.binary);
129 break;
132 HeapFree(GetProcessHeap(), 0, entry);
135 HeapFree(GetProcessHeap(), 0, This);
137 return ref;
140 /* returns name of given GUID */
141 static const char *debugstr_SP(const GUID *id) {
142 static const guid_info guids[] = {
143 /* CLSIDs */
144 GE(CLSID_DP8SP_IPX),
145 GE(CLSID_DP8SP_TCPIP),
146 GE(CLSID_DP8SP_SERIAL),
147 GE(CLSID_DP8SP_MODEM)
149 unsigned int i;
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));
168 return DPN_OK;
171 static HRESULT WINAPI IDirectPlay8AddressImpl_BuildFromURLA(IDirectPlay8Address *iface,
172 CHAR *pszSourceURL)
174 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
175 TRACE("(%p, %s): stub\n", This, pszSourceURL);
176 return DPN_OK;
179 static HRESULT WINAPI IDirectPlay8AddressImpl_Duplicate(IDirectPlay8Address *iface,
180 IDirectPlay8Address **ppdpaNewAddress)
182 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
183 IDirectPlay8Address *dup;
184 HRESULT hr;
186 TRACE("(%p, %p)\n", This, ppdpaNewAddress);
188 if(!ppdpaNewAddress)
189 return E_POINTER;
191 hr = DPNET_CreateDirectPlay8Address(NULL, NULL, &IID_IDirectPlay8Address, (LPVOID*)&dup);
192 if(hr == S_OK)
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);
203 if(hr != S_OK)
204 ERR("Failed to copy component: %s - 0x%08x\n", debugstr_w(entry->name), hr);
207 *ppdpaNewAddress = dup;
210 return hr;
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);
218 return DPN_OK;
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);
226 return DPN_OK;
229 static HRESULT WINAPI IDirectPlay8AddressImpl_Clear(IDirectPlay8Address *iface)
231 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
232 TRACE("(%p): stub\n", This);
233 return DPN_OK;
236 static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLW(IDirectPlay8Address *iface, WCHAR *pwszURL,
237 DWORD *pdwNumChars)
239 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
240 TRACE("(%p): stub\n", This);
241 return DPN_OK;
244 static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address *iface, CHAR *pszURL,
245 DWORD *pdwNumChars)
247 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
248 TRACE("(%p): stub\n", This);
249 return DPN_OK;
252 static HRESULT WINAPI IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address *iface, GUID *pguidSP)
254 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
256 TRACE("(%p, %p)\n", iface, pguidSP);
258 if(!pguidSP)
259 return DPNERR_INVALIDPOINTER;
261 if(!This->init)
262 return DPNERR_DOESNOTEXIST;
264 *pguidSP = This->SP_guid;
265 return DPN_OK;
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);
273 return DPN_OK;
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));
283 if(!pguidSP)
284 return DPNERR_INVALIDPOINTER;
286 This->init = TRUE;
287 This->SP_guid = *pguidSP;
289 IDirectPlay8Address_AddComponent(iface, DPNA_KEY_PROVIDER, &This->SP_guid, sizeof(GUID), DPNA_DATATYPE_GUID);
291 return DPN_OK;
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);
299 return DPN_OK;
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);
313 return DPN_OK;
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))
325 return E_POINTER;
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;
342 switch (entry->type)
344 case DPNA_DATATYPE_DWORD:
345 memcpy(pvBuffer, &entry->data.value, sizeof(DWORD));
346 break;
347 case DPNA_DATATYPE_GUID:
348 memcpy(pvBuffer, &entry->data.guid, sizeof(GUID));
349 break;
350 case DPNA_DATATYPE_STRING:
351 memcpy(pvBuffer, &entry->data.string, entry->size);
352 break;
353 case DPNA_DATATYPE_STRING_ANSI:
354 memcpy(pvBuffer, &entry->data.ansi, entry->size);
355 break;
356 case DPNA_DATATYPE_BINARY:
357 memcpy(pvBuffer, &entry->data.binary, entry->size);
358 break;
361 return S_OK;
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);
374 return DPN_OK;
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;
383 BOOL found = FALSE;
385 TRACE("(%p, %s, %p, %u, %x): stub\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
387 if (NULL == lpvData)
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));
395 found = TRUE;
397 break;
401 if(!found)
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);
411 switch (dwDataType)
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);
419 break;
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));
426 break;
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));
432 break;
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);
438 break;
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);
445 break;
448 entry->size = dwDataSize;
450 return DPN_OK;
453 static HRESULT WINAPI IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address *iface, GUID *pDevGuid) {
454 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
455 TRACE("(%p): stub\n", This);
456 return DPN_OK;
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));
464 return DPN_OK;
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);
472 return DPN_OK;
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;
504 HRESULT ret;
506 TRACE("(%p, %s, %p)\n", pUnkOuter, debugstr_guid(riid), ppobj);
508 *ppobj = NULL;
510 client = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectPlay8AddressImpl));
511 if (!client)
512 return E_OUTOFMEMORY;
514 client->IDirectPlay8Address_iface.lpVtbl = &DirectPlay8Address_Vtbl;
515 client->ref = 1;
517 list_init(&client->components);
519 ret = IDirectPlay8AddressImpl_QueryInterface(&client->IDirectPlay8Address_iface, riid, ppobj);
520 IDirectPlay8AddressImpl_Release(&client->IDirectPlay8Address_iface);
522 return ret;