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