ReactOS 0.4.15-dev-7953-g1f49173
name_server.c File Reference
#include <stdarg.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "wine/debug.h"
#include "mmsystem.h"
#include "dplayx_global.h"
#include "name_server.h"
#include "wine/dplaysp.h"
#include "dplayx_messages.h"
#include "dplayx_queue.h"
Include dependency graph for name_server.c:

Go to the source code of this file.

Classes

struct  NSCacheData
 
struct  NSCache
 

Macros

#define NONAMELESSUNION
 

Typedefs

typedef struct NSCacheData NSCacheData
 
typedef struct NSCacheDatalpNSCacheData
 
typedef struct NSCache NSCache
 
typedef struct NSCachelpNSCache
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dplay)
 
static DPQ_DECL_DELETECB (cbDeleteNSNodeFromHeap, lpNSCacheData)
 
void NS_SetLocalComputerAsNameServer (LPCDPSESSIONDESC2 lpsd, LPVOID lpNSInfo)
 
static DPQ_DECL_COMPARECB (cbUglyPig, GUID)
 
void NS_AddRemoteComputerAsNameServer (LPCVOID lpcNSAddrHdr, DWORD dwHdrSize, LPCDPMSG_ENUMSESSIONSREPLY lpcMsg, LPVOID lpNSInfo)
 
LPVOID NS_GetNSAddr (LPVOID lpNSInfo)
 
DWORD NS_GetNsMagic (LPVOID lpNSInfo)
 
void NS_SetLocalAddr (LPVOID lpNSInfo, LPCVOID lpHdr, DWORD dwHdrSize)
 
HRESULT NS_SendSessionRequestBroadcast (LPCGUID lpcGuid, DWORD dwFlags, const SPINITDATA *lpSpData)
 
void NS_InvalidateSessionCache (LPVOID lpNSInfo)
 
BOOL NS_InitializeSessionCache (LPVOID *lplpNSInfo)
 
void NS_DeleteSessionCache (LPVOID lpNSInfo)
 
void NS_ResetSessionEnumeration (LPVOID lpNSInfo)
 
LPDPSESSIONDESC2 NS_WalkSessions (LPVOID lpNSInfo)
 
void NS_PruneSessionCache (LPVOID lpNSInfo)
 
void NS_ReplyToEnumSessionsRequest (const void *lpcMsg, void **lplpReplyData, DWORD *lpdwReplySize, IDirectPlayImpl *lpDP)
 

Macro Definition Documentation

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 25 of file name_server.c.

Typedef Documentation

◆ lpNSCache

Definition at line 66 of file name_server.c.

◆ lpNSCacheData

Definition at line 54 of file name_server.c.

◆ NSCache

Definition at line 66 of file name_server.c.

◆ NSCacheData

Definition at line 54 of file name_server.c.

Function Documentation

◆ DPQ_DECL_COMPARECB()

static DPQ_DECL_COMPARECB ( cbUglyPig  ,
GUID   
)
static

Definition at line 81 of file name_server.c.

82{
83 return IsEqualGUID( elem1, elem2 );
84}
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147

◆ DPQ_DECL_DELETECB()

static DPQ_DECL_DELETECB ( cbDeleteNSNodeFromHeap  ,
lpNSCacheData   
)
static

Definition at line 232 of file name_server.c.

233{
234 /* NOTE: This proc doesn't deal with the walking pointer */
235
236 /* FIXME: Memory leak on data (contained ptrs) */
237 HeapFree( GetProcessHeap(), 0, elem->data );
238 HeapFree( GetProcessHeap(), 0, elem->lpNSAddrHdr );
240}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
static size_t elem
Definition: string.c:68

◆ NS_AddRemoteComputerAsNameServer()

void NS_AddRemoteComputerAsNameServer ( LPCVOID  lpcNSAddrHdr,
DWORD  dwHdrSize,
LPCDPMSG_ENUMSESSIONSREPLY  lpcMsg,
LPVOID  lpNSInfo 
)

