xref: /reactos/dll/directx/wine/dplayx/name_server.c (revision eed82436)
1c2c66affSColin Finck /* DPLAYX.DLL name server implementation
2c2c66affSColin Finck  *
3c2c66affSColin Finck  * Copyright 2000-2001 - Peter Hunnisett
4c2c66affSColin Finck  *
5c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
6c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
7c2c66affSColin Finck  * License as published by the Free Software Foundation; either
8c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
9c2c66affSColin Finck  *
10c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
11c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13c2c66affSColin Finck  * Lesser General Public License for more details.
14c2c66affSColin Finck  *
15c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
16c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
17c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18c2c66affSColin Finck  */
19c2c66affSColin Finck 
20c2c66affSColin Finck /* NOTE: Methods with the NS_ prefix are name server methods */
21c2c66affSColin Finck 
22*a5313181SAmine Khaldi #include <stdarg.h>
23*a5313181SAmine Khaldi #include <string.h>
24c2c66affSColin Finck 
25*a5313181SAmine Khaldi #define NONAMELESSUNION
26*a5313181SAmine Khaldi 
27*a5313181SAmine Khaldi #include "windef.h"
28*a5313181SAmine Khaldi #include "winbase.h"
29*a5313181SAmine Khaldi #include "winnls.h"
30*a5313181SAmine Khaldi #include "wine/debug.h"
31*a5313181SAmine Khaldi #include "mmsystem.h"
32*a5313181SAmine Khaldi 
33*a5313181SAmine Khaldi #include "dplayx_global.h"
34*a5313181SAmine Khaldi #include "name_server.h"
35*a5313181SAmine Khaldi #include "wine/dplaysp.h"
36*a5313181SAmine Khaldi #include "dplayx_messages.h"
37*a5313181SAmine Khaldi #include "dplayx_queue.h"
38c2c66affSColin Finck 
39c2c66affSColin Finck /* FIXME: Need to create a crit section, store and use it */
40c2c66affSColin Finck 
41*a5313181SAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(dplay);
42*a5313181SAmine Khaldi 
43c2c66affSColin Finck /* NS specific structures */
44c2c66affSColin Finck struct NSCacheData
45c2c66affSColin Finck {
46c2c66affSColin Finck   DPQ_ENTRY(NSCacheData) next;
47c2c66affSColin Finck 
48c2c66affSColin Finck   DWORD dwTime; /* Time at which data was last known valid */
49c2c66affSColin Finck   LPDPSESSIONDESC2 data;
50c2c66affSColin Finck 
51c2c66affSColin Finck   LPVOID lpNSAddrHdr;
52c2c66affSColin Finck 
53c2c66affSColin Finck };
54c2c66affSColin Finck typedef struct NSCacheData NSCacheData, *lpNSCacheData;
55c2c66affSColin Finck 
56c2c66affSColin Finck struct NSCache
57c2c66affSColin Finck {
58c2c66affSColin Finck   lpNSCacheData present; /* keep track of what is to be looked at when walking */
59c2c66affSColin Finck 
60c2c66affSColin Finck   DPQ_HEAD(NSCacheData) first;
61c2c66affSColin Finck 
62c2c66affSColin Finck   BOOL bNsIsLocal;
63c2c66affSColin Finck   LPVOID lpLocalAddrHdr;  /* FIXME: Not yet used */
64c2c66affSColin Finck   LPVOID lpRemoteAddrHdr; /* FIXME: Not yet used */
65c2c66affSColin Finck };
66c2c66affSColin Finck typedef struct NSCache NSCache, *lpNSCache;
67c2c66affSColin Finck 
68c2c66affSColin Finck /* Function prototypes */
69c2c66affSColin Finck static DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData );
70c2c66affSColin Finck 
71c2c66affSColin Finck /* Name Server functions
72c2c66affSColin Finck  * ---------------------
73c2c66affSColin Finck  */
NS_SetLocalComputerAsNameServer(LPCDPSESSIONDESC2 lpsd,LPVOID lpNSInfo)74c2c66affSColin Finck void NS_SetLocalComputerAsNameServer( LPCDPSESSIONDESC2 lpsd, LPVOID lpNSInfo )
75c2c66affSColin Finck {
76c2c66affSColin Finck   lpNSCache lpCache = (lpNSCache)lpNSInfo;
77c2c66affSColin Finck 
78c2c66affSColin Finck   lpCache->bNsIsLocal = TRUE;
79c2c66affSColin Finck }
80c2c66affSColin Finck 
DPQ_DECL_COMPARECB(cbUglyPig,GUID)81c2c66affSColin Finck static DPQ_DECL_COMPARECB( cbUglyPig, GUID )
82c2c66affSColin Finck {
83c2c66affSColin Finck   return IsEqualGUID( elem1, elem2 );
84c2c66affSColin Finck }
85c2c66affSColin Finck 
86c2c66affSColin Finck /* Store the given NS remote address for future reference */
NS_AddRemoteComputerAsNameServer(LPCVOID lpcNSAddrHdr,DWORD dwHdrSize,LPCDPMSG_ENUMSESSIONSREPLY lpcMsg,LPVOID lpNSInfo)87c2c66affSColin Finck void NS_AddRemoteComputerAsNameServer( LPCVOID                      lpcNSAddrHdr,
88c2c66affSColin Finck                                        DWORD                        dwHdrSize,
89c2c66affSColin Finck                                        LPCDPMSG_ENUMSESSIONSREPLY   lpcMsg,
90c2c66affSColin Finck                                        LPVOID                       lpNSInfo )
91c2c66affSColin Finck {
92c2c66affSColin Finck   DWORD len;
93c2c66affSColin Finck   lpNSCache     lpCache = (lpNSCache)lpNSInfo;
94c2c66affSColin Finck   lpNSCacheData lpCacheNode;
95c2c66affSColin Finck 
96c2c66affSColin Finck   TRACE( "%p, %p, %p\n", lpcNSAddrHdr, lpcMsg, lpNSInfo );
97c2c66affSColin Finck 
98c2c66affSColin Finck   /* See if we can find this session. If we can, remove it as it's a dup */
99c2c66affSColin Finck   DPQ_REMOVE_ENTRY_CB( lpCache->first, next, data->guidInstance, cbUglyPig,
100c2c66affSColin Finck                        lpcMsg->sd.guidInstance, lpCacheNode );
101c2c66affSColin Finck 
102c2c66affSColin Finck   if( lpCacheNode != NULL )
103c2c66affSColin Finck   {
104c2c66affSColin Finck     TRACE( "Duplicate session entry for %s removed - updated version kept\n",
105c2c66affSColin Finck            debugstr_guid( &lpCacheNode->data->guidInstance ) );
106c2c66affSColin Finck     cbDeleteNSNodeFromHeap( lpCacheNode );
107c2c66affSColin Finck   }
108c2c66affSColin Finck 
109c2c66affSColin Finck   /* Add this to the list */
110c2c66affSColin Finck   lpCacheNode = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpCacheNode ) );
111c2c66affSColin Finck 
112c2c66affSColin Finck   if( lpCacheNode == NULL )
113c2c66affSColin Finck   {
114c2c66affSColin Finck     ERR( "no memory for NS node\n" );
115c2c66affSColin Finck     return;
116c2c66affSColin Finck   }
117c2c66affSColin Finck 
118c2c66affSColin Finck   lpCacheNode->lpNSAddrHdr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
119c2c66affSColin Finck                                         dwHdrSize );
120c2c66affSColin Finck   CopyMemory( lpCacheNode->lpNSAddrHdr, lpcNSAddrHdr, dwHdrSize );
121c2c66affSColin Finck 
122c2c66affSColin Finck   lpCacheNode->data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(lpCacheNode->data) ) );
123c2c66affSColin Finck 
124c2c66affSColin Finck   if( lpCacheNode->data == NULL )
125c2c66affSColin Finck   {
126c2c66affSColin Finck     ERR( "no memory for SESSIONDESC2\n" );
127c2c66affSColin Finck     HeapFree( GetProcessHeap(), 0, lpCacheNode );
128c2c66affSColin Finck     return;
129c2c66affSColin Finck   }
130c2c66affSColin Finck 
131c2c66affSColin Finck   *lpCacheNode->data = lpcMsg->sd;
132c2c66affSColin Finck   len = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1, NULL, 0, NULL, NULL );
133c2c66affSColin Finck   if ((lpCacheNode->data->u1.lpszSessionNameA = HeapAlloc( GetProcessHeap(), 0, len )))
134c2c66affSColin Finck   {
135c2c66affSColin Finck       WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1,
136c2c66affSColin Finck                            lpCacheNode->data->u1.lpszSessionNameA, len, NULL, NULL );
137c2c66affSColin Finck   }
138c2c66affSColin Finck 
139c2c66affSColin Finck   lpCacheNode->dwTime = timeGetTime();
140c2c66affSColin Finck 
141c2c66affSColin Finck   DPQ_INSERT(lpCache->first, lpCacheNode, next );
142c2c66affSColin Finck 
143c2c66affSColin Finck   lpCache->present = lpCacheNode;
144c2c66affSColin Finck 
145c2c66affSColin Finck   /* Use this message as an opportunity to weed out any old sessions so
146c2c66affSColin Finck    * that we don't enum them again
147c2c66affSColin Finck    */
148c2c66affSColin Finck   NS_PruneSessionCache( lpNSInfo );
149c2c66affSColin Finck }
150c2c66affSColin Finck 
NS_GetNSAddr(LPVOID lpNSInfo)151c2c66affSColin Finck LPVOID NS_GetNSAddr( LPVOID lpNSInfo )
152c2c66affSColin Finck {
153c2c66affSColin Finck   lpNSCache lpCache = (lpNSCache)lpNSInfo;
154c2c66affSColin Finck 
155c2c66affSColin Finck   FIXME( ":quick stub\n" );
156c2c66affSColin Finck 
157c2c66affSColin Finck   /* Ok. Cheat and don't search for the correct stuff just take the first.
158c2c66affSColin Finck    * FIXME: In the future how are we to know what is _THE_ enum we used?
159c2c66affSColin Finck    *        This is going to have to go into dplay somehow. Perhaps it
160c2c66affSColin Finck    *        comes back with app server id for the join command! Oh... that
161c2c66affSColin Finck    *        must be it. That would make this method obsolete once that's
162c2c66affSColin Finck    *        in place.
163c2c66affSColin Finck    */
164c2c66affSColin Finck #if 1
165c2c66affSColin Finck   if ( lpCache->first.lpQHFirst )
166c2c66affSColin Finck     return lpCache->first.lpQHFirst->lpNSAddrHdr;
167c2c66affSColin Finck 
168c2c66affSColin Finck   return NULL;
169c2c66affSColin Finck #else
170c2c66affSColin Finck   /* FIXME: Should convert over to this */
171c2c66affSColin Finck   return lpCache->bNsIsLocal ? lpCache->lpLocalAddrHdr
172c2c66affSColin Finck                              : lpCache->lpRemoteAddrHdr;
173c2c66affSColin Finck #endif
174c2c66affSColin Finck }
175c2c66affSColin Finck 
176c2c66affSColin Finck /* Get the magic number associated with the Name Server */
NS_GetNsMagic(LPVOID lpNSInfo)177c2c66affSColin Finck DWORD NS_GetNsMagic( LPVOID lpNSInfo )
178c2c66affSColin Finck {
179c2c66affSColin Finck   LPDWORD lpHdrInfo = NS_GetNSAddr( lpNSInfo );
180c2c66affSColin Finck 
181c2c66affSColin Finck   return lpHdrInfo[1];
182c2c66affSColin Finck }
183c2c66affSColin Finck 
NS_SetLocalAddr(LPVOID lpNSInfo,LPCVOID lpHdr,DWORD dwHdrSize)184c2c66affSColin Finck void NS_SetLocalAddr( LPVOID lpNSInfo, LPCVOID lpHdr, DWORD dwHdrSize )
185c2c66affSColin Finck {
186c2c66affSColin Finck   lpNSCache lpCache = (lpNSCache)lpNSInfo;
187c2c66affSColin Finck 
188c2c66affSColin Finck   lpCache->lpLocalAddrHdr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwHdrSize );
189c2c66affSColin Finck 
190c2c66affSColin Finck   CopyMemory( lpCache->lpLocalAddrHdr, lpHdr, dwHdrSize );
191c2c66affSColin Finck }
192c2c66affSColin Finck 
193c2c66affSColin Finck /* This function is responsible for sending a request for all other known
194c2c66affSColin Finck    nameservers to send us what sessions they have registered locally
195c2c66affSColin Finck  */
NS_SendSessionRequestBroadcast(LPCGUID lpcGuid,DWORD dwFlags,const SPINITDATA * lpSpData)196c2c66affSColin Finck HRESULT NS_SendSessionRequestBroadcast( LPCGUID lpcGuid,
197c2c66affSColin Finck                                         DWORD dwFlags,
198c2c66affSColin Finck                                         const SPINITDATA *lpSpData )
199c2c66affSColin Finck 
200c2c66affSColin Finck {
201c2c66affSColin Finck   DPSP_ENUMSESSIONSDATA data;
202c2c66affSColin Finck   LPDPMSG_ENUMSESSIONSREQUEST lpMsg;
203c2c66affSColin Finck 
204c2c66affSColin Finck   TRACE( "enumerating for guid %s\n", debugstr_guid( lpcGuid ) );
205c2c66affSColin Finck 
206c2c66affSColin Finck   /* Get the SP to deal with sending the EnumSessions request */
207c2c66affSColin Finck   FIXME( ": not all data fields are correct\n" );
208c2c66affSColin Finck 
209c2c66affSColin Finck   data.dwMessageSize = lpSpData->dwSPHeaderSize + sizeof( *lpMsg ); /*FIXME!*/
210c2c66affSColin Finck   data.lpMessage = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
211c2c66affSColin Finck                               data.dwMessageSize );
212c2c66affSColin Finck   data.lpISP = lpSpData->lpISP;
213c2c66affSColin Finck   data.bReturnStatus = (dwFlags & DPENUMSESSIONS_RETURNSTATUS) != 0;
214c2c66affSColin Finck 
215c2c66affSColin Finck 
216c2c66affSColin Finck   lpMsg = (LPDPMSG_ENUMSESSIONSREQUEST)(((BYTE*)data.lpMessage)+lpSpData->dwSPHeaderSize);
217c2c66affSColin Finck 
218c2c66affSColin Finck   /* Setup EnumSession request message */
219c2c66affSColin Finck   lpMsg->envelope.dwMagic    = DPMSGMAGIC_DPLAYMSG;
220c2c66affSColin Finck   lpMsg->envelope.wCommandId = DPMSGCMD_ENUMSESSIONSREQUEST;
221c2c66affSColin Finck   lpMsg->envelope.wVersion   = DPMSGVER_DP6;
222c2c66affSColin Finck 
223c2c66affSColin Finck   lpMsg->dwPasswordSize = 0; /* FIXME: If enumerating passwords..? */
224c2c66affSColin Finck   lpMsg->dwFlags        = dwFlags;
225c2c66affSColin Finck 
226c2c66affSColin Finck   lpMsg->guidApplication = *lpcGuid;
227c2c66affSColin Finck 
228c2c66affSColin Finck   return (lpSpData->lpCB->EnumSessions)( &data );
229c2c66affSColin Finck }
230c2c66affSColin Finck 
231c2c66affSColin Finck /* Delete a name server node which has been allocated on the heap */
DPQ_DECL_DELETECB(cbDeleteNSNodeFromHeap,lpNSCacheData)232c2c66affSColin Finck static DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData )
233c2c66affSColin Finck {
234c2c66affSColin Finck   /* NOTE: This proc doesn't deal with the walking pointer */
235c2c66affSColin Finck 
236c2c66affSColin Finck   /* FIXME: Memory leak on data (contained ptrs) */
237c2c66affSColin Finck   HeapFree( GetProcessHeap(), 0, elem->data );
238c2c66affSColin Finck   HeapFree( GetProcessHeap(), 0, elem->lpNSAddrHdr );
239c2c66affSColin Finck   HeapFree( GetProcessHeap(), 0, elem );
240c2c66affSColin Finck }
241c2c66affSColin Finck 
242c2c66affSColin Finck /* Render all data in a session cache invalid */
NS_InvalidateSessionCache(LPVOID lpNSInfo)243c2c66affSColin Finck void NS_InvalidateSessionCache( LPVOID lpNSInfo )
244c2c66affSColin Finck {
245c2c66affSColin Finck   lpNSCache lpCache = (lpNSCache)lpNSInfo;
246c2c66affSColin Finck 
247c2c66affSColin Finck   if( lpCache == NULL )
248c2c66affSColin Finck   {
249c2c66affSColin Finck     ERR( ": invalidate nonexistent cache\n" );
250c2c66affSColin Finck     return;
251c2c66affSColin Finck   }
252c2c66affSColin Finck 
253c2c66affSColin Finck   DPQ_DELETEQ( lpCache->first, next, lpNSCacheData, cbDeleteNSNodeFromHeap );
254c2c66affSColin Finck 
255c2c66affSColin Finck   /* NULL out the walking pointer */
256c2c66affSColin Finck   lpCache->present = NULL;
257c2c66affSColin Finck 
258c2c66affSColin Finck   lpCache->bNsIsLocal = FALSE;
259c2c66affSColin Finck 
260c2c66affSColin Finck }
261c2c66affSColin Finck 
262c2c66affSColin Finck /* Create and initialize a session cache */
NS_InitializeSessionCache(LPVOID * lplpNSInfo)263c2c66affSColin Finck BOOL NS_InitializeSessionCache( LPVOID* lplpNSInfo )
264c2c66affSColin Finck {
265c2c66affSColin Finck   lpNSCache lpCache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpCache ) );
266c2c66affSColin Finck 
267c2c66affSColin Finck   *lplpNSInfo = lpCache;
268c2c66affSColin Finck 
269c2c66affSColin Finck   if( lpCache == NULL )
270c2c66affSColin Finck   {
271c2c66affSColin Finck     return FALSE;
272c2c66affSColin Finck   }
273c2c66affSColin Finck 
274c2c66affSColin Finck   DPQ_INIT(lpCache->first);
275c2c66affSColin Finck   lpCache->present = NULL;
276c2c66affSColin Finck 
277c2c66affSColin Finck   lpCache->bNsIsLocal = FALSE;
278c2c66affSColin Finck 
279c2c66affSColin Finck   return TRUE;
280c2c66affSColin Finck }
281c2c66affSColin Finck 
282c2c66affSColin Finck /* Delete a session cache */
NS_DeleteSessionCache(LPVOID lpNSInfo)283c2c66affSColin Finck void NS_DeleteSessionCache( LPVOID lpNSInfo )
284c2c66affSColin Finck {
285c2c66affSColin Finck   NS_InvalidateSessionCache( (lpNSCache)lpNSInfo );
286c2c66affSColin Finck }
287c2c66affSColin Finck 
288c2c66affSColin Finck /* Reinitialize the present pointer for this cache */
NS_ResetSessionEnumeration(LPVOID lpNSInfo)289c2c66affSColin Finck void NS_ResetSessionEnumeration( LPVOID lpNSInfo )
290c2c66affSColin Finck {
291c2c66affSColin Finck   ((lpNSCache)lpNSInfo)->present = ((lpNSCache)lpNSInfo)->first.lpQHFirst;
292c2c66affSColin Finck }
293c2c66affSColin Finck 
NS_WalkSessions(LPVOID lpNSInfo)294c2c66affSColin Finck LPDPSESSIONDESC2 NS_WalkSessions( LPVOID lpNSInfo )
295c2c66affSColin Finck {
296c2c66affSColin Finck   LPDPSESSIONDESC2 lpSessionDesc;
297c2c66affSColin Finck   lpNSCache lpCache = (lpNSCache)lpNSInfo;
298c2c66affSColin Finck 
299c2c66affSColin Finck   /* FIXME: The pointers could disappear when walking if a prune happens */
300c2c66affSColin Finck 
301c2c66affSColin Finck   /* Test for end of the list */
302c2c66affSColin Finck   if( lpCache->present == NULL )
303c2c66affSColin Finck   {
304c2c66affSColin Finck     return NULL;
305c2c66affSColin Finck   }
306c2c66affSColin Finck 
307c2c66affSColin Finck   lpSessionDesc = lpCache->present->data;
308c2c66affSColin Finck 
309c2c66affSColin Finck   /* Advance tracking pointer */
310c2c66affSColin Finck   lpCache->present = lpCache->present->next.lpQNext;
311c2c66affSColin Finck 
312c2c66affSColin Finck   return lpSessionDesc;
313c2c66affSColin Finck }
314c2c66affSColin Finck 
315c2c66affSColin Finck /* This method should check to see if there are any sessions which are
316c2c66affSColin Finck  * older than the criteria. If so, just delete that information.
317c2c66affSColin Finck  */
318c2c66affSColin Finck /* FIXME: This needs to be called by some periodic timer */
NS_PruneSessionCache(LPVOID lpNSInfo)319c2c66affSColin Finck void NS_PruneSessionCache( LPVOID lpNSInfo )
320c2c66affSColin Finck {
321c2c66affSColin Finck   lpNSCache     lpCache = lpNSInfo;
322c2c66affSColin Finck 
323c2c66affSColin Finck   const DWORD dwPresentTime = timeGetTime();
324c2c66affSColin Finck   const DWORD dwPrunePeriod = DPMSG_WAIT_60_SECS; /* is 60 secs enough? */
325c2c66affSColin Finck 
326c2c66affSColin Finck   /* This silly little algorithm is based on the fact we keep entries in
327c2c66affSColin Finck    * the queue in a time based order. It also assumes that it is not possible
328c2c66affSColin Finck    * to wrap around over yourself (which is not unreasonable).
329c2c66affSColin Finck    * The if statements verify if the first entry in the queue is less
330c2c66affSColin Finck    * than dwPrunePeriod old depending on the "clock" roll over.
331c2c66affSColin Finck    */
332c2c66affSColin Finck   for( ;; )
333c2c66affSColin Finck   {
334c2c66affSColin Finck     lpNSCacheData lpFirstData;
335c2c66affSColin Finck 
336c2c66affSColin Finck     if( DPQ_IS_EMPTY(lpCache->first) )
337c2c66affSColin Finck     {
338c2c66affSColin Finck       /* Nothing to prune */
339c2c66affSColin Finck       break;
340c2c66affSColin Finck     }
341c2c66affSColin Finck 
342c2c66affSColin Finck     /* Deal with time in a wrap around safe manner - unsigned arithmetic.
343c2c66affSColin Finck      * Check the difference in time */
344c2c66affSColin Finck     if( (dwPresentTime - (DPQ_FIRST(lpCache->first)->dwTime)) < dwPrunePeriod )
345c2c66affSColin Finck     {
346c2c66affSColin Finck       /* First entry has not expired yet; don't prune */
347c2c66affSColin Finck       break;
348c2c66affSColin Finck     }
349c2c66affSColin Finck 
350c2c66affSColin Finck     lpFirstData = DPQ_FIRST(lpCache->first);
351c2c66affSColin Finck     DPQ_REMOVE( lpCache->first, DPQ_FIRST(lpCache->first), next );
352c2c66affSColin Finck     cbDeleteNSNodeFromHeap( lpFirstData );
353c2c66affSColin Finck   }
354c2c66affSColin Finck 
355c2c66affSColin Finck }
356c2c66affSColin Finck 
357c2c66affSColin Finck /* NAME SERVER Message stuff */
NS_ReplyToEnumSessionsRequest(const void * lpcMsg,void ** lplpReplyData,DWORD * lpdwReplySize,IDirectPlayImpl * lpDP)358c2c66affSColin Finck void NS_ReplyToEnumSessionsRequest( const void *lpcMsg, void **lplpReplyData, DWORD *lpdwReplySize,
359c2c66affSColin Finck         IDirectPlayImpl *lpDP )
360c2c66affSColin Finck {
361c2c66affSColin Finck   LPDPMSG_ENUMSESSIONSREPLY rmsg;
362c2c66affSColin Finck   DWORD dwVariableSize;
363c2c66affSColin Finck   DWORD dwVariableLen;
364c2c66affSColin Finck   /* LPCDPMSG_ENUMSESSIONSREQUEST msg = (LPDPMSG_ENUMSESSIONSREQUEST)lpcMsg; */
365c2c66affSColin Finck 
366c2c66affSColin Finck   /* FIXME: Should handle ANSI or WIDECHAR input. Currently just ANSI input */
367c2c66affSColin Finck   FIXME( ": few fixed + need to check request for response, might need UNICODE input ability.\n" );
368c2c66affSColin Finck 
369c2c66affSColin Finck   dwVariableLen = MultiByteToWideChar( CP_ACP, 0,
370c2c66affSColin Finck                                        lpDP->dp2->lpSessionDesc->u1.lpszSessionNameA,
371c2c66affSColin Finck                                        -1, NULL, 0 );
372c2c66affSColin Finck   dwVariableSize = dwVariableLen * sizeof( WCHAR );
373c2c66affSColin Finck 
374c2c66affSColin Finck   *lpdwReplySize = lpDP->dp2->spData.dwSPHeaderSize +
375c2c66affSColin Finck                      sizeof( *rmsg ) + dwVariableSize;
376c2c66affSColin Finck   *lplpReplyData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
377c2c66affSColin Finck                               *lpdwReplySize );
378c2c66affSColin Finck 
379c2c66affSColin Finck   rmsg = (LPDPMSG_ENUMSESSIONSREPLY)( (BYTE*)*lplpReplyData +
380c2c66affSColin Finck                                              lpDP->dp2->spData.dwSPHeaderSize);
381c2c66affSColin Finck 
382c2c66affSColin Finck   rmsg->envelope.dwMagic    = DPMSGMAGIC_DPLAYMSG;
383c2c66affSColin Finck   rmsg->envelope.wCommandId = DPMSGCMD_ENUMSESSIONSREPLY;
384c2c66affSColin Finck   rmsg->envelope.wVersion   = DPMSGVER_DP6;
385c2c66affSColin Finck 
386c2c66affSColin Finck   CopyMemory( &rmsg->sd, lpDP->dp2->lpSessionDesc,
387c2c66affSColin Finck               lpDP->dp2->lpSessionDesc->dwSize );
388c2c66affSColin Finck   rmsg->dwUnknown = 0x0000005c;
389c2c66affSColin Finck   MultiByteToWideChar( CP_ACP, 0, lpDP->dp2->lpSessionDesc->u1.lpszSessionNameA, -1,
390c2c66affSColin Finck                        (LPWSTR)(rmsg+1), dwVariableLen );
391c2c66affSColin Finck }
392