ReactOS 0.4.17-dev-966-gf06eace
name_server.h File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "dplay.h"
#include "wine/dplaysp.h"
#include "dplayx_messages.h"
#include "dplay_global.h"
Include dependency graph for name_server.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void NS_SetLocalComputerAsNameServer (LPCDPSESSIONDESC2 lpsd, LPVOID lpNSInfo)
 
void NS_AddRemoteComputerAsNameServer (LPCVOID lpNSAddrHdr, DWORD dwHdrSize, LPCDPMSG_ENUMSESSIONSREPLY lpcMsg, DWORD msgSize, LPVOID lpNSInfo)
 
void NS_SetLocalAddr (LPVOID lpNSInfo, LPCVOID lpHdr, DWORD dwHdrSize)
 
void NS_ReplyToEnumSessionsRequest (LPCVOID lpcMsg, LPVOID *lplpReplyData, LPDWORD lpdwReplySize, IDirectPlayImpl *lpDP)
 
HRESULT NS_SendSessionRequestBroadcast (LPCGUID lpcGuid, DWORD dwFlags, WCHAR *password, const SPINITDATA *lpSpData)
 
BOOL NS_InitializeSessionCache (LPVOID *lplpNSInfo)
 
void NS_DeleteSessionCache (LPVOID lpNSInfo)
 
void NS_InvalidateSessionCache (LPVOID lpNSInfo)
 
void NS_ResetSessionEnumeration (LPVOID lpNSInfo)
 
LPDPSESSIONDESC2 NS_WalkSessions (LPVOID lpNSInfo, void **spMessageHeader, BOOL ansi)
 
void NS_PruneSessionCache (LPVOID lpNSInfo)
 

Function Documentation

◆ NS_AddRemoteComputerAsNameServer()

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

Definition at line 101 of file name_server.c.

106{
107 lpNSCache lpCache = (lpNSCache)lpNSInfo;
108 lpNSCacheData lpCacheNode;
109 DPSESSIONDESC2 dpsd;
110 DWORD maxNameLength;
111 DWORD nameLength;
112
113 TRACE( "%p, %p, %p\n", lpcNSAddrHdr, lpcMsg, lpNSInfo );
114
115 if ( msgSize < sizeof( DPMSG_ENUMSESSIONSREPLY ) + sizeof( WCHAR ) )
116 return;
117
118 maxNameLength = (msgSize - sizeof( DPMSG_ENUMSESSIONSREPLY )) / sizeof( WCHAR );
119 nameLength = wcsnlen( (WCHAR *) (lpcMsg + 1), maxNameLength );
120 if ( nameLength == maxNameLength )
121 return;
122
123 /* See if we can find this session. If we can, remove it as it's a dup */
124 DPQ_REMOVE_ENTRY_CB( lpCache->first, next, data->guidInstance, cbUglyPig,
125 lpcMsg->sd.guidInstance, lpCacheNode );
126
127 if( lpCacheNode != NULL )
128 {
129 TRACE( "Duplicate session entry for %s removed - updated version kept\n",
130 debugstr_guid( &lpCacheNode->data->guidInstance ) );
131 cbReleaseNSNode( lpCacheNode );
132 }
133
134 /* Add this to the list */
135 lpCacheNode = calloc( 1, sizeof( *lpCacheNode ) );
136
137 if( lpCacheNode == NULL )
138 {
139 ERR( "no memory for NS node\n" );
140 return;
141 }
142
143 lpCacheNode->lpNSAddrHdr = malloc( dwHdrSize );
144 CopyMemory( lpCacheNode->lpNSAddrHdr, lpcNSAddrHdr, dwHdrSize );
145
146 dpsd = lpcMsg->sd;
147 dpsd.lpszSessionName = (WCHAR *) (lpcMsg + 1);
148 dpsd.lpszPassword = NULL;
149
150 lpCacheNode->data = DP_DuplicateSessionDesc( &dpsd, FALSE, FALSE );
151
152 if( lpCacheNode->data == NULL )
153 {
154 ERR( "no memory for SESSIONDESC2\n" );
155 free( lpCacheNode );
156 return;
157 }
158
159 lpCacheNode->dataA = DP_DuplicateSessionDesc( &dpsd, TRUE, FALSE );
160
161 if( lpCacheNode->dataA == NULL )
162 {
163 ERR( "no memory for SESSIONDESC2\n" );
164 free( lpCacheNode->data );
165 free( lpCacheNode );
166 return;
167 }
168
169 lpCacheNode->ref = 1;
170 lpCacheNode->dwTime = timeGetTime();
171
172 DPQ_INSERT(lpCache->first, lpCacheNode, next );
173
174 /* Use this message as an opportunity to weed out any old sessions so
175 * that we don't enum them again
176 */
177 NS_PruneSessionCache( lpNSInfo );
178}
#define ERR(fmt,...)
Definition: precomp.h:57
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_ACRTIMP size_t __cdecl wcsnlen(const wchar_t *, size_t)
Definition: wcs.c:2925
DWORD WINAPI timeGetTime(void)
Definition: time.c:466
DPSESSIONDESC2 * DP_DuplicateSessionDesc(const DPSESSIONDESC2 *src, BOOL dstAnsi, BOOL srcAnsi)
Definition: dplay.c:4579
struct tagDPMSG_ENUMSESSIONSREPLY DPMSG_ENUMSESSIONSREPLY
#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
#define debugstr_guid
Definition: kernel32.h:35
#define CopyMemory
Definition: minwinbase.h:29
void NS_PruneSessionCache(LPVOID lpNSInfo)
Definition: name_server.c:332
struct NSCache * lpNSCache
Definition: name_server.c:80
short WCHAR
Definition: pedump.c:58
static unsigned __int64 next
Definition: rand_nt.c:6
#define calloc
Definition: rosglue.h:14
#define TRACE(s)
Definition: solgame.cpp:4
LPWSTR lpszPassword
Definition: dplay.h:249
LPWSTR lpszSessionName
Definition: dplay.h:243
GUID guidInstance
Definition: dplay.h:234