Definition at line 87 of file name_server.c.

91{
92 DWORD len;
93 lpNSCache lpCache = (lpNSCache)lpNSInfo;
94 lpNSCacheData lpCacheNode;
95
96 TRACE( "%p, %p, %p\n", lpcNSAddrHdr, lpcMsg, lpNSInfo );
97
98 /* See if we can find this session. If we can, remove it as it's a dup */
99 DPQ_REMOVE_ENTRY_CB( lpCache->first, next, data->guidInstance, cbUglyPig,
100 lpcMsg->sd.guidInstance, lpCacheNode );
101
102 if( lpCacheNode != NULL )
103 {
104 TRACE( "Duplicate session entry for %s removed - updated version kept\n",
105 debugstr_guid( &lpCacheNode->data->guidInstance ) );
106 cbDeleteNSNodeFromHeap( lpCacheNode );
107 }
108
109 /* Add this to the list */
110 lpCacheNode = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpCacheNode ) );
111
112 if( lpCacheNode == NULL )
113 {
114 ERR( "no memory for NS node\n" );
115 return;
116 }
117
118 lpCacheNode->lpNSAddrHdr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
119 dwHdrSize );
120 CopyMemory( lpCacheNode->lpNSAddrHdr, lpcNSAddrHdr, dwHdrSize );
121
122 lpCacheNode->data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(lpCacheNode->data) ) );
123
124 if( lpCacheNode->data == NULL )
125 {
126 ERR( "no memory for SESSIONDESC2\n" );
127 HeapFree( GetProcessHeap(), 0, lpCacheNode );
128 return;
129 }
130
131 *lpCacheNode->data = lpcMsg->sd;
132 len = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1, NULL, 0, NULL, NULL );
133 if ((lpCacheNode->data->u1.lpszSessionNameA = HeapAlloc( GetProcessHeap(), 0, len )))
134 {
135 WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1,
136 lpCacheNode->data->u1.lpszSessionNameA, len, NULL, NULL );
137 }
138
139 lpCacheNode->dwTime = timeGetTime();
140
141 DPQ_INSERT(lpCache->first, lpCacheNode, next );
142
143 lpCache->present = lpCacheNode;
144
145 /* Use this message as an opportunity to weed out any old sessions so
146 * that we don't enum them again
147 */
148 NS_PruneSessionCache( lpNSInfo );
149}
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define WideCharToMultiByte
Definition: compat.h:111
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
DWORD WINAPI timeGetTime(void)
Definition: time.c:466
#define DPQ_INSERT(a, b, c)
Definition: dplayx_queue.h:34
#define DPQ_REMOVE_ENTRY_CB(head, elm, field, compare_cb, fieldToCompare, rc)
Definition: dplayx_queue.h:181
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLsizei len
Definition: glext.h:6722
#define debugstr_guid
Definition: kernel32.h:35
void NS_PruneSessionCache(LPVOID lpNSInfo)
Definition: name_server.c:319
struct NSCache * lpNSCache
Definition: name_server.c:66
static unsigned __int64 next
Definition: rand_nt.c:6
#define TRACE(s)
Definition: solgame.cpp:4
lpNSCacheData present
Definition: name_server.c:58
GUID guidInstance
Definition: dplay.h:234
#define CopyMemory
Definition: winbase.h:1710
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by DP_HandleMessage().

◆ NS_DeleteSessionCache()

void NS_DeleteSessionCache ( LPVOID  lpNSInfo)

Definition at line 283 of file name_server.c.

284{
286}
void NS_InvalidateSessionCache(LPVOID lpNSInfo)
Definition: name_server.c:243

Referenced by DP_DestroyDirectPlay2().

◆ NS_GetNSAddr()

LPVOID NS_GetNSAddr ( LPVOID  lpNSInfo)

