msi: Free the user sid string.
[wine] / dlls / dpnet / address.c
1 /* 
2  * DirectPlay8 Address
3  * 
4  * Copyright 2004 Raphael Junqueira
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25
26 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "objbase.h"
32 #include "wine/debug.h"
33
34 #include "dplay8.h"
35 #include "dpnet_private.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
38
39 /* IDirectPlay8Address IUnknown parts follow: */
40 static HRESULT WINAPI IDirectPlay8AddressImpl_QueryInterface(PDIRECTPLAY8ADDRESS iface, REFIID riid, LPVOID *ppobj)
41 {
42     IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
43
44     if (IsEqualGUID(riid, &IID_IUnknown)
45         || IsEqualGUID(riid, &IID_IDirectPlay8Address)) {
46         IUnknown_AddRef(iface);
47         *ppobj = This;
48         return DPN_OK;
49     }
50
51     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
52     return E_NOINTERFACE;
53 }
54
55 static ULONG WINAPI IDirectPlay8AddressImpl_AddRef(PDIRECTPLAY8ADDRESS iface) {
56     IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
57     ULONG refCount = InterlockedIncrement(&This->ref);
58
59     TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
60
61     return refCount;
62 }
63
64 static ULONG WINAPI IDirectPlay8AddressImpl_Release(PDIRECTPLAY8ADDRESS iface) {
65     IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
66     ULONG refCount = InterlockedDecrement(&This->ref);
67
68     TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
69
70     if (!refCount) {
71         HeapFree(GetProcessHeap(), 0, This);
72     }
73     return refCount;
74 }
75
76 /* IDirectPlay8Address Interface follow: */
77
78 static HRESULT WINAPI IDirectPlay8AddressImpl_BuildFromURLW(PDIRECTPLAY8ADDRESS iface, WCHAR* pwszSourceURL) { 
79   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
80   TRACE("(%p, %s): stub\n", This, debugstr_w(pwszSourceURL));
81   return DPN_OK; 
82 }
83
84 static HRESULT WINAPI IDirectPlay8AddressImpl_BuildFromURLA(PDIRECTPLAY8ADDRESS iface, CHAR* pszSourceURL) { 
85   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
86   TRACE("(%p, %s): stub\n", This, pszSourceURL);
87   return DPN_OK; 
88 }
89
90 static HRESULT WINAPI IDirectPlay8AddressImpl_Duplicate(PDIRECTPLAY8ADDRESS iface, PDIRECTPLAY8ADDRESS* ppdpaNewAddress) { 
91   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
92   TRACE("(%p, %p): stub\n", This, ppdpaNewAddress);
93   return DPN_OK; 
94 }
95
96 static HRESULT WINAPI IDirectPlay8AddressImpl_SetEqual(PDIRECTPLAY8ADDRESS iface, PDIRECTPLAY8ADDRESS pdpaAddress) { 
97   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
98   TRACE("(%p, %p): stub\n", This, pdpaAddress);
99   return DPN_OK; 
100 }
101
102 static HRESULT WINAPI IDirectPlay8AddressImpl_IsEqual(PDIRECTPLAY8ADDRESS iface, PDIRECTPLAY8ADDRESS pdpaAddress) { 
103   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
104   TRACE("(%p, %p): stub\n", This, pdpaAddress);
105   return DPN_OK; 
106 }
107
108 static HRESULT WINAPI IDirectPlay8AddressImpl_Clear(PDIRECTPLAY8ADDRESS iface) { 
109   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
110   TRACE("(%p): stub\n", This);
111   return DPN_OK; 
112 }
113
114 static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLW(PDIRECTPLAY8ADDRESS iface, WCHAR* pwszURL, PDWORD pdwNumChars) { 
115   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
116   TRACE("(%p): stub\n", This);
117   return DPN_OK; 
118 }
119
120 static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLA(PDIRECTPLAY8ADDRESS iface, CHAR* pszURL, PDWORD pdwNumChars) { 
121   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
122   TRACE("(%p): stub\n", This);
123   return DPN_OK; 
124 }
125
126 static HRESULT WINAPI IDirectPlay8AddressImpl_GetSP(PDIRECTPLAY8ADDRESS iface, GUID* pguidSP) { 
127   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
128   TRACE("(%p, %p)\n", iface, pguidSP);
129   memcpy(pguidSP, &This->SP_guid, sizeof(GUID));
130   return DPN_OK; 
131 }
132
133 static HRESULT WINAPI IDirectPlay8AddressImpl_GetUserData(PDIRECTPLAY8ADDRESS iface, LPVOID pvUserData, PDWORD pdwBufferSize) { 
134   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
135   TRACE("(%p): stub\n", This);
136   return DPN_OK; 
137 }
138
139 static HRESULT WINAPI IDirectPlay8AddressImpl_SetSP(PDIRECTPLAY8ADDRESS iface, CONST GUID* CONST pguidSP) { 
140   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
141   TRACE("(%p, %s)\n", iface, debugstr_SP(pguidSP));
142   memcpy(&This->SP_guid, pguidSP, sizeof(GUID));
143   return DPN_OK; 
144 }
145
146 static HRESULT WINAPI IDirectPlay8AddressImpl_SetUserData(PDIRECTPLAY8ADDRESS iface, CONST void* CONST pvUserData, CONST DWORD dwDataSize) { 
147   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
148   TRACE("(%p): stub\n", This);
149   return DPN_OK; 
150 }
151
152 static HRESULT WINAPI IDirectPlay8AddressImpl_GetNumComponents(PDIRECTPLAY8ADDRESS iface, PDWORD pdwNumComponents) { 
153   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
154   TRACE("(%p): stub\n", This);
155   return DPN_OK; 
156 }
157
158 static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByName(PDIRECTPLAY8ADDRESS iface, CONST WCHAR* CONST pwszName, LPVOID pvBuffer, PDWORD pdwBufferSize, PDWORD pdwDataType) { 
159   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
160   TRACE("(%p): stub\n", This);
161   return DPN_OK; 
162 }
163
164 static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByIndex(PDIRECTPLAY8ADDRESS iface, CONST DWORD dwComponentID, WCHAR* pwszName, 
165                                                            PDWORD pdwNameLen, void* pvBuffer, PDWORD pdwBufferSize, PDWORD pdwDataType) { 
166   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
167   TRACE("(%p): stub\n", This);
168   return DPN_OK; 
169 }
170
171 static HRESULT WINAPI IDirectPlay8AddressImpl_AddComponent(PDIRECTPLAY8ADDRESS iface, CONST WCHAR* CONST pwszName, 
172                                                     CONST void* CONST lpvData, CONST DWORD dwDataSize, CONST DWORD dwDataType) { 
173   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
174   TRACE("(%p, %s, %p, %u, %x): stub\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
175   
176   if (NULL == lpvData) return DPNERR_INVALIDPOINTER;
177   switch (dwDataType) {
178   case DPNA_DATATYPE_DWORD:
179     if (sizeof(DWORD) != dwDataSize) return DPNERR_INVALIDPARAM;
180     TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
181     break;
182   case DPNA_DATATYPE_GUID:
183     if (sizeof(GUID) != dwDataSize) return DPNERR_INVALIDPARAM;
184     TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid((const GUID*) lpvData));
185     break;
186   case DPNA_DATATYPE_STRING:
187     TRACE("(%p, %u): STRING Type -> %s\n", lpvData, dwDataSize, (const CHAR*) lpvData);
188     break;
189   case DPNA_DATATYPE_BINARY:
190     TRACE("(%p, %u): BINARY Type\n", lpvData, dwDataSize);
191     break;
192   }
193   
194   return DPN_OK; 
195 }
196
197 static HRESULT WINAPI IDirectPlay8AddressImpl_GetDevice(PDIRECTPLAY8ADDRESS iface, GUID* pDevGuid) {   
198   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
199   TRACE("(%p): stub\n", This);
200   return DPN_OK; 
201 }
202
203 static HRESULT WINAPI IDirectPlay8AddressImpl_SetDevice(PDIRECTPLAY8ADDRESS iface, CONST GUID* CONST devGuid) { 
204   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
205   TRACE("(%p, %s): stub\n", This, debugstr_guid(devGuid));
206   return DPN_OK; 
207 }
208
209 static HRESULT WINAPI IDirectPlay8AddressImpl_BuildFromDirectPlay4Address(PDIRECTPLAY8ADDRESS iface, LPVOID pvAddress, DWORD dwDataSize) { 
210   IDirectPlay8AddressImpl *This = (IDirectPlay8AddressImpl *)iface;
211   TRACE("(%p): stub\n", This);
212   return DPN_OK; 
213 }
214
215 static const IDirectPlay8AddressVtbl DirectPlay8Address_Vtbl =
216 {
217     IDirectPlay8AddressImpl_QueryInterface,
218     IDirectPlay8AddressImpl_AddRef,
219     IDirectPlay8AddressImpl_Release,
220     IDirectPlay8AddressImpl_BuildFromURLW,
221     IDirectPlay8AddressImpl_BuildFromURLA,
222     IDirectPlay8AddressImpl_Duplicate,
223     IDirectPlay8AddressImpl_SetEqual,
224     IDirectPlay8AddressImpl_IsEqual,
225     IDirectPlay8AddressImpl_Clear,
226     IDirectPlay8AddressImpl_GetURLW,
227     IDirectPlay8AddressImpl_GetURLA,
228     IDirectPlay8AddressImpl_GetSP,
229     IDirectPlay8AddressImpl_GetUserData,
230     IDirectPlay8AddressImpl_SetSP,
231     IDirectPlay8AddressImpl_SetUserData,
232     IDirectPlay8AddressImpl_GetNumComponents,
233     IDirectPlay8AddressImpl_GetComponentByName,
234     IDirectPlay8AddressImpl_GetComponentByIndex,
235     IDirectPlay8AddressImpl_AddComponent,
236     IDirectPlay8AddressImpl_GetDevice,
237     IDirectPlay8AddressImpl_SetDevice,
238     IDirectPlay8AddressImpl_BuildFromDirectPlay4Address
239 };
240
241 HRESULT DPNET_CreateDirectPlay8Address(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
242   IDirectPlay8AddressImpl* client;
243
244   TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
245   
246   client = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectPlay8AddressImpl));
247   if (NULL == client) {
248     *ppobj = NULL;
249     return E_OUTOFMEMORY;
250   }
251   client->lpVtbl = &DirectPlay8Address_Vtbl;
252   client->ref = 0; /* will be inited with QueryInterface */
253   return IDirectPlay8AddressImpl_QueryInterface ((PDIRECTPLAY8ADDRESS)client, riid, ppobj);
254 }
255
256 /* returns name of given GUID */
257 const char *debugstr_SP(const GUID *id) {
258   static const guid_info guids[] = {
259     /* CLSIDs */
260     GE(CLSID_DP8SP_IPX),
261     GE(CLSID_DP8SP_TCPIP),
262     GE(CLSID_DP8SP_SERIAL),
263     GE(CLSID_DP8SP_MODEM)
264   };      
265   unsigned int i;
266
267   if (!id) return "(null)";
268   
269   for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
270     if (IsEqualGUID(id, guids[i].guid))
271       return guids[i].name;
272   }
273   /* if we didn't find it, act like standard debugstr_guid */   
274   return debugstr_guid(id);
275 }