Referenced by DP_HandleMessage().

◆ NS_DeleteSessionCache()

void NS_DeleteSessionCache ( LPVOID  lpNSInfo)

Definition at line 283 of file name_server.c.

284{
287}
void NS_InvalidateSessionCache(LPVOID lpNSInfo)
Definition: name_server.c:245
void NS_ResetSessionEnumeration(LPVOID lpNSInfo)
Definition: name_server.c:290

Referenced by DP_DestroyDirectPlay2().

◆ NS_InitializeSessionCache()

BOOL NS_InitializeSessionCache ( LPVOID *  lplpNSInfo)

Definition at line 262 of file name_server.c.

263{
264 lpNSCache lpCache = calloc( 1, sizeof( *lpCache ) );
265
266 *lplpNSInfo = lpCache;
267
268 if( lpCache == NULL )
269 {
270 return FALSE;
271 }
272
273 DPQ_INIT(lpCache->walkFirst);
274 DPQ_INIT(lpCache->first);
275 lpCache->present = NULL;
276
277 lpCache->bNsIsLocal = FALSE;
278
279 return TRUE;
280}
#define DPQ_INIT(head)
Definition: dplayx_queue.h:54
lpNSCacheData present
Definition: name_server.c:71

Referenced by DP_CreateDirectPlay2().

◆ NS_InvalidateSessionCache()

void NS_InvalidateSessionCache ( LPVOID  lpNSInfo)

Definition at line 245 of file name_server.c.

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

Referenced by DP_IF_EnumSessions(), and NS_DeleteSessionCache().

◆ NS_PruneSessionCache()

void NS_PruneSessionCache ( LPVOID  lpNSInfo)

Definition at line 332 of file name_server.c.

333{
334 lpNSCache lpCache = lpNSInfo;
335
336 const DWORD dwPresentTime = timeGetTime();
337 const DWORD dwPrunePeriod = DPMSG_WAIT_60_SECS; /* is 60 secs enough? */
338
339 /* This silly little algorithm is based on the fact we keep entries in
340 * the queue in a time based order. It also assumes that it is not possible
341 * to wrap around over yourself (which is not unreasonable).
342 * The if statements verify if the first entry in the queue is less
343 * than dwPrunePeriod old depending on the "clock" roll over.
344 */
345 for( ;; )
346 {
347 lpNSCacheData lpFirstData;
348
349 if( DPQ_IS_EMPTY(lpCache->first) )
350 {
351 /* Nothing to prune */
352 break;
353 }
354
355 /* Deal with time in a wrap around safe manner - unsigned arithmetic.
356 * Check the difference in time */
357 if( (dwPresentTime - (DPQ_FIRST(lpCache->first)->dwTime)) < dwPrunePeriod )
358 {
359 /* First entry has not expired yet; don't prune */
360 break;
361 }
362
363 lpFirstData = DPQ_FIRST(lpCache->first);
364 DPQ_REMOVE( lpCache->first, DPQ_FIRST(lpCache->first), next );
365 cbReleaseNSNode( lpFirstData );
366 }
367
368}
#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_IF_EnumSessions(), and NS_AddRemoteComputerAsNameServer().

◆ NS_ReplyToEnumSessionsRequest()

void NS_ReplyToEnumSessionsRequest ( LPCVOID  lpcMsg,
LPVOID *  lplpReplyData,
LPDWORD  lpdwReplySize,
IDirectPlayImpl *  lpDP 
)

◆ NS_ResetSessionEnumeration()

void NS_ResetSessionEnumeration ( LPVOID  lpNSInfo)

Definition at line 290 of file name_server.c.