Definition at line 151 of file name_server.c.

152{
153 lpNSCache lpCache = (lpNSCache)lpNSInfo;
154
155 FIXME( ":quick stub\n" );
156
157 /* Ok. Cheat and don't search for the correct stuff just take the first.
158 * FIXME: In the future how are we to know what is _THE_ enum we used?
159 * This is going to have to go into dplay somehow. Perhaps it
160 * comes back with app server id for the join command! Oh... that
161 * must be it. That would make this method obsolete once that's
162 * in place.
163 */
164#if 1
165 if ( lpCache->first.lpQHFirst )
166 return lpCache->first.lpQHFirst->lpNSAddrHdr;
167
168 return NULL;
169#else
170 /* FIXME: Should convert over to this */
171 return lpCache->bNsIsLocal ? lpCache->lpLocalAddrHdr
172 : lpCache->lpRemoteAddrHdr;
173#endif
174}
#define FIXME(fmt,...)
Definition: debug.h:111

Referenced by DP_SecureOpen(), and NS_GetNsMagic().

◆ NS_GetNsMagic()

DWORD NS_GetNsMagic ( LPVOID  lpNSInfo)

Definition at line 177 of file name_server.c.

178{
179 LPDWORD lpHdrInfo = NS_GetNSAddr( lpNSInfo );
180
181 return lpHdrInfo[1];
182}
LPVOID NS_GetNSAddr(LPVOID lpNSInfo)
Definition: name_server.c:151
uint32_t * LPDWORD
Definition: typedefs.h:59

Referenced by DP_MSG_ForwardPlayerCreation().

◆ NS_InitializeSessionCache()

BOOL NS_InitializeSessionCache ( LPVOID lplpNSInfo)

Definition at line 263 of file name_server.c.

264{
265 lpNSCache lpCache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpCache ) );
266
267 *lplpNSInfo = lpCache;
268
269 if( lpCache == NULL )
270 {
271 return FALSE;
272 }
273
274 DPQ_INIT(lpCache->first);
275 lpCache->present = NULL;
276
277 lpCache->bNsIsLocal = FALSE;
278
279 return TRUE;
280}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DPQ_INIT(head)
Definition: dplayx_queue.h:54

Referenced by DP_CreateDirectPlay2().

◆ NS_InvalidateSessionCache()

void NS_InvalidateSessionCache ( LPVOID  lpNSInfo)

Definition at line 243 of file name_server.c.

244{
245 lpNSCache lpCache = (lpNSCache)lpNSInfo;
246
247 if( lpCache == NULL )
248 {
249 ERR( ": invalidate nonexistent cache\n" );
250 return;
251 }
252
253 DPQ_DELETEQ( lpCache->first, next, lpNSCacheData, cbDeleteNSNodeFromHeap );
254
255 /* NULL out the walking pointer */
256 lpCache->present = NULL;
257
258 lpCache->bNsIsLocal = FALSE;
259
260}
#define DPQ_DELETEQ(head, field, type, df)
Definition: dplayx_queue.h:199

Referenced by IDirectPlay4Impl_EnumSessions(), and NS_DeleteSessionCache().

◆ NS_PruneSessionCache()

void NS_PruneSessionCache ( LPVOID  lpNSInfo)

Definition at line 319 of file name_server.c.

