ReactOS 0.4.15-dev-7958-gcd0bb1a
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) DECLSPEC_HIDDEN
 
void NS_AddRemoteComputerAsNameServer (LPCVOID lpNSAddrHdr, DWORD dwHdrSize, LPCDPMSG_ENUMSESSIONSREPLY lpcMsg, LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
LPVOID NS_GetNSAddr (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
DWORD NS_GetNsMagic (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_SetLocalAddr (LPVOID lpNSInfo, LPCVOID lpHdr, DWORD dwHdrSize) DECLSPEC_HIDDEN
 
void NS_ReplyToEnumSessionsRequest (LPCVOID lpcMsg, LPVOID *lplpReplyData, LPDWORD lpdwReplySize, IDirectPlayImpl *lpDP) DECLSPEC_HIDDEN
 
HRESULT NS_SendSessionRequestBroadcast (LPCGUID lpcGuid, DWORD dwFlags, const SPINITDATA *lpSpData) DECLSPEC_HIDDEN
 
BOOL NS_InitializeSessionCache (LPVOID *lplpNSInfo) DECLSPEC_HIDDEN
 
void NS_DeleteSessionCache (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_InvalidateSessionCache (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_ResetSessionEnumeration (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
LPDPSESSIONDESC2 NS_WalkSessions (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_PruneSessionCache (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 

Function Documentation

◆ NS_AddRemoteComputerAsNameServer()

void NS_AddRemoteComputerAsNameServer ( LPCVOID  lpNSAddrHdr,
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 GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#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 ( LPCVOID  lpcMsg,
LPVOID lplpReplyData,
LPDWORD  lpdwReplySize,
IDirectPlayImpl lpDP 
)

◆ 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 DPMSGVER_DP6
#define DPMSGCMD_ENUMSESSIONSREQUEST
#define DPMSGMAGIC_DPLAYMSG
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
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
unsigned char BYTE
Definition: xxhash.c:193

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().