291{
292 NSCache *cache = (NSCache *) lpNSInfo;
294
295 DPQ_DELETEQ( cache->walkFirst, walkNext, lpNSCacheData, cbReleaseNSNode );
296
297 for( data = DPQ_FIRST( cache->first ); data; data = DPQ_NEXT( data->next ) )
298 {
299 InterlockedIncrement( &data->ref );
300 DPQ_INSERT( cache->walkFirst, data, walkNext );
301 }
302
303 ((lpNSCache)lpNSInfo)->present = ((lpNSCache)lpNSInfo)->walkFirst.lpQHFirst;
304}
#define InterlockedIncrement
Definition: armddk.h:53
#define DPQ_NEXT(elem)
Definition: dplayx_queue.h:67
Definition: cache.c:41

Referenced by DP_IF_EnumSessions(), DP_SecureOpen(), and NS_DeleteSessionCache().

◆ NS_SendSessionRequestBroadcast()

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

Definition at line 192 of file name_server.c.

197{
200 DWORD passwordSize = 0;
201
202 TRACE( "enumerating for guid %s\n", debugstr_guid( lpcGuid ) );
203
204 if ( password )
205 passwordSize = (wcslen( password ) + 1) * sizeof( WCHAR );
206
207 data.dwMessageSize = lpSpData->dwSPHeaderSize + sizeof( *lpMsg ) + passwordSize;
208 data.lpMessage = calloc( 1, data.dwMessageSize );
209 data.lpISP = lpSpData->lpISP;
210 data.bReturnStatus = (dwFlags & DPENUMSESSIONS_RETURNSTATUS) != 0;
211
212
213 lpMsg = (LPDPMSG_ENUMSESSIONSREQUEST)(((BYTE*)data.lpMessage)+lpSpData->dwSPHeaderSize);
214
215 /* Setup EnumSession request message */
219
220 lpMsg->passwordOffset = password ? sizeof( DPMSG_ENUMSESSIONSREQUEST ) : 0;
221 lpMsg->dwFlags = dwFlags;
222
223 lpMsg->guidApplication = *lpcGuid;
224
225 memcpy( lpMsg + 1, password, passwordSize );
226
227 return (lpSpData->lpCB->EnumSessions)( &data );
228}
static UCHAR password[]
Definition: bcrypt.c:520
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
#define DPENUMSESSIONS_RETURNSTATUS
Definition: dplay.h:1021
struct tagDPMSG_ENUMSESSIONSREQUEST * LPDPMSG_ENUMSESSIONSREQUEST
#define DPMSGVER_DP6
#define DPMSGCMD_ENUMSESSIONSREQUEST
struct tagDPMSG_ENUMSESSIONSREQUEST DPMSG_ENUMSESSIONSREQUEST
#define DPMSGMAGIC_DPLAYMSG
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
LPDPSP_ENUMSESSIONS EnumSessions
Definition: dplaysp.h:326
LPDPSP_SPCALLBACKS lpCB
Definition: dplaysp.h:354
IDirectPlaySP * lpISP
Definition: dplaysp.h:355
DWORD dwSPHeaderSize
Definition: dplaysp.h:360
unsigned char BYTE
Definition: xxhash.c:193

Referenced by DP_EnumSessionsSendAsyncRequestThread(), and DP_IF_EnumSessions().

◆ NS_SetLocalAddr()

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

Definition at line 180 of file name_server.c.

181{
182 lpNSCache lpCache = (lpNSCache)lpNSInfo;
183
184 lpCache->lpLocalAddrHdr = malloc( dwHdrSize );
185
186 CopyMemory( lpCache->lpLocalAddrHdr, lpHdr, dwHdrSize );
187}

Referenced by DP_HandleMessage().

◆ NS_SetLocalComputerAsNameServer()

void NS_SetLocalComputerAsNameServer ( LPCDPSESSIONDESC2  lpsd,
LPVOID  lpNSInfo 
)

Definition at line 88 of file name_server.c.

89{
90 lpNSCache lpCache = (lpNSCache)lpNSInfo;
91
92 lpCache->bNsIsLocal = TRUE;
93}

Referenced by DP_SecureOpen().

◆ NS_WalkSessions()

LPDPSESSIONDESC2 NS_WalkSessions ( LPVOID  lpNSInfo,
void **  spMessageHeader,
BOOL  ansi 
)

Definition at line 306 of file name_server.c.

307{
308 LPDPSESSIONDESC2 lpSessionDesc;
309 lpNSCache lpCache = (lpNSCache)lpNSInfo;
310
311 /* Test for end of the list */
312 if( lpCache->present == NULL )
313 {
314 return NULL;
315 }
316
317 lpSessionDesc = ansi ? lpCache->present->dataA : lpCache->present->data;
318
319 if( spMessageHeader )
320 *spMessageHeader = lpCache->present->lpNSAddrHdr;
321
322 /* Advance tracking pointer */
323 lpCache->present = lpCache->present->walkNext.lpQNext;
324
325 return lpSessionDesc;
326}
static UINT WPARAM LPARAM BOOL ansi
Definition: misc.c:135

Referenced by DP_InvokeEnumSessionCallbacks(), and DP_SecureOpen().