320{
321 lpNSCache lpCache = lpNSInfo;
322
323 const DWORD dwPresentTime = timeGetTime();
324 const DWORD dwPrunePeriod = DPMSG_WAIT_60_SECS; /* is 60 secs enough? */
325
326 /* This silly little algorithm is based on the fact we keep entries in
327 * the queue in a time based order. It also assumes that it is not possible
328 * to wrap around over yourself (which is not unreasonable).
329 * The if statements verify if the first entry in the queue is less
330 * than dwPrunePeriod old depending on the "clock" roll over.
331 */
332 for( ;; )
333 {
334 lpNSCacheData lpFirstData;
335
336 if( DPQ_IS_EMPTY(lpCache->first) )
337 {
338 /* Nothing to prune */
339 break;
340 }
341
342 /* Deal with time in a wrap around safe manner - unsigned arithmetic.
343 * Check the difference in time */
344 if( (dwPresentTime - (DPQ_FIRST(lpCache->first)->dwTime)) < dwPrunePeriod )
345 {
346 /* First entry has not expired yet; don't prune */
347 break;
348 }
349
350 lpFirstData = DPQ_FIRST(lpCache->first);
351 DPQ_REMOVE( lpCache->first, DPQ_FIRST(lpCache->first), next );
352 cbDeleteNSNodeFromHeap( lpFirstData );
353 }
354
355}
#define DPMSG_WAIT_60_SECS
#define DPQ_FIRST(head)
Definition: dplayx_queue.h:61
#define DPQ_IS_EMPTY(head)
Definition: dplayx_queue.h:64
#define DPQ_REMOVE(head, elm, field)
Definition: dplayx_queue.h:82

Referenced by DP_InvokeEnumSessionCallbacks(), and NS_AddRemoteComputerAsNameServer().

◆ NS_ReplyToEnumSessionsRequest()

void NS_ReplyToEnumSessionsRequest ( const void lpcMsg,
void **  lplpReplyData,
DWORD lpdwReplySize,
IDirectPlayImpl lpDP 
)

Definition at line 358 of file name_server.c.

360{
362 DWORD dwVariableSize;
363 DWORD dwVariableLen;
364 /* LPCDPMSG_ENUMSESSIONSREQUEST msg = (LPDPMSG_ENUMSESSIONSREQUEST)lpcMsg; */
365
366 /* FIXME: Should handle ANSI or WIDECHAR input. Currently just ANSI input */
367 FIXME( ": few fixed + need to check request for response, might need UNICODE input ability.\n" );
368
369 dwVariableLen = MultiByteToWideChar( CP_ACP, 0,
371 -1, NULL, 0 );
372 dwVariableSize = dwVariableLen * sizeof( WCHAR );
373
374 *lpdwReplySize = lpDP->dp2->spData.dwSPHeaderSize +
375 sizeof( *rmsg ) + dwVariableSize;
376 *lplpReplyData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
377 *lpdwReplySize );
378
379 rmsg = (LPDPMSG_ENUMSESSIONSREPLY)( (BYTE*)*lplpReplyData +
380 lpDP->dp2->spData.dwSPHeaderSize);
381
385
386 CopyMemory( &rmsg->sd, lpDP->dp2->lpSessionDesc,
387 lpDP->dp2->lpSessionDesc->dwSize );
388 rmsg->dwUnknown = 0x0000005c;
390 (LPWSTR)(rmsg+1), dwVariableLen );
391}
#define MultiByteToWideChar
Definition: compat.h:110
#define DPMSGVER_DP6
struct tagDPMSG_ENUMSESSIONSREPLY * LPDPMSG_ENUMSESSIONSREPLY
#define DPMSGCMD_ENUMSESSIONSREPLY
#define DPMSGMAGIC_DPLAYMSG
DirectPlay2Data * dp2
Definition: dplay_global.h:195
DPMSG_SENDENVELOPE envelope
LPSTR lpszSessionNameA
Definition: dplay.h:244
DWORD dwSize
Definition: dplay.h:232
LPDPSESSIONDESC2 lpSessionDesc
Definition: dplay_global.h:157
DWORD dwSPHeaderSize
Definition: dplaysp.h:360
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193

Referenced by DP_HandleMessage().

◆ NS_ResetSessionEnumeration()

void NS_ResetSessionEnumeration ( LPVOID  lpNSInfo)

Definition at line 289 of file name_server.c.

290{
291 ((lpNSCache)lpNSInfo)->present = ((lpNSCache)lpNSInfo)->first.lpQHFirst;
292}

Referenced by DP_InvokeEnumSessionCallbacks().

◆ NS_SendSessionRequestBroadcast()

HRESULT NS_SendSessionRequestBroadcast ( LPCGUID  lpcGuid,
DWORD  dwFlags,
const SPINITDATA lpSpData 
)

Definition at line 196 of file name_server.c.

200{
203
204 TRACE( "enumerating for guid %s\n", debugstr_guid( lpcGuid ) );
205
206 /* Get the SP to deal with sending the EnumSessions request */
207 FIXME( ": not all data fields are correct\n" );
208
209 data.dwMessageSize = lpSpData->dwSPHeaderSize + sizeof( *lpMsg ); /*FIXME!*/
211 data.dwMessageSize );
212 data.lpISP = lpSpData->lpISP;
213 data.bReturnStatus = (dwFlags & DPENUMSESSIONS_RETURNSTATUS) != 0;
214
215
216 lpMsg = (LPDPMSG_ENUMSESSIONSREQUEST)(((BYTE*)data.lpMessage)+lpSpData->dwSPHeaderSize);
217
218 /* Setup EnumSession request message */
222
223 lpMsg->dwPasswordSize = 0; /* FIXME: If enumerating passwords..? */
224 lpMsg->dwFlags = dwFlags;
225
226 lpMsg->guidApplication = *lpcGuid;
227
228 return (lpSpData->lpCB->EnumSessions)( &data );
229}
#define DPENUMSESSIONS_RETURNSTATUS
Definition: dplay.h:1021
struct tagDPMSG_ENUMSESSIONSREQUEST * LPDPMSG_ENUMSESSIONSREQUEST
#define DPMSGCMD_ENUMSESSIONSREQUEST
LPDPSP_ENUMSESSIONS EnumSessions
Definition: dplaysp.h:326
LPDPSP_SPCALLBACKS lpCB
Definition: dplaysp.h:354
IDirectPlaySP * lpISP
Definition: dplaysp.h:355
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by DP_EnumSessionsSendAsyncRequestThread(), and IDirectPlay4Impl_EnumSessions().

◆ NS_SetLocalAddr()

void NS_SetLocalAddr ( LPVOID  lpNSInfo,
LPCVOID  lpHdr,
DWORD  dwHdrSize 
)

Definition at line 184 of file name_server.c.

185{
186 lpNSCache lpCache = (lpNSCache)lpNSInfo;
187
188 lpCache->lpLocalAddrHdr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwHdrSize );
189
190 CopyMemory( lpCache->lpLocalAddrHdr, lpHdr, dwHdrSize );
191}

Referenced by DP_HandleMessage().

◆ NS_SetLocalComputerAsNameServer()

void NS_SetLocalComputerAsNameServer ( LPCDPSESSIONDESC2  lpsd,
LPVOID  lpNSInfo 
)

Definition at line 74 of file name_server.c.

75{
76 lpNSCache lpCache = (lpNSCache)lpNSInfo;
77
78 lpCache->bNsIsLocal = TRUE;
79}

Referenced by DP_SecureOpen().

◆ NS_WalkSessions()

LPDPSESSIONDESC2 NS_WalkSessions ( LPVOID  lpNSInfo)

Definition at line 294 of file name_server.c.

295{
296 LPDPSESSIONDESC2 lpSessionDesc;
297 lpNSCache lpCache = (lpNSCache)lpNSInfo;
298
299 /* FIXME: The pointers could disappear when walking if a prune happens */
300
301 /* Test for end of the list */
302 if( lpCache->present == NULL )
303 {
304 return NULL;
305 }
306
307 lpSessionDesc = lpCache->present->data;
308
309 /* Advance tracking pointer */
310 lpCache->present = lpCache->present->next.lpQNext;
311
312 return lpSessionDesc;
313}

Referenced by DP_InvokeEnumSessionCallbacks().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dplay  )